简单的执行方式:
drop table USERINFO; create table USERINFO ( EnglishName varchar(30), ChineseName varchar(30), Sex varchar(10), Age int, BirthPlace varchar(100), BirthDate date default sysdate );
上面的方式有个缺陷,如果表不存在,那么会drop语句会报错
ORA-00942: table or view does not exist
更加优秀的执行方式:
declare w_count int; w_name varchar(20); begin w_name:='USERINFO'; select count(*) into w_count from user_tables where table_name = w_name; if(w_count>0) then execute immediate 'drop table USERINFO'; end if; execute immediate 'create table USERINFO ( EnglishName varchar(30), ChineseName varchar(30), Sex varchar(10), Age int, BirthPlace varchar(100), BirthDate date default sysdate )'; end;