sql - 试图检查表中是否存在记录-Oracle sql
问题描述
declare
ac_num accounts_table.account_id%type:=1;
begin
IF EXISTS (SELECT account_id FROM accounts_table WHERE account_id= ac_num) THEN
dbms_output.put_line('exists');
else
dbms_output.put_line('not exists');
end if;
end;
得到这样的错误
ORA-06550:第 4 行,第 4 列:PLS-00204:函数或伪列 'EXISTS' 只能在 SQL 语句中使用 ORA-06550:第 4 行,第 1 列:PL/SQL:语句被忽略 2.ac_num accounts_table .account_id%type:=1; 3. 开始 4. IF EXISTS (SELECT account_id FROM accounts_table WHERE account_id= ac_num) >THEN 5. dbms_output.put_line('exists'); 6. 其他
我需要检查 1accounts_table
是否已经存在,然后打印“存在”否则“不存在”。
解决方案
推荐阅读
- python - 如何使用python以文本模式读取bz2压缩文件?
- django - 将 SQL 查询转换为 django 模型
- ruby - 类语句的奇怪输出
- c++ - 如何在保持最小距离的同时沿有限线随机采样?
- android - 将 dialogFragment 作为 LiveData 的参数传递
- javascript - 画布宽度和高度有时无法调整大小
- javascript - 为什么我的 IF 语句没有执行?以及为什么即使我插入了 clearStatement 调用,间隔仍会继续运行
- mongodb - MongoDB 多个嵌套组
- azure - 如何访问 Azure 管道中的环境变量?
- python - 是否可以在 Google TPU 上运行常规 python 代码?