Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Inserting with WITH FUNCTION Select is giving error

NSK2KSNOct 5 2018 — edited Oct 6 2018

Hi Experts,

Below select query is working fine for me, but am not able to insert the result using insert statement., Please provide me some suggestions

WITH FUNCTION T11 (P_A1 VARCHAR2) RETURN NUMBER

IS

BEGIN

IF P_A1 = 'A' THEN RETURN 10;

ELSE

RETURN 100;

END IF;

END;

SELECT T11('A1') FROM DUAL;

now the result what ever is output of the above query am trying to insert into table

CREATE TABLE T1 (A1 NUMBER);

so I have written below queries, but getting errors:

Insert statement tried 1

INSERT INTO T1 (A1)

WITH FUNCTION T11 (P_A1 VARCHAR2) RETURN NUMBER

IS

BEGIN

IF P_A1 = 'A' THEN RETURN 10;

ELSE

RETURN 100;

END IF;

END;

SELECT T11('A1') FROM DUAL;

Error for above insert:

ORA-00904: "T11": invalid identifier

00904. 00000 -  "%s: invalid identifier"

*Cause:   

*Action:

Error at Line: 12 Column: 8

Insert statement tried 2

WITH FUNCTION T11 (P_A1 VARCHAR2) RETURN NUMBER

IS

BEGIN

IF P_A1 = 'A' THEN RETURN 10;

ELSE

RETURN 100;

END IF;

END;

INSERT INTO T1 (A1)

SELECT T11('A1') FROM DUAL;

Error for above insert option 2

ORA-00928: missing SELECT keyword

00928. 00000 -  "missing SELECT keyword"

*Cause:   

*Action:

Error at Line: 12 Column: 1

This post has been answered by mathguy on Oct 5 2018
Jump to Answer
Comments
Post Details
Added on Oct 5 2018
4 comments
2,797 views