Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.tools -> Re: Assigning a variable to a table name in FROM statement ???
"Bernhard Acke" <ba_at_metropolis.de> ????? news:3ad1a9f4$1_at_netnews.web.de...
> I want to get the number of datasets from a different tables,
> where table names are stored in a separate table.
>
>
> Is it possible to assign the table name dynamically in the
> FROM-Part of the SELECT-Statement (as a variable), so can do
> this with a loop.
>
>
> I thought of something like this, but it doesnt work:
>
>
> DECLARE
> actual_scheme_name VARCHAR(30) := 'students';
> actual_table_name VARCHAR(30) := 'adresses';
> number_of_datasets_entered NUMBER(10) := 0;
> BEGIN
> actual_table := actual_scheme_name || '.' || actual_table_name;
> SELECT count (rowid)
> INTO number_of_datasets_entered
> FROM actual_table;
> ============
> DBMS_OUTPUT.PUT_LINE(number_of_datasets_entered);
> EXCEPTION
> END;
On Oracle8i, you can use the following:
set serveroutput on;
DECLARE
actual_scheme_name VARCHAR(30) := 'students'; actual_table_name VARCHAR(30) := 'adresses'; actual_table varchar(61); number_of_datasets_entered NUMBER(10) := 0;sql_statement varchar2(2000);
![]() |
![]() |