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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

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)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1267
29
C# Tutorial
1239
24
How to solve the problem of closing oracle cursor How to solve the problem of closing oracle cursor Apr 11, 2025 pm 10:18 PM

The method to solve the Oracle cursor closure problem includes: explicitly closing the cursor using the CLOSE statement. Declare the cursor in the FOR UPDATE clause so that it automatically closes after the scope is ended. Declare the cursor in the USING clause so that it automatically closes when the associated PL/SQL variable is closed. Use exception handling to ensure that the cursor is closed in any exception situation. Use the connection pool to automatically close the cursor. Disable automatic submission and delay cursor closing.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

What steps are required to configure CentOS in HDFS What steps are required to configure CentOS in HDFS Apr 14, 2025 pm 06:42 PM

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

What to do if the oracle log is full What to do if the oracle log is full Apr 12, 2025 am 06:09 AM

When Oracle log files are full, the following solutions can be adopted: 1) Clean old log files; 2) Increase the log file size; 3) Increase the log file group; 4) Set up automatic log management; 5) Reinitialize the database. Before implementing any solution, it is recommended to back up the database to prevent data loss.

Oracle's Role in the Business World Oracle's Role in the Business World Apr 23, 2025 am 12:01 AM

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

How to stop oracle database How to stop oracle database Apr 12, 2025 am 06:12 AM

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

How to configure the database connection of weblogic on centos How to configure the database connection of weblogic on centos Apr 14, 2025 pm 02:06 PM

Configuring WebLogic database connection on a CentOS system requires the following steps: JDK installation and environment configuration: Make sure that the server has installed a JDK that is compatible with the WebLogic version (for example, WebLogic14.1.1 usually requires JDK8). Correctly set JAVA_HOME, CLASSPATH and PATH environment variables. WebLogic installation and decompression: Download the WebLogic installation package for CentOS system from the official Oracle website and unzip it to the specified directory. WebLogic user and directory creation: Create a dedicated WebLogic user account and set a security password

How to export oracle view How to export oracle view Apr 12, 2025 am 06:15 AM

Oracle views can be exported through the EXP utility: Log in to the Oracle database. Start the EXP utility, specifying the view name and export directory. Enter export parameters, including target mode, file format, and tablespace. Start exporting. Verify the export using the impdp utility.

See all articles