Home Database Mysql Tutorial Oracle PL/SQL开发利器

Oracle PL/SQL开发利器

Jun 07, 2016 pm 03:45 PM
or oracle sql use sharp weapon develop conduct

使用Toad进行Oracle PL/SQL Program的编写及调试需掌握如下视图应用: (1)Schema Broswer 模式浏览器(Schema Browser)可以快速访问数据字典,浏览数据库中的表、索引、存储 过程。Toad 提供对数据库的快速访问,使用极为方便,用户界面简洁,结构安排合

使用Toad进行Oracle PL/SQL Program的编写及调试需掌握如下视图应用:

(1)Schema Broswer

    模式浏览器(Schema Browser)可以快速访问数据字典,浏览数据库中的表、索引、存储

过程。Toad 提供对数据库的快速访问,使用极为方便,用户界面简洁,结构安排合理。当点击

一个单独的数据库对象,Toad 立即显示此对象的详细信息。例如,点一个数据库的表,所有和

此表相关的索引、约束、存储过程、SQL 语句、表中的数据以及和其他表的相互引用关系都在

同一界面显示出来。所有针对数据库对象的操作都可以在Schema Browser 一个窗口中进行。

  开发人员查询Oracle数据库当前用户连接的所有对象信息,开发中可由这里浏览各种对象,即Procedure、Function、Package,单击某个对象即走读相关代码,右击可实现重新编译等操作,双击某对象进入对应的开发编辑视图,可进行修改、调试、语句跟踪性能分析等操作;

 (2)SQL Editor

     SQL 编辑器(SQL Editor)的主要功能是编辑、运行和调整SQL 语句。TOAD 的高级编

辑窗口包括众多的特性来提高开发人员编写SQL 语句的产品化程度。例如,简单地生成代码模

板,在编写SQL 前自动发现包的内容和列的名字等等。SQL 编辑器包括一个编辑窗口和运行结

果窗口,允许开发人员在编辑的过程中测试运行结果。SQL 编辑器中不仅包括标准的编辑命令,

也包括一些增强的功能,如快速查询表中的字段、将SQL 语句的内容格式化等等。这个窗口可

以处理大到4GB 的内容,对大的开发项目来说非常有用。便捷的书签可以让开发人员非常容易

地找到相关位置。在运行结果窗口可提供用户定义的配置功能,支持LONG 和LONG RAW 列,

可以将数据卸出到磁盘、打印数据、编辑数据等等。

  (3)Procedure Editor

      存储过程编辑器(Procedure Editor)的主要功能是编辑、编译、测试、调试存储过程和触

发器。TOAD 提供语法标识、错误标识和其他很多易于使用的功能,如在弹出窗口显示表名、列

名和Oracle 函数。和其他的 PL/SQL 编辑工具不同,TOAD 允许在一个文件中操作多个数据

库对象,可以编译一个对象、编译多个对象、编译到当前光标、从光标开始编译。在运行出现错

误时,存储过程停止到有问题的语句。用户可以使用快捷方式或模板来快速编写PL/SQL,也可以

根据需要生成自己的模板。使用Toad 可以非常方便地进行编辑工作,可如设置书签、取消注释、

格式化SQL 语句等等。

  写两个实例如下:

  •   Procedure示例:

 

<ol>
<li><span><span>CREATE</span><span> </span><span>OR</span><span> </span><span>REPLACE</span><span> </span><span>PROCEDURE</span><span> SCOTT.calc_totalTemp (fudge_factor_in </span><span>IN</span><span> NUMBER) </span></span></li>
<li><span><span>IS</span><span> </span></span></li>
<li><span>  subtotal NUMBER := 0; </span></li>
<li><span>  <span>PROCEDURE</span><span> compute_running_total (increment_in </span><span>IN</span><span> PLS_INTEGER) </span></span></li>
<li><span>  <span>IS</span><span> </span></span></li>
<li><span>  <span>BEGIN</span><span> </span></span></li>
<li><span>  subtotal := subtotal + increment_in * fudge_factor_in; </span></li>
<li><span>  <span>END</span><span>; </span></span></li>
<li><span><span>BEGIN</span><span> </span></span></li>
<li><span>  <span>FOR</span><span> month_idx </span><span>IN</span><span> 1..12 </span></span></li>
<li><span>  LOOP </span></li>
<li><span>    compute_running_total (month_idx); </span></li>
<li><span>  <span>END</span><span> LOOP; </span></span></li>
<li><span>  DBMS_OUTPUT.PUT_LINE(<span>'Fudged total for year: '</span><span> || subtotal); </span></span></li>
<li><span><span>END</span><span>; </span></span></li>
<li><span>/ </span></li>
</ol>
Copy after login
  •  Function示例

 

