declare v_count int;
begin
select count(*) into v_count from tab where Tname = 'tongji_tmp' and tabType = 'table';
if v_count > 0 then --表存在则做Drop操作
drop table tongji_tmp;
end if;
create table tongji_tmp as select DptId, sum as pCount, 0 as fMarriage,0 as sMarriage,0 as oneChild, 0 as twoChild, 0 as oneBoy, 0 as oneGile, 0 as twoBoy, 0 as twoGile from Dptid_tmp;
select * from tongji_tmp;
end;
本人现在刚学oracle,上面的语句执行后报:出现符号“Drop”在需要下列之一时:
下面是begin case declare之类的。
也就if 语句块中不能执行,请高手帮个忙。公司也是首次使用oracle,同事也都不清楚,在网上也没能搜到,可能是这个问题除了我别人都会的原因吧。
begin
select count(*) into v_count from tab where Tname = 'tongji_tmp' and tabType = 'table';
if v_count > 0 then --表存在则做Drop操作
drop table tongji_tmp;
end if;
create table tongji_tmp as select DptId, sum as pCount, 0 as fMarriage,0 as sMarriage,0 as oneChild, 0 as twoChild, 0 as oneBoy, 0 as oneGile, 0 as twoBoy, 0 as twoGile from Dptid_tmp;
select * from tongji_tmp;
end;
本人现在刚学oracle,上面的语句执行后报:出现符号“Drop”在需要下列之一时:
下面是begin case declare之类的。
也就if 语句块中不能执行,请高手帮个忙。公司也是首次使用oracle,同事也都不清楚,在网上也没能搜到,可能是这个问题除了我别人都会的原因吧。
解决方案 »
- 请教各位Oracle高手,一条关于两张表的操作?
- 想把字段为空的纪录放在最前面
- 求一条SQL,有点意思。愣了
- 删除归档日志出现问题
- 请教oracle存储过程
- sql语句,求高手指教
- 【PL/SQL疑难杂症】关于PL/SQL语句问题,请求诊病????
- Update问题(循环替代)?
- *****散分,讨论:与公司签两年合同的前提下,公司出1万元让我参加oracle的在线图书馆培训,获得ocp,我同意还是不同意?*****
- 新年好,祝大家新的一年中大事有成。我现在在PL/SQL中怎样建表,又怎样使用程序与它连接起来
- 100分 oracle創建新數據庫?
- 请救急!我怎么把以前数据库下创建的ora 文件加载到现在数据库中? 谢谢
BEGIN
FOR T IN (SELECT 'TRUNCATE TABLE '||TABLE_NAME TRUN_TABLE,'DROP TABLE '||TABLE_NAME DROP_TABLE
FROM USER_TABLES WHERE TABLE_NAME IN('大写表名1','大写表名2')) LOOP
EXECUTE IMMEDIATE T.TRUN_TABLE;
EXECUTE IMMEDIATE T.DROP_TABLE;
END LOOP;
END;
/
....
if v_count > 0 then --表存在则做Drop操作
execute immediate 'drop table tongji_tmp';
end if;
....
后面的create语句也像这样写。
drop table tongji_tmp;
create table tongji_tmp as select DptId, sum as pCount, 0 as fMarriage,0 as sMarriage,0 as oneChild, 0 as twoChild, 0 as oneBoy, 0 as oneGile, 0 as twoBoy, 0 as twoGile from Dptid_tmp;
select * from tongji_tmp;
这段语句可以执行,但如果表不存在,则会报错
ATGC(花开蝶舞,木秀鸟栖) 的我看不懂。