首页 > 解决方案 > 试图检查表中是否存在记录-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是否已经存在,然后打印“存在”否则“不存在”。

标签: sqloracleplsql

解决方案


推荐阅读