该程序有什么问题?

时间:2018-07-18 11:14:43

标签: sql oracle plsql plsql-package

我已经在一个程序包中创建了过程...在TOAD中编译时,没有任何错误,但是提交我的jsp页面后,它显示了

  

“”程序包主体“ USERINFO.FORM_PKG”出现错误ORA-06508:PL / SQL:可以   找不到正在被调用的程序单元:“ USERINFO.FORM_PKG”“”

CREATE OR REPLACE PACKAGE form_pkg AS  -- package body
PROCEDURE Insert_receipts(
p_receipt NUMBER, 
p_transaction NUMBER, 
p_amount NUMBER);
PROCEDURE Insert_stkqntys(
p_itemid NUMBER, 
p_date VARCHAR2,
p_supplier VARCHAR2,
p_type VARCHAR2,
p_transaction NUMBER,
p_quantity NUMBER);
END form_pkg;
/
CREATE OR REPLACE PACKAGE BODY form_pkg AS  -- package body

PROCEDURE Insert_receipts (

 p_receipt NUMBER(6), 
 p_transaction NUMBER(5), 
 p_amount NUMBER(10),
 seq_value  NUMBER) IS
 BEGIN

 INSERT INTO receipt
 ( ID, Receipt_Number,Transaction_ID,Amount) 
  VALUES (seq.nextval, p_receipt, p_transaction, p_amount); 
END Insert_receipts
;
PROCEDURE Insert_stkqntys 
(
p_itemid NUMBER(8), 
p_date VARCHAR2(50),
p_supplier VARCHAR2(50),
p_type VARCHAR2(50),
p_transaction NUMBER(8),
p_quantity NUMBER,
seq_value  NUMBER) IS
 BEGIN
 INSERT INTO stock_quantity(ID,Item_ID,Date_Received,Supplier_Challan,Transaction_Type,Transaction_ID,Quantity)VALUES (seq.nextval, p_itemid, p_date,p_supplier,p_type,p_transaction,p_quantity);
 END Insert_stkqntys;
 End form_pkg;
/

2 个答案:

答案 0 :(得分:3)

package及其body中,过程/函数的声明必须相等。尽量避免使用幻数p_amount NUMBER(10)一样:10是什么意思?但是请使用p_amount receipt.Amount%Type receipt.Amount字段的类型。

CREATE OR REPLACE PACKAGE form_pkg AS  
  -- interface: procedure with 3 arguments
  PROCEDURE Insert_receipts(
    p_receipt     receipt.Receipt_Number%Type, 
    p_transaction receipt.Transaction_ID%Type, 
    p_amount      receipt.Amount%Type);

  ...
END form_pkg;
/

CREATE OR REPLACE PACKAGE BODY form_pkg AS  -- package body
  -- implementation
  -- The same three arguments (no seq_value!)
  PROCEDURE Insert_receipts (
    p_receipt     receipt.Receipt_Number%Type, 
    p_transaction receipt.Transaction_ID%Type, 
    p_amount      receipt.Amount%Type) 
  IS
  BEGIN
    INSERT INTO receipt( 
      ID, 
      Receipt_Number,
      Transaction_ID,
      Amount) 
    VALUES (
      seq.NextVal, 
      p_receipt, 
      p_transaction, 
      p_amount);
  END Insert_receipts;

  ...
END form_pkg;
/

实施例行程序时,您可以在USER_ERRORS视图中查看错误的详细信息(名称,行等):

-- all (syntactic) errors in the form_pkg
select *
  from USER_ERRORS
 where Name = upper('form_pkg')

答案 1 :(得分:2)

对于每个过程/函数,程序包的规范和主体应具有相同的参数/数据类型,并且不能包括大小/比例/精度。

此外,请使用[SCHEMA_NAME.]TABLE_NAME.COLUMN_NAME%TYPE而不是显式声明类型。但是,如果要使用基础数据类型,则只需删除精度。即p_receipt NUMBER(6)应该只是p_receipt NUMBER,没有大小/比例/精度。

CREATE OR REPLACE PACKAGE form_pkg AS  -- package specification
  PROCEDURE Insert_receipts(
    p_receipt     RECEIPT.RECEIPT_NUMBER%TYPE, 
    p_transaction RECEIPT.TRANSACTION_ID%TYPE, 
    p_amount      RECEIPT.AMOUNT%TYPE
  );

  PROCEDURE Insert_stkqntys(
    p_itemid      STOCK_QUANTITY.ITEM_ID%TYPE, 
    p_date        STOCK_QUANTITY.DATE_RECEIVED%TYPE,
    p_supplier    STOCK_QUANTITY.SUPPLIER_CHALLAN%TYPE,
    p_type        STOCK_QUANTITY.TRANSACTION_TYPE%TYPE,
    p_transaction STOCK_QUANTITY.TRANSACTION_ID%TYPE,
    p_quantity    STOCK_QUANTITY.QUANTITY%TYPE
  );
END form_pkg;
/

CREATE OR REPLACE PACKAGE BODY form_pkg AS  -- package body
  PROCEDURE Insert_receipts (
    p_receipt     RECEIPT.RECEIPT_NUMBER%TYPE, 
    p_transaction RECEIPT.TRANSACTION_ID%TYPE, 
    p_amount      RECEIPT.AMOUNT%TYPE
  )
  IS
  BEGIN
    INSERT INTO receipt (
      ID,
      Receipt_Number,
      Transaction_ID,
      Amount
    ) VALUES (
      seq.nextval, 
      p_receipt, 
      p_transaction, 
      p_amount
    ); 
  END Insert_receipts;

  PROCEDURE Insert_stkqntys 
  (
    p_itemid      STOCK_QUANTITY.ITEM_ID%TYPE, 
    p_date        STOCK_QUANTITY.DATE_RECEIVED%TYPE,
    p_supplier    STOCK_QUANTITY.SUPPLIER_CHALLAN%TYPE,
    p_type        STOCK_QUANTITY.TRANSACTION_TYPE%TYPE,
    p_transaction STOCK_QUANTITY.TRANSACTION_ID%TYPE,
    p_quantity    STOCK_QUANTITY.QUANTITY%TYPE
  )
  IS
  BEGIN
    INSERT INTO stock_quantity(
      ID,
      Item_ID,
      Date_Received,
      Supplier_Challan,
      Transaction_Type,
      Transaction_ID,
      Quantity
    ) VALUES (
      seq.nextval,
      p_itemid,
      p_date,
      p_supplier,
      p_type,
      p_transaction,
      p_quantity
    );
  END Insert_stkqntys;
End form_pkg;
/