Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Newbie question: Is there a way to let "select ...from" statement accept a variable as a table name?

Re: Newbie question: Is there a way to let "select ...from" statement accept a variable as a table name?

From: Karsten Farrell <kfarrell_at_belgariad.com>
Date: Mon, 25 Nov 2002 18:57:44 GMT
Message-ID: <IouE9.93$xI5.7966875@newssvr21.news.prodigy.com>


phmyhn wrote:
> I created a procedure which has two IN type parameters. Then I
> declared a local variable and assign it to the concatenation of the
> two passed in variables. Then I wanted to use this variable as a table
> name for "select...from" statement. But I got error said that table
> name didn't exist. Is there a way to let the select statement get the
> value of the variable but not the literal name of the variable ? My
> code was like this:
> create or replace procedure addpara(p_para1 varchar2, p_para2
> varchar2)
> is
> v_name varchar2(20) := p_para1 || p_para2;
> begin
> select * from v_name where id = 10000; --if commented this
> line,there's no error
> dbms_output.put_line(v_name);
> end addpara;
> Any helps would be appreciated.

Change the select to:

execute immediate 'select * from ' || v_name || ' where id = 10000'; Received on Mon Nov 25 2002 - 12:57:44 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US