判断表是否存在
if exists(select table_name from user_tables where table_name='Thyc') hen
drop table Thyc;
end if;
--这句不行
--下面这句也不行
declare
tcnt number;
begin
select count(*) into tcnt from user_tables where table_name='thyc';
if tcnt>1 then
drop table Thyc;
else
dbms_output.put_line('不存在!');
end if;
end;
--新手呀,莫笑我
if exists(select table_name from user_tables where table_name='Thyc') hen
drop table Thyc;
end if;
--这句不行
--下面这句也不行
declare
tcnt number;
begin
select count(*) into tcnt from user_tables where table_name='thyc';
if tcnt>1 then
drop table Thyc;
else
dbms_output.put_line('不存在!');
end if;
end;
--新手呀,莫笑我
c_sql := 'drop table Thyc';
execute immediate c_sql;
exception
when OTHERS THEN
IF SQLCODE = -00942 THEN
dbms_output.put_line('不存在!');
END IF;
END ;
可能是你的表名的问题
hyc varchar2(4000);
begin
hyc:='xxx' || to_Char(222);
dbms_output.put_line(hyc);
end;--但是这句也不显示xxx222
declare
c_sql varchar2(4000);
begin
c_sql := 'drop table Thyc';
execute immediate c_sql;
exception
when OTHERS THEN
IF SQLCODE = -00942 THEN
dbms_output.put_line('不存在!');
END IF;
END ;--是不是需要对系统怎么设置一下才可以利用dbms_output.put_line('不存在!');
这个方法打印文本?
set serveroutput on dbms_output.put_line() 才可以显示
SQL> begin
2 DBMS_OUTPUT.PUT_LINE('result');
3 end;
4 /
resultPL/SQL 过程已成功完成。
SQL> set serveroutput on
SQL> declare
2 c_sql varchar2(4000);
3 begin
4 c_sql := 'drop table THYC';
5 execute immediate c_sql;
6 exception
7 when OTHERS THEN
8 IF SQLCODE = -00942 THEN
9
10 dbms_output.put_line('不存在!');
11
12 END IF;
13 END ;
14 set serveroutput on
15 dbms_output.put_line('hyc');
16
declare
c_sql varchar2(4000);
begin
dbms_output.put_line('start');
c_sql := 'drop table THYC';
execute immediate c_sql;
exception
when OTHERS THEN
IF SQLCODE = -00942 THEN
dbms_output.put_line('不存在!');
END IF;
END ;
/