0

I have a function that takes table_name as input and returns a number. The function gets compiled properly but for some reason when I try test the function it throws error - missing keyword.

CREATE OR replace FUNCTION TEST_FUNCTION (name_table IN VARCHAR2) RETURN NUMBER

        IS         

          rday NUMBER;                
  BEGIN 

  execute immediate 
  'select day_i into rday
                FROM ' || name_table || '
                WHERE day_i = 1 and rownum = 1';

   return rday;

  END TEST_FUNCTION;

This is how I am testing it Select TEST_FUNCTION ('FDR_REP') from dual;

1 Answer 1

2

The syntax for execute immediate is different for an into clause try

CREATE OR replace FUNCTION TEST_FUNCTION (name_table IN VARCHAR2) RETURN NUMBER

        IS         

          rday NUMBER;                
  BEGIN 
   execute immediate  'select day_i 
                FROM ' || name_table || '
                WHERE day_i = 1 and rownum = 1' into rday;


   return rday;

  END TEST_FUNCTION;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.