我正在制作用于打印收据的PL SQL应用程序,但是我在显示该功能时遇到了问题。它显示错误--- PLS-00221:'DISPLAY_TRANS'不是程序或未定义---当我调用它时。
我的功能如下:
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
请帮我找一个解决方案......
答案 0 :(得分:2)
以错误的方式执行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;