oracle 如何在pl sql developer中运行sql函数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35863314/
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-09 01:02:56  来源:igfitidea点击:

how to run a sql function in pl sql developer

oracleplsql

提问by suri

I am new to oracle. I created one function in oracle database using pl sql developer, and I executed successfully. Now I want to run that function from same pl sql developer by query. but it is not working properly. Below is my function.

我是 oracle 的新手。我使用pl sql developer在oracle数据库中创建了一个函数,并成功执行。现在我想通过查询从同一个 pl sql 开发人员运行该函数。但它不能正常工作。下面是我的功能。

create or replace function com.my_first_test_function(module_code out varchar2,                         
bpm_process_name out varchar2,module_name out varchar2,input in number)return number is
y_return number(1)
N_return varchar(200)
begin
if input='yes' then
Y_return :=select module_code ,bpm_process_name,module_name from com_tm_bpm_process_details;

if input='no' then nested_procedure_exception exception

but when I try to run this function using below query it is throwing some error message. can any one tell me how to call the function from pl sql developer.

但是当我尝试使用以下查询运行此函数时,它会抛出一些错误消息。谁能告诉我如何从pl sql developer调用该函数。

select * from  com.my_first_test_function(java.sql.Types.VARCHAR,java.sql.Types.VARCHAR,java.sql.Types.VARCHAR,'yes')

here I tried without out parameter values also but still no use.

在这里,我也尝试不使用参数值,但仍然没有用。

回答by Aleksej

To call a function in a SQL statement is intended to compute some return value, reading informations from parameters; so, functions with OUT parameters make not sense in SQL. If you need something that could handle OUT parameters, you can use procedures, within a PL/SQL block, passing variables as OUT parameters.

在 SQL 语句中调用函数是为了计算一些返回值,从参数中读取信息;因此,带有 OUT 参数的函数在 SQL 中没有意义。如果您需要可以处理 OUT 参数的东西,您可以在 PL/SQL 块中使用过程,将变量作为 OUT 参数传递。

About calling a FUNCTION, you can use a PL/SQL block, with variables:

关于调用 FUNCTION,您可以使用带有变量的 PL/SQL 块:

SQL> create or replace function f( n IN number) return number is
  2  begin
  3      return n * 2;
  4  end;
  5  /

Function created.

SQL> declare
  2      outNumber number;
  3  begin
  4      select f(10)
  5      into outNumber
  6      from dual;
  7      --
  8      dbms_output.put_line('outNumber: "' || outNumber || '"');
  9  end;
 10  /
outNumber: "20"

PL/SQL procedure successfully completed.

or even call it directly in a SQL query:

甚至直接在 SQL 查询中调用它:

SQL> select f(10) from dual;

     F(10)
----------
        20