我遇到了Oracle的问题。谁能帮帮我吗?我需要调用一个函数,它在一个包下面。但我不知道如何在此包下调用此功能。非常需要你的帮助。
答案 0 :(得分:3)
甲骨文:
CREATE OR REPLACE PACKAGE MY_PACKAGE AS
FUNCTION MyFunction(Param1 IN NUMBER) RETURN NUMBER;
END MY_PACKAGE;
/
CREATE OR REPLACE PACKAGE BODY MY_PACKAGE AS
FUNCTION MyFunction(Param1 IN NUMBER) RETURN NUMBER IS
BEGIN
RETURN Param1;
END;
END MY_PACKAGE;
/
-- using function in SQL
select MY_PACKAGE.MyFunction(123) as val
from dual
/
-- using function in PL/SQL
declare
val_ number;
begin
val_ := MY_PACKAGE.MyFunction(123);
end;
/
PHP不在我的竞争对手中,但这段代码显示了概念 -
// as select
$query1 = oci_parse($conn, 'select MY_PACKAGE.MyFunction(:id) as val from dual');
oci_bind_by_name($query1, ":id", $Param1);
oci_execute($query1);
// as anonymous block
$query1 = oci_parse($conn, 'BEGIN :val := MY_PACKAGE.MyFunction(:id); END;');
oci_bind_by_name($query1,':id',$id);
oci_bind_by_name($query1,':val',$val);
oci_execute($query1);