我試圖寫一個小觸發我的數據庫,但我得到的錯誤:的SQLException:您不能指定目標表「P」的更新在FROM子句
的SQLException:你可以用」牛逼指定目標表「p」的更新在FROM子句
我使用的查詢是:
create trigger CheckVendibilitaPP
after update on hotel
for each row
if (old.IN_VENDITA=true and new.IN_VENDITA=false) then
update pacchettopreconfigurato as p
set IN_VENDITA=false
where p.id_pp in (select p2.id_pp
from pacchettopreconfigurato as p2 join hotel as h on p2.DESTINAZIONE_PACCHETTO = h.LUOGO
where h.id = new.id)
and (select count(*)
from pacchettopreconfigurato as p3 join hotel as h2 on p3.DESTINAZIONE_PACCHETTO = h2.LUOGO
where p3.id_pp = p.id_pp) > 0;
end if;;
我看到一些答案symilar問題,並嘗試了一些的有所示的技術,但沒有那些是有效的。在「SELECT id_pp FROM(select ...)AS c」塊中包裝查詢的第一部分,但那也不起作用。
我該如何重寫查詢以便停止拋出錯誤?
你不能做到這一點:「......從pacchettopreconfigurato爲P2加入」 ..您剛纔指定的表在FROM子句,因爲錯誤說 –
子查詢不能取參數AFAIK,所以我所做的是使用兩個布爾函數,然後將它們放在更新的where子句中。 – GPhilo