增强的 COMMIT
| COMMIT WRITE <option> |
| COMMIT WRITE WAIT; |
| COMMIT WRITE NOWAIT; |
| COMMIT WRITE BATCH; |
| COMMIT WRITE IMMEDIATE; |
| ALTER SYSTEM SET COMMIT_WRITE = NOWAIT; |
| ALTER SESSION SET COMMIT_WORK = NOWAIT; |
| SQL> insert into accounts 2 select * from accounts_ny; insert into accounts * ERROR at line 1: ORA-00001:unique constraint (ARUP.PK_ACCOUNTS) violated |
| exec dbms_errlog.CREATE_ERROR_LOG ('ACCOUNTS','ERR_ACCOUNTS') |
| SQL> insert into accounts 2 select * from accounts_ny 3 log errors into err_accounts 4 reject limit 200 5 / 6 rows created. |
| SQL> select ORA_ERR_NUMBER$, ORA_ERR_MESG$, ACC_NO 2 from err_accounts; ORA_ERR_NUMBER$ ORA_ERR_MESG$ ACC_NO --------------- -------------------------------------------------- ------ 1 ORA-00001:unique constraint (ARUP.PK_ACCOUNTS) vi 9997 olated 1 ORA-00001:unique constraint (ARUP.PK_ACCOUNTS)vi 9998 olated 1 ORA-00001:unique constraint (ARUP.PK_ACCOUNTS) vi 9999 olated 1 ORA-00001:unique constraint (ARUP.PK_ACCOUNTS) vi 10000 olated |
| create or replace procedure p1 as begin null; end; |
| begin dbms_ddl.create_wrapped ('create or replace procedure p1 as begin null; end;') end; / |
| SQL> select text from user_source where name = 'P1'; Text ----------------------------------------------------------------- procedure p1 wrapped a000000 369 abcd abcd |
| SQL> select dbms_ddl.wrap 2 ('create or replace procedure p1 as begin null; end;') 3 from dual 4 / DBMS_DDL.WRAP('CREATEORREPLACEPROCEDUREP1ASBEGINNULL;END;') ---------------------------------------------------------------------- create or replace procedure p1 wrapped a000000 369 abcd abcd ... and so on ... |
| create or replace procedure myproc as l_key VARCHAR2(200); begin l_key := 'ARUPNANDA'; end; |
| 1 declare 2 l_input_code dbms_sql.varchar2s; 3 begin 4 l_input_code (1) := 'Array to hold the MYPROC'; 5 l_input_code (2) := 'create or replace procedure myproc as '; 6 l_input_code (3) := ' l_key VARCHAR2(200);'; 7 l_input_code (4) := 'begin '; 8 l_input_code (5) := ' l_key := ''ARUPNANDA'';'; 9 l_input_code (6) := 'end;'; 10 l_input_code (7) := 'the end'; 11 sys.dbms_ddl.create_wrapped ( 12 ddl => l_input_code, 13 lb => 2, 14 ub => 6 15 ); 16* end; |
在这里我们定义了一个变量 l_input_code 来保存输入的明文代码。在第 4 行到第 10 行中,我们用要打包的代码来填充这些行。在本示例中,同样为了简单起见,我使用了非常短的行。实际上,您可能要使用非常长的行,其大小多达 32KB。同样,我在数组中只使用了 7 个单元;实际上您可能要使用若干单元来填充全部代码。 第 11 到第 15 行表明我如何调用该过程,以便将该过程创建为打包形式。在第 12 行中,我将集合作为一个参数 DDL 来传递。但是,在这里暂停一下 — 我已经分配了一个注释作为数组的第一个单元,可能用于文档。但它不是有效的语法。同样,我将另一个注释分配给数组的最后一个单元 (7),它也不是用于创建过程的有效语法。为了使包装操作仅仅处理有效的行,我在第 13 和第 14 行中指定了存储我们代码的集合的最低 (2) 和最高 (6) 的单元。参数 LB 表示数组的下界,在本示例中是 2,而 HB 是上界 (6)。
使用这种方法,现在可以从您的 PL/SQL 代码中以打包方式创建任意大小的过程。