1

我在 SQL Developer 中创建了一些程序,它们工作正常。但是,我现在正在创建一个包以包含所有这些程序,并且似乎无法找出正确的方法来对包进行编码,因为它返回以下错误(参考 PACKAGE BODY 的 CREATE):

 PLS-00103: Encountered the symbol "CREATE"

这是我的代码:

CREATE OR REPLACE PACKAGE package_test AS

PROCEDURE copy_object;

END package_test;

CREATE OR REPLACE PACKAGE BODY package_test AS

PROCEDURE copy_object IS
CURSOR object_cursor IS
SELECT COD_OBJECT, OBJECT_NAME FROM OBJECT;

object_rec object_cursor%rowtype;

BEGIN
EXECUTE IMMEDIATE 'TRUNCATE TABLE DATABASE2.D_OBJECT';
FOR object_rec IN object_cursor
LOOP
    INSERT INTO DATABASE2.D_OBJECT (COD_OBJECT,OBJECT_NAME) VALUES (object_rec.OOD_OBJECT,object_rec.OBJECT_NAME);
END LOOP;
COMMIT;
END copy_object;
END package_test;

我做了一些搜索,我唯一能想到的可能是与 CURSOR 上的定义相关的一些问题……但不确定。提前致谢

4

1 回答 1

2

我在 sqlplus 和 sqldeveloper 中成功运行了这个(sqldeveloper 中的 F5:“运行脚本”)。我更改了两个 dml 语句,因为我的架构不同。

SQL> CREATE OR REPLACE PACKAGE package_test AS
  2
  3  PROCEDURE copy_object;
  4
  5  END package_test;
  6  /

Package created.

SQL>
SQL> CREATE OR REPLACE PACKAGE BODY package_test AS
  2
  3  PROCEDURE copy_object IS
  4  CURSOR object_cursor IS
  5  SELECT * from dual;
  6
  7  object_rec object_cursor%rowtype;
  8
  9  BEGIN
 10  EXECUTE IMMEDIATE 'TRUNCATE TABLE DATABASE2.D_OBJECT';
 11  FOR object_rec IN object_cursor
 12  LOOP
 13      NULL; --INSER INTO DATABASE2.D_OBJECT (COD_OBJECT,OBJECT_NAME) VALUES (object_rec.OOD_OBJECT,object_rec.OBJECT_
NAME);
 14  END LOOP;
 15  COMMIT;
 16  END copy_object;
 17  END package_test;
 18  /

Package body created.

SQL>
于 2012-07-20T11:55:45.267 回答