sql里判断表存在不存在的语句

2025-03-01 00:17:17
推荐回答(1个)
回答1:

使用exists判断。
以Oracle为示例:
exists(select 1 from all_tables u where 条件一:限制用户名 and 条件二:限制表名)
查询系统字典表all_tables,判断表是否存在,存在则结果为真;不存在则结果为假
通过结合if语句使用:
if exists(select 1 from all_tables u where 条件一:限制用户名 and 条件二:限制表名) then 执行子句一
else 执行子句二;