dbalearner
Technical User
I am trying to check if a table belonging to a schema exists so I can describe it. The code is as follows:
set serveroutput on
set pagesize 0
declare
V_Owner sys.dba_tables.owner%TYPE := upper('&&owner');
V_Table sys.dba_tables.table_name%TYPE := upper('&&table');
V_NumRows integer := null;
begin
select count(1) into V_NUmRows from dual
where exists (select null from dba_tables where owner = V_Owner and table_name = V_Table);
if V_numRows > 0
then
dbms_output.put_line (' ');
desc V_Owner.V_Table;
else
dbms_output.put_line ('No record!');
end if;
end;
/
exit
Enter value for owner: scott
old 2: V_Owner sys.dba_tables.owner%TYPE := upper('&&owner');
new 2: V_Owner sys.dba_tables.owner%TYPE := upper('scott');
Enter value for table: emp
old 3: V_Table sys.dba_tables.table_name%TYPE := upper('&&table');
new 3: V_Table sys.dba_tables.table_name%TYPE := upper('emp');
desc V_Owner.V_Table;
*
ERROR at line 11:
ORA-06550: line 11, column 3:
PLS-00103: Encountered the symbol "DESC" when expecting one of the following:
begin case declare else elsif end exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-identifier>
<a bind variable> << close current delete fetch lock insert
open rollback savepoint set sql execute commit forall merge
<a single-quoted SQL string> pipe
<an alternatively-quoted SQL string>
The symbol "DESC" was ignored.
Any idea how I can make it work or I need to use dynamic SQL for describing the table?
Thanks
set serveroutput on
set pagesize 0
declare
V_Owner sys.dba_tables.owner%TYPE := upper('&&owner');
V_Table sys.dba_tables.table_name%TYPE := upper('&&table');
V_NumRows integer := null;
begin
select count(1) into V_NUmRows from dual
where exists (select null from dba_tables where owner = V_Owner and table_name = V_Table);
if V_numRows > 0
then
dbms_output.put_line (' ');
desc V_Owner.V_Table;
else
dbms_output.put_line ('No record!');
end if;
end;
/
exit
Enter value for owner: scott
old 2: V_Owner sys.dba_tables.owner%TYPE := upper('&&owner');
new 2: V_Owner sys.dba_tables.owner%TYPE := upper('scott');
Enter value for table: emp
old 3: V_Table sys.dba_tables.table_name%TYPE := upper('&&table');
new 3: V_Table sys.dba_tables.table_name%TYPE := upper('emp');
desc V_Owner.V_Table;
*
ERROR at line 11:
ORA-06550: line 11, column 3:
PLS-00103: Encountered the symbol "DESC" when expecting one of the following:
begin case declare else elsif end exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-identifier>
<a bind variable> << close current delete fetch lock insert
open rollback savepoint set sql execute commit forall merge
<a single-quoted SQL string> pipe
<an alternatively-quoted SQL string>
The symbol "DESC" was ignored.
Any idea how I can make it work or I need to use dynamic SQL for describing the table?
Thanks