PLS-00221:“DISPLAY_TRANS”不是过程或未定义
Posted
技术标签:
【中文标题】PLS-00221:“DISPLAY_TRANS”不是过程或未定义【英文标题】:PLS-00221: 'DISPLAY_TRANS' is not a procedure or is undefined 【发布时间】:2015-12-13 03:15:48 【问题描述】:我正在制作一个用于打印收据的 PL SQL 应用程序,但我在显示该功能时遇到了问题。它显示错误 --- PLS-00221: 'DISPLAY_TRANS' is not an procedure or is undefined --- 当我调用它时。
我的函数如下所示:
CREATE OR REPLACE FUNCTION DISPLAY_TRANS(in_id diamanteruga_invoice.invoice_id%TYPE) RETURN NUMBER AS
v_gas_type diamanteruga_gas.gas_type%TYPE;
v_gas_liters diamanteruga_gas.gas_liters%TYPE;
v_gas_priceperliter diamanteruga_gas.gas_priceperliter%TYPE;
v_gas_amount diamanteruga_gas.gas_amount%TYPE;
v_vatable_sale diamanteruga_invoice.vatable_sale%TYPE;
v_vat_exempt_sale diamanteruga_invoice.vat_exempt_sale%TYPE;
v_vat_zero_rated_sale diamanteruga_invoice.vat_zero_rated_sale%TYPE;
v_subtotal diamanteruga_invoice.subtotal%TYPE;
v_vat diamanteruga_invoice.subtotal%TYPE;
v_amount_due diamanteruga_invoice.amount_due%TYPE;
v_amount_paid diamanteruga_invoice.amount_paid%TYPE;
v_change_due diamanteruga_invoice.change_due%TYPE;
v_payment_type diamanteruga_invoice.payment_type%TYPE;
BEGIN
select gas_type, gas_liters, gas_priceperliter, vatable_sale, vat_exempt_sale, vat_zero_rated_sale, subtotal, vat, amount_due, amount_paid, change_due, payment_type
into v_gas_type, v_gas_liters, v_gas_priceperliter, v_vatable_sale, v_vat_exempt_sale, v_vat_zero_rated_sale, v_subtotal, v_vat, v_amount_due, v_amount_paid, v_change_due, v_payment_type
from diamanteruga_invoice join diamanteruga_gas using (gas_id)
where invoice_id = in_id;
dbms_output.put_line ('');
dbms_output.put_line (' DESCRIPTION AMOUNT');
dbms_output.put_line('________________________________________________________________');
dbms_output.put_line (' ' ||v_gas_type|| ' '||to_char((v_vatable_sale), '9999.99'));
dbms_output.put_line (' ' || v_gas_liters || ' @ P/L' || v_gas_priceperliter );
dbms_output.put_line('________________________________________________________________');
dbms_output.put_line (' VATable Sale ' || to_char(v_vatable_sale, '9999.99'));
dbms_output.put_line (' VAT-Exempt Sale ' || to_char(v_vat_exempt_sale, '0.99'));
dbms_output.put_line (' VAT-Zero Rated Sale ' || to_char(v_vat_zero_rated_sale, '0.99'));
dbms_output.put_line (' Sub Total(12% VAT) ' || to_char((v_vatable_sale/1.12),'9999.99'));
dbms_output.put_line (' VAT(12%) ' || to_char((v_vatable_sale-(v_vatable_sale/1.12)), '9999.99'));
dbms_output.put_line ('');
dbms_output.put_line (' Amount Due ' || to_char(v_amount_due, '9999.99'));
dbms_output.put_line (' Cash Tendered ' || to_char(v_amount_paid, '9999.99'));
if (v_amount_due-v_amount_paid) <= 0 then dbms_output.put_line (' Change Due ' || to_char((v_amount_due-v_amount_paid),'0.99'));
else dbms_output.put_line (' Change Due ' || to_char((v_amount_due-v_amount_paid),'9999.99'));
end if;
dbms_output.put_line ('');
dbms_output.put_line ('________________________________________________________________');
dbms_output.put_line ('');
dbms_output.put_line (' PAYMENT TYPE: ' || v_payment_type);
RETURN NULL;
END DISPLAY_TRANS;
我的调用程序如下所示:
set serveroutput on
BEGIN
DISPLAY_TRANS(000000322170);
END;
输出应该是:
DESCRIPTION AMOUNT
________________________________________________________________
8 PREMIUM 95 500.00
11.99 @ P/L41.7
________________________________________________________________
VATable Sale 500.00
VAT-Exempt Sale 0.00
VAT-Zero Rated Sale 0.00
Sub Total(12% VAT) 446.43
VAT(12%) 53.57
Amount Due 500.00
Cash Tendered 500.00
Change Due 0.00
________________________________________________________________
PAYMENT TYPE: Cash
请帮我找到解决办法...
【问题讨论】:
您将其创建为一个函数,因此您必须为其赋予一些价值。类似declare somevar number; begin somevar:=DISPLAY_TRANS(000000322170); end;
删除该功能。创建或替换程序 ...
【参考方案1】:
您以错误的方式执行 PL/SQL 函数。 正确的方法是:
1) 由于函数返回一个值,我们可以将它分配给一个变量。
declare result varchar2(20);
result := DISPLAY_TRANS(000000322170);
2) 作为 SELECT 语句的一部分
SELECT DISPLAY_TRANS(000000322170) FROM dual;
3) 在 PL/SQL 语句中,例如,
dbms_output.put_line( DISPLAY_TRANS(000000322170));
这一行显示函数返回的值。
但是,在您的情况下,更好的选择是程序。删除您创建的函数 (DROP FUNCTION DISPLAY_TRANS
) 并尝试以下操作:
CREATE OR REPLACE procedure DISPLAY_TRANS(
in_id diamanteruga_invoice.invoice_id%TYPE
)
AS
v_gas_type diamanteruga_gas.gas_type%TYPE;
v_gas_liters diamanteruga_gas.gas_liters%TYPE;
v_gas_priceperliter diamanteruga_gas.gas_priceperliter%TYPE;
v_gas_amount diamanteruga_gas.gas_amount%TYPE;
v_vatable_sale diamanteruga_invoice.vatable_sale%TYPE;
v_vat_exempt_sale diamanteruga_invoice.vat_exempt_sale%TYPE;
v_vat_zero_rated_sale diamanteruga_invoice.vat_zero_rated_sale%TYPE;
v_subtotal diamanteruga_invoice.subtotal%TYPE;
v_vat diamanteruga_invoice.subtotal%TYPE;
v_amount_due diamanteruga_invoice.amount_due%TYPE;
v_amount_paid diamanteruga_invoice.amount_paid%TYPE;
v_change_due diamanteruga_invoice.change_due%TYPE;
v_payment_type diamanteruga_invoice.payment_type%TYPE;
BEGIN
select gas_type, gas_liters, gas_priceperliter, vatable_sale, vat_exempt_sale, vat_zero_rated_sale, subtotal, vat, amount_due, amount_paid, change_due, payment_type
into v_gas_type, v_gas_liters, v_gas_priceperliter, v_vatable_sale, v_vat_exempt_sale, v_vat_zero_rated_sale, v_subtotal, v_vat, v_amount_due, v_amount_paid, v_change_due, v_payment_type
from diamanteruga_invoice join diamanteruga_gas using (gas_id)
where invoice_id = in_id;
dbms_output.put_line ('');
dbms_output.put_line (' DESCRIPTION AMOUNT');
dbms_output.put_line('________________________________________________________________');
dbms_output.put_line (' ' ||v_gas_type|| ' '||to_char((v_vatable_sale), '9999.99'));
dbms_output.put_line (' ' || v_gas_liters || ' @ P/L' || v_gas_priceperliter );
dbms_output.put_line('________________________________________________________________');
dbms_output.put_line (' VATable Sale ' || to_char(v_vatable_sale, '9999.99'));
dbms_output.put_line (' VAT-Exempt Sale ' || to_char(v_vat_exempt_sale, '0.99'));
dbms_output.put_line (' VAT-Zero Rated Sale ' || to_char(v_vat_zero_rated_sale, '0.99'));
dbms_output.put_line (' Sub Total(12% VAT) ' || to_char((v_vatable_sale/1.12),'9999.99'));
dbms_output.put_line (' VAT(12%) ' || to_char((v_vatable_sale-(v_vatable_sale/1.12)), '9999.99'));
dbms_output.put_line ('');
dbms_output.put_line (' Amount Due ' || to_char(v_amount_due, '9999.99'));
dbms_output.put_line (' Cash Tendered ' || to_char(v_amount_paid, '9999.99'));
if (v_amount_due-v_amount_paid) <= 0 then dbms_output.put_line (' Change Due ' || to_char((v_amount_due-v_amount_paid),'0.99'));
else dbms_output.put_line (' Change Due ' || to_char((v_amount_due-v_amount_paid),'9999.99'));
end if;
dbms_output.put_line ('');
dbms_output.put_line ('________________________________________________________________');
dbms_output.put_line ('');
dbms_output.put_line (' PAYMENT TYPE: ' || v_payment_type);
END DISPLAY_TRANS;
该过程可以通过以下方式称为倾斜:
SQL> EXECUTE DISPLAY_TRANS(000000322170);
或者像你提到的那样:
BEGIN
DISPLAY_TRANS(000000322170);
END;
【讨论】:
以上是关于PLS-00221:“DISPLAY_TRANS”不是过程或未定义的主要内容,如果未能解决你的问题,请参考以下文章
PLS-00221 'to_date' 不是程序或未定义的错误,并转换以句点分隔的日期
解决PLS-00221: 'FUN2' 不是过程或尚未定义 的总结