Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: [PL/SQL] Help - Select into from a variable tablename?
Hi,
You can do it via dbms_sql package. It's my function which use one.
v_Cursor NUMBER; v_Command VARCHAR2(200) := Upper(RTrim(LTrim(p_SQL))); v_Result NUMBER; v_NumRows INTEGER;
v_NumRows := DBMS_SQL.Execute(v_Cursor); IF DBMS_SQL.Fetch_Rows(v_Cursor) > 0 THEN DBMS_SQL.Column_Value(v_Cursor, 1, v_Result);ELSE
DECLARE
numOfRows NUMBER;
BEGIN
numOfRows := admin_SQL('select count(*) from my_table');
dbms_output.put_line('Number of rows for table my_table is
'||to_Char(numOfRows));
END;
Have a nice day,
Slava
> From: David & Janet Harris <music_at_waymark.com>
> Newsgroups: comp.databases.oracle.misc
> Subject: [PL/SQL] Help - Select into from a variable tablename?
> Date: 19 ÁÐÒÅÌÑ 1997 Ç. 07:35
>
> I need some help selecting into from a variable tablename.
> Example:
>
> Procedure CountTable(tbl char) is
> cnt number;
> BEGIN
> select count(*) into cnt from tbl;
> dbms_output.put_line (tbl || ' ' || cnt);
> end;
>
> PL/SQL interprets tbl as an existing table and fails. I would like to
have a
> loop call this routine for each table in a user's schema yielding these
> results:
>
> Tablename Cnt
> --------- ---
> TABLE1 234
> TABLE2 823
> .
> .
> .
>
> Any ideas? Thanks in advance.
>
> --David H.
>
Received on Sat Apr 19 1997 - 00:00:00 CDT