if条件下是否允许子查询

问题描述 投票:0回答:1

正确代码

"BEGIN 
    FOR ievt IN (
        SELECT 
            evt_udfchar06,evt_code,evt_enteredby 
        FROM 
            r5events 
        WHERE rowid       = :rowid ) LOOP 
        
        IF o7sess.cur_user = 'R5' AND ievt.evt_udfchar06 (SELECT evt_udfchar06 FROM r5events WHERE rowid <>:rowid) THEN 
            RAISE_APPLICATION_ERROR(-20004,''Incident number is associated with other WO.''); 
        END IF; 
        --o7sess.cur_user; 
    END LOOP; 
END;" 

PLS-00405: subquery not allowed in this context

if 条件是否允许子查询

oracle plsql
1个回答
0
投票

if 条件是否允许子查询

没有。

无论使用:

  • SELECT ... INTO ...
    IF
    语句之前;或

  • 检查光标中的其他行:

    BEGIN 
      FOR ievt IN (
        SELECT *
        FROM   (
          SELECT evt_udfchar06,
                 evt_code,
                 evt_enteredby,
                 COUNT(*) OVER (PARTITION BY evt_udfchar06) AS num_rows
         FROM    r5events
       )
       WHERE  rowid = :rowid
     ) LOOP 
       IF o7sess.cur_user = 'R5'
          AND ievt.num_rows > 1
       THEN 
         RAISE_APPLICATION_ERROR(-20004,'Incident number is associated with other WO.'); 
       END IF; 
       --o7sess.cur_user; 
      END LOOP; 
    END;
    
© www.soinside.com 2019 - 2024. All rights reserved.