<ol>
<li><span><span>CREATE</span><span> </span><span>OR</span><span> </span><span>REPLACE</span><span> </span><span>FUNCTION</span><span> SCOTT.wordcountTemp (str </span><span>IN</span><span> VARCHAR2) </span></span></li>
<li><span><span>RETURN</span><span> PLS_INTEGER </span></span></li>
<li><span><span>AS</span><span> </span></span></li>
<li><span>/* words PLS_INTEGER := 0; ***Commented <span>out</span><span> </span><span>for</span><span> intentional error*** */ </span></span></li>
<li><span>words PLS_INTEGER := 0; </span></li>
<li><span>len PLS_INTEGER := NVL(LENGTH(str),0); </span></li>
<li><span>inside_a_word BOOLEAN; </span></li>
<li><span><span>BEGIN</span><span> </span></span></li>
<li><span><span>FOR</span><span> i </span><span>IN</span><span> 1..len + 1 </span></span></li>
<li><span>LOOP </span></li>
<li>
<span>IF ASCII(SUBSTR(str, i, 1)) OR</span><span> i > len </span>
</li>
<li><span><span>THEN</span><span> </span></span></li>
<li><span>IF inside_a_word </span></li>
<li><span><span>THEN</span><span> </span></span></li>
<li><span>words := words + 1; </span></li>
<li><span>inside_a_word := <span>FALSE</span><span>; </span></span></li>
<li><span><span>END</span><span> IF; </span></span></li>
<li><span><span>ELSE</span><span> </span></span></li>
<li><span>inside_a_word := <span>TRUE</span><span>; </span></span></li>
<li><span><span>END</span><span> IF; </span></span></li>
<li><span><span>END</span><span> LOOP; </span></span></li>
<li><span><span>RETURN</span><span> words; </span></span></li>
<li><span><span>END</span><span>; </span></span></li>
<li><span>/ </span></li>
</ol>
Copy after login

  (4)PL/SQL Debugger

     Toad 提供强大易用的PL/SQL 调试功能,可以节省开发人员在大型项目中用于开发和测

试的宝贵时间,提高应用开发的质量。在存储过程开发的过程中,Toad 可以逐行编辑、调试和

运行代码。运行时可以根据需要输入参数,观察相关参数的变化来检查存储过程的正确性。在调

式过程中,Toad 可以通过窗口显示所有的断点、参数, 调用堆栈和输出参数。使用Toad,非

常容易检测到存储过程的错误,开发人员可以一步一步运行PL/SQL 语句来识别问题。调试会话

可以和其他程序会话同时进行。

    我在刚开始使用Toad对Procedure和Function进行调试的时候,出现了调试按钮置灰无法进行调试、点击调试按钮后程序直接跑完没有在断点处停住等情况,在网上查了很久,大都对这个问题都没有人进行正确的解决;

    解决Toad调试的问题的方法如下:

    首先确认一点:你当前Toad的用户连接是否为Sys、System等DBA用户,如果是的话,就会出现Toad Debug按钮是可用的,断点也可以设置,但是程序直接跑完的情况,应该是Toad不支持DBA用户直接调试PL/SQL程序;

    然后,将用户连接改为其他用户例如Scott重连Toad,当Toad在此用户连接下,直接进行调试PL/SQL是不行的,因为该用户默认是没有Debugger权限的,在此情况下Debug按钮也是置灰的;

    然后,执行如下语句,(假设当前Toad连接Oracle的用户为Toad):

 

<ol>
<li><span><span>grant</span><span> debug </span><span>connect</span><span> session </span><span>to</span><span> scott; </span></span></li>
<li><span><span>grant</span><span> debug </span><span>any</span><span> </span><span>procedure</span><span> </span><span>to</span><span> scott; </span></span></li>
</ol>
Copy after login

  最后,就跟在Eclipse Debug Java程序差不多了,即设置断点,点击Toad上的按钮Execute PL/SQL with Debugger,那就开始调试吧!

   (5)Connection Color-Coding

  Toad 允许同时连接多个数据库,便于在多个数据库之间进行切换和比对。但是这样也增加

