程序有啥问题?
Posted
技术标签:
【中文标题】程序有啥问题?【英文标题】:What is wrong in the program?程序有什么问题? 【发布时间】:2018-07-18 11:14:42 【问题描述】:我已经在一个包中创建了程序...在 TOAD 中编译时,没有错误,但在提交我的 jsp 页面后它显示
""包体 "USERINFO.FORM_PKG" 有错误 ORA-06508: PL/SQL: could 找不到被调用的程序单元:“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;
/
【问题讨论】:
请看详情:select * from user_errors where name = upper('form_pkg')
你不能定义参数的限制 - 删除字符的长度/数字的特异性。
我看到了不同的声明:PROCEDURE Insert_receipts(p_receipt NUMBER,
和 PROCEDURE Insert_receipts (p_receipt NUMBER(6)
- 请注意6。包及其主体必须具有相同的过程/函数声明
是属于用户信息
在写入 select * from user_errors where name = upper('form_pkg') 后出现错误我收到错误为 PLS-00103:在预期以下情况之一时遇到符号“(”::=。 ) , @ % 默认字符符号 ":=" 被替换为 "(" 以继续。在行号 5,6,7,18,19,20,21,22
【参考方案1】:
过程'/函数'声明在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')
【讨论】:
【参考方案2】:包规范和主体应该对每个过程/函数具有相同的参数/数据类型,并且不能包含大小/比例/精度。
另外,使用[SCHEMA_NAME.]TABLE_NAME.COLUMN_NAME%TYPE
而不是显式声明类型。但是,如果您要使用基础数据类型,则只需删除精度。 IE。 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;
/
【讨论】:
以上是关于程序有啥问题?的主要内容,如果未能解决你的问题,请参考以下文章