PLSQL-ORA-01008-并非所有变量都绑定



我试图调用一个非常简单的PLSQL函数,但我猜不出我做错了什么:

CREATE OR REPLACE PACKAGE BODY KYC_OWN.KYCK_TEMP IS
FUNCTION PrintHelloWorld RETURN VARCHAR2 IS
BEGIN
RETURN 'Hello World'; 
END printHelloWorld;
END KYCK_TEMP;

然后我调用这样的函数:

call   KYC_OWN.KYCK_TEMP.PrintHelloWorld() INTO :x;

我想我需要在某个地方声明x变量,但是怎么声明呢?

提前感谢

你可以试试这个:

CREATE OR REPLACE PACKAGE BODY KYC_OWN.KYCK_TEMP IS
FUNCTION PrintHelloWorld RETURN VARCHAR2 IS
BEGIN
RETURN ('Hello World'); 
END printHelloWorld;
END KYCK_TEMP;

或者创建如下变量并返回g_helloworld

create or replace package constants as
g_helloworld constant varchar2(11) := 'Hello World';
function get_helloworld return varchar2;
end constants;
/
create or replace package body constants as
function get_helloworld return varchar2
is
begin
return g_helloworld;
end get_helloworld;
end constants;

/

如果您使用SQL*Plus,您可以创建一个变量,然后用它来保存函数返回变量,例如:

VARIABLE x varchar2(30)
call   KYC_OWN.KYCK_TEMP.PrintHelloWorld() INTO :x;
print x

或者,您可以简单地使用匿名块和dbms_output来显示数字:

set serveroutput on -- assuming you're in SQL*Plus
declare
v_val varchar2(30);
begin
v_val := KYC_OWN.KYCK_TEMP.PrintHelloWorld;
dbms_output.put_line('return val = '||v_val);
end;

最新更新