【发布时间】:2011-07-04 21:22:46
【问题描述】:
我在 oracle 中创建了一个函数,它在特定表中插入记录并根据函数中发生的情况返回输出。例如(ins_rec 返回编号)
如何调用这个函数并在sql plus中查看它的输出
【问题讨论】:
我在 oracle 中创建了一个函数,它在特定表中插入记录并根据函数中发生的情况返回输出。例如(ins_rec 返回编号)
如何调用这个函数并在sql plus中查看它的输出
【问题讨论】:
正如另一个答案已经说过的,请致电 select myfunc(:y) from dual; ,但您可能会发现在 sqlplus 中声明和设置变量有点棘手:
sql> var y number
sql> begin
2 select 7 into :y from dual;
3 end;
4 /
PL/SQL procedure successfully completed.
sql> print :y
Y
----------
7
sql> select myfunc(:y) from dual;
【讨论】:
declare
x number;
begin
x := myfunc(myargs);
end;
或者:
select myfunc(myargs) from dual;
【讨论】:
select myfunc(myargs) from dual; 为我工作。我遇到了delcare 版本的问题。
select 语句中使用修改数据的函数。
select 语句用于非 DML,即不对数据执行任何更新。你得到的错误是ORA-14551: cannot perform a DML operation inside a query。
一种选择是:
SET SERVEROUTPUT ON
EXEC DBMS_OUTPUT.PUT_LINE(your_fn_name(your_fn_arguments));
【讨论】: