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 21:01:13 GMT
Message-ID: <tcwE9.120$TA6.11436126@newssvr21.news.prodigy.com>


Martin Doherty wrote:

> Karsten Farrell wrote:
> 

>> 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';
> 
> 
> Karsten,
> 
> Is it possible to retrieve the results of a query executed in this manner?
> 
>  From my knowledge of dynamic SQL in Pro*languages, it's going to be 
> more complex than this.
> 
> Martin Doherty
> 

You are absolutely correct. I guess I assumed the code was a snippit. You know what they say about people who 'assume' (or maybe they don't say that anymore). Just executing the select, without an INTO clause, will not give you any output. Received on Mon Nov 25 2002 - 15:01:13 CST

Original text of this message

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