此 SQL 代码给我错误“第 2 行错误:PL/SQL:语句被忽略”,我正在处理 SQL oracle 应用程序 Express / APEX:我尝试了我能想到的一切,但它每次都会给我带来不同的问题。
CREATE or replace TRIGGER remove_artista
instead of delete on V_ARTISTA
REFERENCING old AS orow
FOR EACH ROW
BEGIN
if exists(select * from Utilizadores where pessoaID = orow.pessoaID) then
delete from Pessoas where pessoaID = orow.pessoaID;
ELSE
delete from Artistas where pessoaID = orow.pessoaID;
delete from Pessoas where pessoaID = orow.pessoaID;
end if;
END;
Run Code Online (Sandbox Code Playgroud)
风景:
create or replace view v_artista as
select
pessoaID, nome_p, sexo, data_nasc, nome_art, biografica
from Pessoas natural inner join Artistas;
Run Code Online (Sandbox Code Playgroud)
编辑:修复了代码上的一个小拼写错误。
我从您的触发器收到的完整错误如下:
LINE/COL ERROR
-------- -----------------------------------------------------------------
2/1 PL/SQL: Statement ignored
2/4 PLS-00204: function or pseudo-column 'EXISTS' may be used inside
a SQL statement only
Run Code Online (Sandbox Code Playgroud)
本质上,问题在于你不能if exists(...)像你所做的那样说。甲骨文不让你这么做。
相反,尝试将表中匹配行的数量选择Utilizadores到局部变量中,然后在if语句中使用它:
CREATE or replace TRIGGER remove_artista
instead of delete on V_ARTISTA
REFERENCING old AS orow
FOR EACH ROW
DECLARE
l_count INTEGER;
BEGIN
select count(*)
into l_count
from Utilizadores
where pessoaID = :orow.pessoaID;
if l_count > 0 then
delete from Pessoas where pessoaID = :orow.pessoaID;
ELSE
delete from Artistas where pessoaID = :orow.pessoaID;
delete from Pessoas where pessoaID = :orow.pessoaID;
end if;
END;
Run Code Online (Sandbox Code Playgroud)
我还需要替换orow为:orow. 进行此更改后,您的触发器也为我编译了。
| 归档时间: |
|
| 查看次数: |
11562 次 |
| 最近记录: |