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?
In article <5j97k7$1pn_at_news1-alterdial.uu.net>, David & Janet Harris
<music_at_waymark.com> writes
>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.
You can use the DBMS_SQL package to do dynamic sql in PL/SQL.
-- Jim SmithReceived on Sat Apr 19 1997 - 00:00:00 CDT