简体   繁体   English

PL SQL多单行返回问题

[英]PL SQL more than single row returned issue

I'm executing the following query and I get "ORA-01427: single-row subquery returns more than one row". 我正在执行以下查询,并且得到“ ORA-01427:单行子查询返回多个行”。 The error returns in the DECODE which is located in the main SELECT. 错误返回到位于主SELECT中的DECODE中。 I cannot place the USER_PRF_NOTIFICATION_T table in the FROM section, as USER_PRF_NOTIFICATION_T may not contain any values. 我不能将USER_PRF_NOTIFICATION_T表放在FROM部分中,因为USER_PRF_NOTIFICATION_T可能不包含任何值。 If it does than the values in SEC_USER_PRIV.ENTITY_ID do not all exist in USER_PRF_NOTIFICATION_T.ENTITY_ID . 如果不是,则USER_PRF_NOTIFICATION_T.ENTITY_ID中并不全部存在SEC_USER_PRIV.ENTITY_ID中的值

    SELECT DISTINCT
    SEC_USER.USR_ID         AS USR_ID,
    SEC_USER.USR_FIRST_NAME AS USR_FIRST_NAME,
    SEC_USER.USR_LAST_NAME  AS USR_LAST_NAME,
    SEC_USER_PRIV.ROLE_ID   AS SYSTEM_ROLE_ID,
    DECODE (
              (
              SELECT
                  SYSTMTYP_CODE
              FROM
                  USER_PRF_NOTIFICATION_T
              WHERE
                  USER_PRF_NOTIFICATION_T.USR_ID = SEC_USER.USR_ID
              AND USER_PRF_NOTIFICATION_T.ENTITY_ID IN
                  (
                      SELECT
                          SERVER_T.SRV_ID
                      FROM
                          SERVER_T
                      WHERE
                          UPPER(SERVER_T.SRV_NAME) LIKE UPPER('%gen%') )
              AND USER_PRF_NOTIFICATION_T.ENTITY_TYP_CODE = 21), 1, 'SYSTEM', 2, 'TEST', NULL ,
            'ALL') AS ENTITY_SYSTM_TYP_NOTIFICATION
FROM
    SEC_USER_PRIV,
    SEC_USER
WHERE
    SEC_USER.USR_ID = SEC_USER_PRIV.USR_ID
AND ((
            SEC_USER_PRIV.ENTITY_TYP_CODE = 21
        AND SEC_USER_PRIV.ENTITY_ID IN (
            (
                SELECT
                    SERVER_T.SRV_ID
                FROM
                    SERVER_T
                WHERE
                    UPPER(SERVER_T.SRV_NAME) LIKE UPPER('%gen%') ))))

How can solve this? 怎么解决呢? referencing the entity ID directly obviously resolves that issue. 直接引用实体ID显然可以解决该问题。 I tried using tableof which contains all ID and trying: 我尝试使用包含所有ID的tableof并尝试:

USER_PRF_NOTIFICATION_T.ENTITY_ID IN (tableof) but I get the same error. USER_PRF_NOTIFICATION_T.ENTITY_ID IN(tableof),但出现相同的错误。 How can resolve this? 如何解决呢? I need to create a correlation between the ID selected in the FROM section and the ID used in the DECODE. 我需要在FROM部分中选择的ID和DECODE中使用的ID之间建立关联。

Thanks in advance. 提前致谢。

I think you added "NULL" in the list of key/value pairs and that is causing the error. 我认为您在键/值对列表中添加了“ NULL”,这导致了错误。

`1, 'SYSTEM', 2, 'TEST', NULL , 'ALL'`

Remove NULL here 在此处删除NULL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM