定义包内的过程

时间:2012-07-20 11:17:32

标签: plsql oracle-sqldeveloper

我在SQL Developer中创建了一些程序,它们运行正常。但是我现在正在创建一个包以包含所有这些过程的包,并且似乎无法找到编写包的正确方法,因为它返回以下错误(参考包装的创建):

 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上的定义有关的一些问题......但不确定。提前致谢

1 个答案:

答案 0 :(得分:1)

我在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>