Mega Code Archive

 
Categories / Oracle PLSQL / Stored Procedure Function
 

This function cannot be called from a SQL statement

SQL> SQL> CREATE TABLE MyTable (   2    num_col    NUMBER,   3    char_col   VARCHAR2(60)   4    ); Table created. SQL> SQL> SQL> CREATE OR REPLACE FUNCTION InsertTemp(   2    p_Num IN MyTable.num_col%TYPE,   3    p_Char IN MyTable.char_col%type)   4    RETURN NUMBER AS   5  BEGIN   6    INSERT INTO MyTable (num_col, char_col)   7      VALUES (p_Num, p_Char);   8    RETURN 0;   9  END InsertTemp;  10  / Function created. SQL> SQL> REM Illegal query SQL> SELECT InsertTemp(1, 'Hello')   2    FROM dual; SELECT InsertTemp(1, 'Hello')        * ERROR at line 1: ORA-14551: cannot perform a DML operation inside a query ORA-06512: at "RNTSOFT.INSERTTEMP", line 6 SQL> SQL> SQL> drop table MyTable; Table dropped. SQL>