了在数据库上进行误操作的风险。Connection Color-Coding 允许用户在定义一个新的数据库连

接时,为该连接指定一种颜色,以便作为醒目提醒。

 

中子星” 博客,请务必保留此出处http://ckitpro8086.blog.51cto.com/3653012/770589

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to import oracle database How to import oracle database Apr 11, 2025 pm 08:06 PM

Data import method: 1. Use the SQLLoader utility: prepare data files, create control files, and run SQLLoader; 2. Use the IMP/EXP tool: export data, import data. Tip: 1. Recommended SQL*Loader for big data sets; 2. The target table should exist and the column definition matches; 3. After importing, data integrity needs to be verified.

How to create a table in oracle How to create a table in oracle Apr 11, 2025 pm 08:00 PM

Creating an Oracle table involves the following steps: Use the CREATE TABLE syntax to specify table names, column names, data types, constraints, and default values. The table name should be concise and descriptive, and should not exceed 30 characters. The column name should be descriptive, and the data type specifies the data type stored in the column. The NOT NULL constraint ensures that null values ​​are not allowed in the column, and the DEFAULT clause specifies the default values ​​for the column. PRIMARY KEY Constraints to identify the unique record of the table. FOREIGN KEY constraint specifies that the column in the table refers to the primary key in another table. See the creation of the sample table students, which contains primary keys, unique constraints, and default values.

How to check tablespace size of oracle How to check tablespace size of oracle Apr 11, 2025 pm 08:15 PM

To query the Oracle tablespace size, follow the following steps: Determine the tablespace name by running the query: SELECT tablespace_name FROM dba_tablespaces; Query the tablespace size by running the query: SELECT sum(bytes) AS total_size, sum(bytes_free) AS available_space, sum(bytes) - sum(bytes_free) AS used_space FROM dba_data_files WHERE tablespace_

How to add table fields to oracle How to add table fields to oracle Apr 11, 2025 pm 07:30 PM

Use the ALTER TABLE statement, the specific syntax is as follows: ALTER TABLE table_name ADD column_name data_type [constraint-clause]. Where: table_name is the table name, column_name is the field name, data_type is the data type, and constraint-clause is an optional constraint. Example: ALTER TABLE employees ADD email VARCHAR2(100) Add an email field to the employees table.

What to do if the oracle can't be opened What to do if the oracle can't be opened Apr 11, 2025 pm 10:06 PM

Solutions to Oracle cannot be opened include: 1. Start the database service; 2. Start the listener; 3. Check port conflicts; 4. Set environment variables correctly; 5. Make sure the firewall or antivirus software does not block the connection; 6. Check whether the server is closed; 7. Use RMAN to recover corrupt files; 8. Check whether the TNS service name is correct; 9. Check network connection; 10. Reinstall Oracle software.

How to solve garbled code in oracle How to solve garbled code in oracle Apr 11, 2025 pm 10:09 PM

Oracle garbled problems can be solved by checking the database character set to ensure they match the data. Set the client character set to match the database. Convert data or modify column character sets to match database character sets. Use Unicode character sets and avoid multibyte character sets. Check that the language settings of the database and client are correct.

How to re-query oracle How to re-query oracle Apr 11, 2025 pm 07:33 PM

Oracle provides multiple deduplication query methods: The DISTINCT keyword returns a unique value for each column. The GROUP BY clause groups the results and returns a non-repetitive value for each group. The UNIQUE keyword is used to create an index containing only unique rows, and querying the index will automatically deduplicate. The ROW_NUMBER() function assigns unique numbers and filters out results that contain only line 1. The MIN() or MAX() function returns non-repetitive values ​​of a numeric column. The INTERSECT operator returns the common values ​​of the two result sets (no duplicates).

How to set up users of oracle How to set up users of oracle Apr 11, 2025 pm 08:21 PM

To create a user in Oracle, follow these steps: Create a new user using the CREATE USER statement. Grant the necessary permissions using the GRANT statement. Optional: Use the RESOURCE statement to set the quota. Configure other options such as default roles and temporary tablespaces.

See all articles