oracle PLS-00231:函数不能在 SQL 中使用

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

PLS-00231: Function may not be used in SQL

oracleplsql

提问by David Silva

I want to test my pipelined function without creating a package. The following example is simplified:

我想在不创建包的情况下测试我的流水线函数。以下示例已简化:

DECLARE
    FUNCTION testDC RETURN NCOL PIPELINED IS
    BEGIN
        PIPE ROW(5);
    END;
BEGIN
    FOR cur IN (select * from table (testDC())) LOOP
        dbms_output.put_line('--> ');
    END LOOP;
END;

But I get this error:

但我收到此错误:

ORA-06550: line 7, column 7: pls-00231: function TESTDC may not be used in SQL
ORA-06550: line 7, column 7: PL/SQL: ORA-00904: : invalid identifier
ORA-06550: line 7, column 7: PL/SQL: SQL Statement ignored

ORA-06550:第 7 行,第 7 列:pls-00231:函数 TESTDC 不能用于 SQL
ORA-06550:第 7 行,第 7 列:PL/SQL:ORA-00904::无效标识符
ORA-06550:第 7 行,第 7 列:PL/SQL:忽略 SQL 语句

What is better way to test these function?

测试这些功能的更好方法是什么?

回答by kevinsky

Create your pipelined function as a standalone procedure or package member. Then you can call it from your script.

创建您的流水线函数作为独立过程或包成员。然后你可以从你的脚本中调用它。

Also ensure that the NCOL parameter you refer to is declared in a schema that can be accessed by the calling script.

还要确保您引用的 NCOL 参数是在调用脚本可以访问的模式中声明的。

回答by Marmite Bomber

You can't access a table function direct in PL/SQL - see the test case below. So as other pointed out you must define the table function as standalone or packaged.

您不能直接在 PL/SQL 中访问表函数 - 请参阅下面的测试用例。因此,正如其他人指出的那样,您必须将表函数定义为独立的或打包的。

 DECLARE
   res NUMBER; 
   FUNCTION testDC RETURN NCOL PIPELINED IS
     BEGIN
         PIPE ROW(5);
     END;

 BEGIN
         res := testDC();
         dbms_output.put_line('--> '||res);

 END;
 /


 ORA-06550: line 3, column 12:
 PLS-00653: aggregate/table functions are not allowed in PL/SQL scope