错误号 | 描述 |
---|---|
ORU-10027: |
Buffer缓存溢出 |
ORU-10028: |
行长溢出 |
DBMS_OUTPUT.PUT_LINE('I got here:'||:new.col||' is the new value');若启用了DBMS_OUTPUT包,那么由PUT_LINE所生成的文本将被缓存到Buffer中,之后我们可以通过以下代码获取该Buffer中的信息:
BEGIN DBMS_OUTPUT.GET_LINE(:buffer, :status); END;你还可以额外地将buffer显示在屏幕上。可以反复调用GET_LINE直到status返回非零值。处于性能的考虑,推荐使用GET_LINES过程,该过程将返回一个行的数组(an array of lines)。 示例2:调试存储过程和触发器 DBMS_OUTPUT包常被用于调试(debug)存储过程和触发器。该包也可以用于获取对象信息并且格式化地输出。 以下函数将查询EMP表并返回某个部门的总薪水,该函数包含了多次对PUT_LINE过程的调用。 假设EMP表的数据如下:
EMPNO SAL COMM DEPT ----- ------- -------- ------- 1002 1500 500 20 1203 1000 30 1289 1000 10 1347 1000 250 20函数代码如下:
SQL> select * from global_name; GLOBAL_NAME -------------------------------------------------------------------------------- www.oracledatabase12g.com CREATE FUNCTION dept_salary (dnum NUMBER) RETURN NUMBER IS CURSOR emp_cursor IS SELECT sal, comm FROM emp WHERE deptno = dnum; total_wages NUMBER(11, 2) := 0; counter NUMBER(10) := 1; BEGIN FOR emp_record IN emp_cursor LOOP emp_record.comm := NVL(emp_record.comm, 0); total_wages := total_wages + emp_record.sal + emp_record.comm; DBMS_OUTPUT.PUT_LINE('Loop number = ' || counter || '; Wages = '|| TO_CHAR(total_wages)); /* Debug line */ counter := counter + 1; /* Increment debug counter */ END LOOP; /* Debug line */ DBMS_OUTPUT.PUT_LINE('Total wages = ' || TO_CHAR(total_wages)); RETURN total_wages;假设用户在SQL*PLUS中执行以下语句:
SET SERVEROUTPUT ON VARIABLE salary NUMBER; EXECUTE :salary := dept_salary(20);用户将在屏幕输出中看到以下信息:
Loop number = 1; Wages = 2000 Loop number = 2; Wages = 3250 Total wages = 3250 PL/SQL procedure successfully executed.示例3:检索对象相关信息 以下示例中用户使用EXPLAIN PLAN命令以检索某条语句的执行计划信息,这些信息存放在plan_table表中。用户还为语句分配了语句ID(statement ID)。示例的EXPLAIN_OUT存储过程从表上检索信息并嵌套地格式化输出。
/****************************************************************/ /* Create EXPLAIN_OUT procedure. User must pass STATEMENT_ID to */ /* to procedure, to uniquely identify statement. */ /****************************************************************/ CREATE OR REPLACE PROCEDURE explain_out (statement_id IN VARCHAR2) AS -- Retrieve information from PLAN_TABLE into cursor EXPLAIN_ROWS. CURSOR explain_rows IS SELECT level, id, position, operation, options, object_name FROM plan_table WHERE statement_id = explain_out.statement_id CONNECT BY PRIOR id = parent_id AND statement_id = explain_out.statement_id START WITH id = 0 ORDER BY id; BEGIN -- Loop through information retrieved from PLAN_TABLE: FOR line IN explain_rows LOOP -- At start of output, include heading with estimated cost. IF line.id = 0 THEN DBMS_OUTPUT.PUT_LINE ('Plan for statement ' || statement_id || ', estimated cost = ' || line.position); END IF; -- Output formatted information. LEVEL determines indention level. DBMS_OUTPUT.PUT_LINE (lpad(' ',2*(line.level-1)) || line.operation || ' ' || line.options || ' ' || line.object_name); END LOOP; END;数据结构 DBMS_OUTPUT包声明了2中集合类型,以便GET_LINES函数使用。 TABLE Types CHARARR Table Type OBJECT Types DBMSOUTPUT_LINESARRAY Object Type CHARARR Table Type This package type is to be used with the GET_LINES Procedure to obtain text submitted through the PUT Procedure and PUT_LINE Procedure. Syntax TYPE CHARARR IS TABLE OF VARCHAR2(32767) INDEX BY BINARY_INTEGER; DBMSOUTPUT_LINESARRAY Object Type This package type is to be used with the GET_LINES Procedure to obtain text submitted through the PUT Procedure and PUT_LINE Procedure. Syntax TYPE DBMSOUTPUT_LINESARRAY IS VARRAY(2147483647) OF VARCHAR2(32767); DBMS_OUTPUT包子程序摘要
子程序 | 描述 | |||||
---|---|---|---|---|---|---|
DISABLE 存储过程 | 禁用消息输出 | |||||
ENABLE
类别:未分类┆阅读(
0)┆评论(
0) ┆ 返回博主首页┆ 返回博客首页
上一篇 Script:Diagnostic Oracle Locks 下一篇 Script:优化crs_stat命令的输出
文章评论发表评论
同时赞一个
每日博报 精彩不止一点
|