json singh
json singh

Reputation: 305

PL/SQL take input as table

DECLARE 
 tablename table;
 nor number(10);
BEGIN 
    tablename:=&tablename;
    select count(*) into nor from tablename;
    dbms_output.put_line('The number of rows are '||nor);
END;
/

I am using this code to take table name as input from user and displaying the row count but it shows errors but if use a specific table name it runs fine!

Upvotes: 0

Views: 772

Answers (1)

Bruno Nalon Amaral
Bruno Nalon Amaral

Reputation: 36

DECLARE 
 tablename table;
 nor number(10);
BEGIN 
    tablename:=&tablename;
    execute immediate 'select count(*) from '|| tablename
      into nor;
    dbms_output.put_line('The number of rows are '||nor);
END;
/

You can try to use EXECUTE IMMDEDIATE

Upvotes: 1

Related Questions