oracle 在sql plus中执行一个函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5127482/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 03:06:41  来源:igfitidea点击:

executing a function in sql plus

oraclefunctionsqlplus

提问by maher

I created a function in oracle that inserts records in specific tables and return an output according to what occurs within the function. e.g (ins_rec return number)

我在 oracle 中创建了一个函数,该函数在特定表中插入记录并根据函数内发生的情况返回输出。例如(ins_rec 返回编号)

How do I call this function and see its output in sql plus

如何调用此函数并在 sql plus 中查看其输出

回答by GriffeyDog

declare
  x number;
begin
  x := myfunc(myargs);
end;

Alternatively:

或者:

select myfunc(myargs) from dual;

回答by cagcowboy

One option would be:

一种选择是:

SET SERVEROUTPUT ON

EXEC DBMS_OUTPUT.PUT_LINE(your_fn_name(your_fn_arguments));

回答by CoderSteve

As another answer already said, call select myfunc(:y) from dual;, but you might find declaring and setting a variable in sqlplus a little tricky:

正如另一个答案已经说过的那样,调用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;