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!

dynamic table name after FROM

goodluck247Dec 28 2016 — edited Jan 16 2017

Hello all,

I have this rather simple function, which I am unable to compile successfully:

create or replace function lab_exists (p_in_labno worklist.labno%type, p_in_test test_desc.test_n%type) return boolean is

   v_exists boolean;

   v_number number;

begin

   -- determine table name based on the test number and verify if labno already exists in that table

   select count(*) into v_number from (select table_name from test_desc where test_n = p_in_test)

   where labno = p_in_labno;

   -- return true or false accordingly

   if v_number = 0 then

      v_exists := false;

   else

      v_exists := true;

   end if;

   return v_exists;

end;

It is obvious, that it has to do with the 'table name' after the FROM keyword.

Why can't I assign a table name dynamically?

Or, if I can, what am I doing wrong?

Thank you.

This post has been answered by unknown-7404 on Dec 28 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 13 2017
Added on Dec 28 2016
13 comments
6,282 views