ORA-03113 SQL中select语句全表扫描带来的异常

今天在ERP系统的维护过程中,业务人员反馈了一个问题过来,是ERP系统生产单模块的预览打印报表出错,看到后我逐步做了以下的排查:

1、尝试其他单据是否存在相同问题

2、直接打开水晶报表,将参数代入看看是否是报表问题

排查之后逐渐发现,问题出在数据源身上,找到返回数据集的存储过程,进入测试窗口检查是否运行正常,结果发现运行即进入卡死状态,进程无法中断,只好强行退出PL/SQL,这时候我估计到问题出在SQL语句上,因此将SQL语句复制到新的窗口,代入参数,如下:

SELECT WO_NBR,WO_LOT,WO_TYPE,WO_TYPE2 ,WO_PART, WO_QTY_ORD,WO_QTY_COMP,WO_QTY_RJCT,WO_LINE,WO_ORD_DATE,WO_REL_DATE,WO_DUE_DATE,WO_STATUS,WO_CLOSE_BY,WO_CLOSE_DATE,
         WO_SO_NBR,WO_SO_LINE,WO_FGOV_PER,WO_VEND,WO_SEND,WO_SOFT,WO_SOFT_VER,WO_ECA_NBR,WO_ECA_VER,WO_COUNT_OUTPUT,WO_ECN_NBR ,WO_TYPE1, WO_SKDR_NBR, WO_MAN_HAUR, WO_LIST_UPDATED,WO_SCHEDULE_DATE,
         WO_STD_PL,WO_ADD_SPARE, WO_ADD_SCREEN,WO_COMMON_ONLY,WO_RMKS,cast(WO_OTHER_RMKS as varchar2(1024)) as WO_OTHER_RMKS,WO_SITE,WO_PROG_CODE, WO_DOC_CODE,WO_CRT_BY,WO_CRT_DATE,WO_MOD_TIMES,WO_MOD_BY,WO_MOD_DATE,WO_CHAR1,WO_CHAR2,WO_CHAR3,WO_CHAR4,WO_CHAR5,
         WO_CHAR6, WO_QTY1,WO_QTY2,WO_WF_STATUS WO_PST,WO_PST_BY,WO_PST_DATE,WO_SRC_NBR,WO_SRC_LINE,WO_SRC_LOT,WO_PT_LOT,WO_TRY_NBR,
         OEM_MSTR.*,

        OEMDO_LOGO_COUNT,OEMDO_MN_LOGO,OEMDO_DEF_LANG,OEMDO_S_LOGO,
           OEMDC_NBR,OEMDC_VERSION, OEMDC_NAME,OEMDC_EN_COMP,(OEMDC_EN_QTY_PER_M/OEMDC_EN_QTY_PER_D) AS OEMDC_EN_QTY_PER,OEMDC_PT_MSTR.PT_UM AS OEMDC_EN_COMP_UM,
           OEMDC_RMKS,

        WO_PT_MSTR.PT_DESC1 AS WO_PT_DESC1, WO_PT_MSTR.PT_DESC2 AS WO_PT_DESC2,
        WO_PT_MSTR.PT_DESC1  AS WO_PT_DESC,
        WO_PT_MSTR.PT_DRAW,WO_PT_MSTR.PT_CLASS AS WO_PT_CLASS,WO_PT_MSTR.PT_GROUP AS WO_PT_GROUP,WO_PT_MSTR.PT_MD AS PT_MD,

        SOFT_PT_MSTR.PT_DESC1 AS SOFT_PT_DESC1, SOFT_PT_MSTR.PT_DESC2 AS SOFT_PT_DESC2,
        SOFT_PT_MSTR.PT_DESC1 AS SOFT_PT_DESC,

        OEMDC_PT_MSTR.PT_DESC1 AS OEMDC_EN_COMP_DESC1,OEMDC_PT_MSTR.PT_DESC2 AS OEMDC_EN_COMP_DESC2,SOD_CMMT ,SO_CUST,
        SC4_MSTR.*,
        SOD_PART_QTY,
        SOD_SC_QTY,SC5_DESC,OEMDO_SFS_NBR,OEMDO_SFS_VERSION,A.GEND_NAME AS MB_DESC ,B.GEND_NAME AS INTERFACE_DESC,SOD_SFS_NBR,SOD_SFS_VERSION,
        SFS_S_LOGO,SFS_MN_LOGO,SFSD1_MN_LANG,wo_print_times,
        wo_try_nbr,try_task_no,try_content,try_aim

 FROM
        WO_MSTR JOIN PT_MSTR  WO_PT_MSTR ON WO_PART = WO_PT_MSTR.PT_PART
           LEFT JOIN OEM_MSTR ON WO_ECA_NBR = OEM_NBR AND WO_ECA_VER = OEM_VERSION
           LEFT JOIN OEMDC_DET ON OEM_NBR = OEMDC_NBR AND OEM_VERSION = OEMDC_VERSION
           LEFT JOIN OEMDO_DET ON OEM_NBR = OEMDO_NBR AND OEM_VERSION = OEMDO_VERSION
           LEFT JOIN PT_MSTR  OEMDC_PT_MSTR ON TRIM(OEMDC_EN_COMP) = TRIM(OEMDC_PT_MSTR.PT_PART)
           LEFT JOIN PT_MSTR  SOFT_PT_MSTR ON TRIM(WO_SOFT) = SOFT_PT_MSTR.PT_PART
           LEFT JOIN GEND_DET A ON OEM_MB_PROJECT = A.GEND_OPTION AND A.GEND_GEN =‘SBGD_SCHEME‘
           LEFT JOIN GEND_DET B ON OEM_INTER_REQ = B.GEND_OPTION AND B.GEND_GEN =‘INTERFACE_REQ‘

           LEFT JOIN SOD_DET ON SOD_NBR = WO_SO_NBR AND SOD_LINE = WO_SO_LINE
           LEFT JOIN SO_MSTR ON SO_NBR  = SOD_NBR
           LEFT JOIN  SFS_MSTR ON SFS_NBR = SOD_SFS_NBR AND SFS_VERSION = SOD_SFS_VERSION
           LEFT JOIN SFSD1_DET ON SFSD1_NBR = SFS_NBR AND SFSD1_VERSION = SFS_VERSION AND SFSD1_DEF_LANG = 1
           LEFT JOIN SC5_MSTR ON SC5_CODE  = SOD_SC5 AND SC5_CURR = SO_CURR  AND SOD_REQ_DATE BETWEEN  SC5_START AND SC5_EXPIRE   -- SC5_EXPIRE > TRUNC(SYSDATE, ‘DD‘)
           LEFT JOIN SC4_MSTR ON SC4_CODE  = SOD_SC4_CODE AND SC4_CURR = SO_CURR  AND SOD_REQ_DATE BETWEEN SC4_START AND SC4_EXPIRE
           left join try_mstr on wo_try_nbr=try_nbr
    WHERE (WO_NBR = ‘GWH17040102‘ ) AND
         (WO_LOT = ‘ ‘) AND
          (OEMDC_NAME  IN (SELECT GEND_OPTION
                                          FROM GEND_DET
                                          WHERE GEND_GEN =‘MT_COMP‘
                                               AND (GEND_PROPERTY2 =‘Y‘ OR GEND_PROPERTY2 =‘Y‘))
                         OR ISEQUAL(OEMDC_NAME , ‘‘) = 1 )

执行结果如下:

接着又一次进入了卡死状态,PL/SQL客户端崩溃,只好重新登录。

之后为了减少客户端崩溃的次数,思索问题原因和问题解决方案,度娘查了有一会,可能查的方向有所偏差,没搜到能够解决问题的办法,于是只好自己通过调试来解决问题。首先,对于SQL方面的问题,我一般从两个地方入手:一个连表处,一个是列。

刚开始从连表处进行调试,第一次调试顺利的SQL如下:

SELECT count(1)

 FROM
        WO_MSTR JOIN PT_MSTR  WO_PT_MSTR ON WO_PART = WO_PT_MSTR.PT_PART
           LEFT JOIN OEM_MSTR ON WO_ECA_NBR = OEM_NBR AND WO_ECA_VER = OEM_VERSION
           LEFT JOIN OEMDC_DET ON OEM_NBR = OEMDC_NBR AND OEM_VERSION = OEMDC_VERSION
           LEFT JOIN OEMDO_DET ON OEM_NBR = OEMDO_NBR AND OEM_VERSION = OEMDO_VERSION
           LEFT JOIN PT_MSTR  OEMDC_PT_MSTR ON TRIM(OEMDC_EN_COMP) = TRIM(OEMDC_PT_MSTR.PT_PART)
           LEFT JOIN PT_MSTR  SOFT_PT_MSTR ON TRIM(WO_SOFT) = SOFT_PT_MSTR.PT_PART
           LEFT JOIN GEND_DET A ON OEM_MB_PROJECT = A.GEND_OPTION AND A.GEND_GEN =‘SBGD_SCHEME‘
           LEFT JOIN GEND_DET B ON OEM_INTER_REQ = B.GEND_OPTION AND B.GEND_GEN =‘INTERFACE_REQ‘

           LEFT JOIN SOD_DET ON SOD_NBR = WO_SO_NBR AND SOD_LINE = WO_SO_LINE
           LEFT JOIN SO_MSTR ON SO_NBR  = SOD_NBR
           LEFT JOIN  SFS_MSTR ON SFS_NBR = SOD_SFS_NBR AND SFS_VERSION = SOD_SFS_VERSION
           LEFT JOIN SFSD1_DET ON SFSD1_NBR = SFS_NBR AND SFSD1_VERSION = SFS_VERSION AND SFSD1_DEF_LANG = 1
           --LEFT JOIN SC5_MSTR ON SC5_CODE  = SOD_SC5 AND SC5_CURR = SO_CURR  AND SOD_REQ_DATE BETWEEN  SC5_START AND SC5_EXPIRE   -- SC5_EXPIRE > TRUNC(SYSDATE, ‘DD‘)
           --LEFT JOIN SC4_MSTR ON SC4_CODE  = SOD_SC4_CODE AND SC4_CURR = SO_CURR  AND SOD_REQ_DATE BETWEEN SC4_START AND SC4_EXPIRE
           left join try_mstr on wo_try_nbr=try_nbr
    WHERE (WO_NBR = ‘GWH17040102‘ ) AND
         (WO_LOT = ‘ ‘) AND
          (OEMDC_NAME  IN (SELECT GEND_OPTION
                                          FROM GEND_DET
                                          WHERE GEND_GEN =‘MT_COMP‘
                                               AND (GEND_PROPERTY2 =‘Y‘ OR GEND_PROPERTY2 =‘Y‘))
                         OR ISEQUAL(OEMDC_NAME , ‘‘) = 1 )

虽然调试成功,但是却牺牲了业务需求,业务数据方面不满足实际,因此需要进行下一步尝试,紧接着打算从属性列方面着手,由于之前已有select后面最好带具体的列名的常识,

因此在调试中,直接将OEM_MSTR.*和SC4_MSTR.*这两个全表扫描进行注释,避免执行这两句SQL

SELECT WO_NBR,WO_LOT,WO_TYPE,WO_TYPE2 ,WO_PART, WO_QTY_ORD,WO_QTY_COMP,WO_QTY_RJCT,WO_LINE,WO_ORD_DATE,WO_REL_DATE,WO_DUE_DATE,WO_STATUS,WO_CLOSE_BY,WO_CLOSE_DATE,
         WO_SO_NBR,WO_SO_LINE,WO_FGOV_PER,WO_VEND,WO_SEND,WO_SOFT,WO_SOFT_VER,WO_ECA_NBR,WO_ECA_VER,WO_COUNT_OUTPUT,WO_ECN_NBR ,WO_TYPE1, WO_SKDR_NBR, WO_MAN_HAUR, WO_LIST_UPDATED,WO_SCHEDULE_DATE,
         WO_STD_PL,WO_ADD_SPARE, WO_ADD_SCREEN,WO_COMMON_ONLY,WO_RMKS,cast(WO_OTHER_RMKS as varchar2(1024)) as WO_OTHER_RMKS,WO_SITE,WO_PROG_CODE, WO_DOC_CODE,WO_CRT_BY,WO_CRT_DATE,WO_MOD_TIMES,WO_MOD_BY,WO_MOD_DATE,WO_CHAR1,WO_CHAR2,WO_CHAR3,WO_CHAR4,WO_CHAR5,
         WO_CHAR6, WO_QTY1,WO_QTY2,WO_WF_STATUS WO_PST,WO_PST_BY,WO_PST_DATE,WO_SRC_NBR,WO_SRC_LINE,WO_SRC_LOT,WO_PT_LOT,WO_TRY_NBR,
         --OEM_MSTR.*,

        OEMDO_LOGO_COUNT,OEMDO_MN_LOGO,OEMDO_DEF_LANG,OEMDO_S_LOGO,
           OEMDC_NBR,OEMDC_VERSION, OEMDC_NAME,OEMDC_EN_COMP,(OEMDC_EN_QTY_PER_M/OEMDC_EN_QTY_PER_D) AS OEMDC_EN_QTY_PER,OEMDC_PT_MSTR.PT_UM AS OEMDC_EN_COMP_UM,
           OEMDC_RMKS,

        WO_PT_MSTR.PT_DESC1 AS WO_PT_DESC1, WO_PT_MSTR.PT_DESC2 AS WO_PT_DESC2,
        WO_PT_MSTR.PT_DESC1  AS WO_PT_DESC,
        WO_PT_MSTR.PT_DRAW,WO_PT_MSTR.PT_CLASS AS WO_PT_CLASS,WO_PT_MSTR.PT_GROUP AS WO_PT_GROUP,WO_PT_MSTR.PT_MD AS PT_MD,

        SOFT_PT_MSTR.PT_DESC1 AS SOFT_PT_DESC1, SOFT_PT_MSTR.PT_DESC2 AS SOFT_PT_DESC2,
        SOFT_PT_MSTR.PT_DESC1 AS SOFT_PT_DESC,

        OEMDC_PT_MSTR.PT_DESC1 AS OEMDC_EN_COMP_DESC1,OEMDC_PT_MSTR.PT_DESC2 AS OEMDC_EN_COMP_DESC2,SOD_CMMT ,SO_CUST,
        --SC4_MSTR.*,
        SOD_PART_QTY,
        SOD_SC_QTY,SC5_DESC,OEMDO_SFS_NBR,OEMDO_SFS_VERSION,A.GEND_NAME AS MB_DESC ,B.GEND_NAME AS INTERFACE_DESC,SOD_SFS_NBR,SOD_SFS_VERSION,
        SFS_S_LOGO,SFS_MN_LOGO,SFSD1_MN_LANG,wo_print_times,
        wo_try_nbr,try_task_no,try_content,try_aim

 FROM
        WO_MSTR JOIN PT_MSTR  WO_PT_MSTR ON WO_PART = WO_PT_MSTR.PT_PART
           LEFT JOIN OEM_MSTR ON WO_ECA_NBR = OEM_NBR AND WO_ECA_VER = OEM_VERSION
           LEFT JOIN OEMDC_DET ON OEM_NBR = OEMDC_NBR AND OEM_VERSION = OEMDC_VERSION
           LEFT JOIN OEMDO_DET ON OEM_NBR = OEMDO_NBR AND OEM_VERSION = OEMDO_VERSION
           LEFT JOIN PT_MSTR  OEMDC_PT_MSTR ON TRIM(OEMDC_EN_COMP) = TRIM(OEMDC_PT_MSTR.PT_PART)
           LEFT JOIN PT_MSTR  SOFT_PT_MSTR ON TRIM(WO_SOFT) = SOFT_PT_MSTR.PT_PART
           LEFT JOIN GEND_DET A ON OEM_MB_PROJECT = A.GEND_OPTION AND A.GEND_GEN =‘SBGD_SCHEME‘
           LEFT JOIN GEND_DET B ON OEM_INTER_REQ = B.GEND_OPTION AND B.GEND_GEN =‘INTERFACE_REQ‘

           LEFT JOIN SOD_DET ON SOD_NBR = WO_SO_NBR AND SOD_LINE = WO_SO_LINE
           LEFT JOIN SO_MSTR ON SO_NBR  = SOD_NBR
           LEFT JOIN  SFS_MSTR ON SFS_NBR = SOD_SFS_NBR AND SFS_VERSION = SOD_SFS_VERSION
           LEFT JOIN SFSD1_DET ON SFSD1_NBR = SFS_NBR AND SFSD1_VERSION = SFS_VERSION AND SFSD1_DEF_LANG = 1
           LEFT JOIN SC5_MSTR ON SC5_CODE  = SOD_SC5 AND SC5_CURR = SO_CURR  AND SOD_REQ_DATE BETWEEN  SC5_START AND SC5_EXPIRE   -- SC5_EXPIRE > TRUNC(SYSDATE, ‘DD‘)
           LEFT JOIN SC4_MSTR ON SC4_CODE  = SOD_SC4_CODE AND SC4_CURR = SO_CURR  AND SOD_REQ_DATE BETWEEN SC4_START AND SC4_EXPIRE
           left join try_mstr on wo_try_nbr=try_nbr
    WHERE (WO_NBR = ‘GWH17040102‘ ) AND
         (WO_LOT = ‘ ‘) AND
          (OEMDC_NAME  IN (SELECT GEND_OPTION
                                          FROM GEND_DET
                                          WHERE GEND_GEN =‘MT_COMP‘
                                               AND (GEND_PROPERTY2 =‘Y‘ OR GEND_PROPERTY2 =‘Y‘))
                         OR ISEQUAL(OEMDC_NAME , ‘‘) = 1 )

结果,SQL顺利执行,并返回受影响的行集,这时候我就想有可能已经找到原因了,同时,如果真的是这个问题,那么解决方案可以将*号替换为具体需要的列,在完全不影响需求而且SQL可行的情况下解决这个问题,于是开始尝试:

SELECT WO_NBR,WO_LOT,WO_TYPE,WO_TYPE2 ,WO_PART, WO_QTY_ORD,WO_QTY_COMP,WO_QTY_RJCT,WO_LINE,WO_ORD_DATE,WO_REL_DATE,WO_DUE_DATE,WO_STATUS,WO_CLOSE_BY,WO_CLOSE_DATE,
         WO_SO_NBR,WO_SO_LINE,WO_FGOV_PER,WO_VEND,WO_SEND,WO_SOFT,WO_SOFT_VER,WO_ECA_NBR,WO_ECA_VER,WO_COUNT_OUTPUT,WO_ECN_NBR ,WO_TYPE1, WO_SKDR_NBR, WO_MAN_HAUR, WO_LIST_UPDATED,WO_SCHEDULE_DATE,
         WO_STD_PL,WO_ADD_SPARE, WO_ADD_SCREEN,WO_COMMON_ONLY,WO_RMKS,cast(WO_OTHER_RMKS as varchar2(1024)) as WO_OTHER_RMKS,WO_SITE,WO_PROG_CODE, WO_DOC_CODE,WO_CRT_BY,WO_CRT_DATE,WO_MOD_TIMES,WO_MOD_BY,WO_MOD_DATE,WO_CHAR1,WO_CHAR2,WO_CHAR3,WO_CHAR4,WO_CHAR5,
         WO_CHAR6, WO_QTY1,WO_QTY2,WO_WF_STATUS WO_PST,WO_PST_BY,WO_PST_DATE,WO_SRC_NBR,WO_SRC_LINE,WO_SRC_LOT,WO_PT_LOT,WO_TRY_NBR,

         OEM_NBR, OEM_VERSION, OEM_APPLY, OEM_CUST, OEM_BRAND, OEM_STATUS, OEM_STCHG_BY, OEM_STCHG_DATE, OEM_MT, OEM_CUST_TYPE, OEM_CFG_TYPE,
         OEM_SAME, OEM_MB_PRO, OEM_SCREEN, OEM_LEVEL, OEM_QUALITY, OEM_BC_TYPE, OEM_URGENCY, OEM_RMKS, OEM_TEMPLATE, OEM_NG, OEM_NG_BY, OEM_NG_DATE,
         OEM_NG_REASON, OEM_MT_BY, OEM_MT_DATE, OEM_TRY, OEM_EMC, OEM_SITE, OEM_WF_STATUS, OEM_PROG_CODE, OEM_CRT_BY, OEM_CRT_DATE, OEM_MOD_TIMES,
         OEM_MOD_BY, OEM_MOD_DATE, OEM_PST, OEM_PST_BY, OEM_PST_DATE, OEM_APRV, OEM_APRV_BY, OEM_APRV_DATE, OEM_CHAR1, OEM_CHAR2, OEM_CHAR3,
         OEM_CHAR4, OEM_CHAR5, OEM_CHAR6, OEM_QTY1, OEM_QTY2, OEM_SRC_NBR, OEM_MTP_FLOW, OEM_DISABLED, OEM_MB_REQ, OEM_PW_REQ, OEM_MB_PROJECT,
         OEM_INTER_REQ, OEM_COUNTRY, OEM_MAC_REQ, OEM_MATERIAL, OEM_CI_INTERFACE, OEM_DATE, OEM_DSGN_NBR, OEM_APP_MSTR, OEM_PACK_TYPE, OEM_BOTTOM_CODE,
         OEM_SALE_METHOD,
         --OEM_MSTR.*,

        OEMDO_LOGO_COUNT,OEMDO_MN_LOGO,OEMDO_DEF_LANG,OEMDO_S_LOGO,
           OEMDC_NBR,OEMDC_VERSION, OEMDC_NAME,OEMDC_EN_COMP,(OEMDC_EN_QTY_PER_M/OEMDC_EN_QTY_PER_D) AS OEMDC_EN_QTY_PER,OEMDC_PT_MSTR.PT_UM AS OEMDC_EN_COMP_UM,
           OEMDC_RMKS,

        WO_PT_MSTR.PT_DESC1 AS WO_PT_DESC1, WO_PT_MSTR.PT_DESC2 AS WO_PT_DESC2,
        WO_PT_MSTR.PT_DESC1  AS WO_PT_DESC,
        WO_PT_MSTR.PT_DRAW,WO_PT_MSTR.PT_CLASS AS WO_PT_CLASS,WO_PT_MSTR.PT_GROUP AS WO_PT_GROUP,WO_PT_MSTR.PT_MD AS PT_MD,

        SOFT_PT_MSTR.PT_DESC1 AS SOFT_PT_DESC1, SOFT_PT_MSTR.PT_DESC2 AS SOFT_PT_DESC2,
        SOFT_PT_MSTR.PT_DESC1 AS SOFT_PT_DESC,

        OEMDC_PT_MSTR.PT_DESC1 AS OEMDC_EN_COMP_DESC1,OEMDC_PT_MSTR.PT_DESC2 AS OEMDC_EN_COMP_DESC2,SOD_CMMT ,SO_CUST,
        --SC4_MSTR.*,
        SC4_CODE, SC4_DESC, SC4_CURR, SC4_START, SC4_EXPIRE, SC4_BUY, SC4_SCREEN_INCL, SC4_SC_GRT, SC4_FREE, SC4_PR_DISC, SC4_PR_DISC_QTY,
        SC4_PR_ADJ, SC4_PR_ADJ_QTY, SC4_FR_SPARE, SC4_FR_SPARE_PCT, SC4_FR_SUIT, SC4_FR_SUIT_PCT, SC4_SPARE_PCT, SC4_PRJ, SC4_RMKS, SC4_WF_STATUS,
        SC4_PROG_CODE, SC4_CRT_BY, SC4_CRT_DATE, SC4_MOD_TIMES, SC4_MOD_BY, SC4_MOD_DATE, SC4_PST, SC4_PST_BY, SC4_PST_DATE, SC4_CHAR1, SC4_CHAR2,
        SC4_CHAR3, SC4_CHAR4, SC4_CHAR5, SC4_CHAR6, SC4_QTY1, SC4_QTY2, SC4_FR_SC, SC4_FR_SC_PCT, SC4_CUST, SC4_MACHINE,

        SOD_PART_QTY,
        SOD_SC_QTY,SC5_DESC,OEMDO_SFS_NBR,OEMDO_SFS_VERSION,A.GEND_NAME AS MB_DESC ,B.GEND_NAME AS INTERFACE_DESC,SOD_SFS_NBR,SOD_SFS_VERSION,
        SFS_S_LOGO,SFS_MN_LOGO,SFSD1_MN_LANG,wo_print_times,
        wo_try_nbr,try_task_no,try_content,try_aim

 FROM
        WO_MSTR JOIN PT_MSTR  WO_PT_MSTR ON WO_PART = WO_PT_MSTR.PT_PART
           LEFT JOIN OEM_MSTR ON WO_ECA_NBR = OEM_NBR AND WO_ECA_VER = OEM_VERSION
           LEFT JOIN OEMDC_DET ON OEM_NBR = OEMDC_NBR AND OEM_VERSION = OEMDC_VERSION
           LEFT JOIN OEMDO_DET ON OEM_NBR = OEMDO_NBR AND OEM_VERSION = OEMDO_VERSION
           LEFT JOIN PT_MSTR  OEMDC_PT_MSTR ON TRIM(OEMDC_EN_COMP) = TRIM(OEMDC_PT_MSTR.PT_PART)
           LEFT JOIN PT_MSTR  SOFT_PT_MSTR ON TRIM(WO_SOFT) = SOFT_PT_MSTR.PT_PART
           LEFT JOIN GEND_DET A ON OEM_MB_PROJECT = A.GEND_OPTION AND A.GEND_GEN =‘SBGD_SCHEME‘
           LEFT JOIN GEND_DET B ON OEM_INTER_REQ = B.GEND_OPTION AND B.GEND_GEN =‘INTERFACE_REQ‘

           LEFT JOIN SOD_DET ON SOD_NBR = WO_SO_NBR AND SOD_LINE = WO_SO_LINE
           LEFT JOIN SO_MSTR ON SO_NBR  = SOD_NBR
           LEFT JOIN  SFS_MSTR ON SFS_NBR = SOD_SFS_NBR AND SFS_VERSION = SOD_SFS_VERSION
           LEFT JOIN SFSD1_DET ON SFSD1_NBR = SFS_NBR AND SFSD1_VERSION = SFS_VERSION AND SFSD1_DEF_LANG = 1
           LEFT JOIN SC5_MSTR ON SC5_CODE  = SOD_SC5 AND SC5_CURR = SO_CURR  AND SOD_REQ_DATE BETWEEN  SC5_START AND SC5_EXPIRE   -- SC5_EXPIRE > TRUNC(SYSDATE, ‘DD‘)
           LEFT JOIN SC4_MSTR ON SC4_CODE  = SOD_SC4_CODE AND SC4_CURR = SO_CURR  AND SOD_REQ_DATE BETWEEN SC4_START AND SC4_EXPIRE
           left join try_mstr on wo_try_nbr=try_nbr
    WHERE (WO_NBR = ‘GWH17040102‘ ) AND
         (WO_LOT = ‘ ‘) AND
          (OEMDC_NAME  IN (SELECT GEND_OPTION
                                          FROM GEND_DET
                                          WHERE GEND_GEN =‘MT_COMP‘
                                               AND (GEND_PROPERTY2 =‘Y‘ OR GEND_PROPERTY2 =‘Y‘))
                         OR ISEQUAL(OEMDC_NAME , ‘‘) = 1 )

测试结果,成功!

总结:

1、*在复杂的SQL中还是需要慎重使用,特别是本来不需要那么多列数据,结果带出了很多多余的数据,造成浪费,同时,后来者若不熟悉业务,不加研读该存储过程,实际上很难知道,哪些信息是真正需要的,哪些是不需要的,久而久之,会加重企业后期的维护成本;

2、在调试SQL的过程中可以通过注释来排查异常。

3、该SQL仍待优化,若哪位仁兄有更好的见解,还望指导迷津。

时间: 2024-11-07 16:44:27

ORA-03113 SQL中select语句全表扫描带来的异常的相关文章

Oracle SQL优化必要的全表扫描思路分析

大多数情况下,我们需要避免SQL在查询时进行全表扫描(FTS),但是对于必须需要进行全表扫描的情况,也可以进行一些优化处理. 即使全表扫描是检索所需数据的唯一可行方法,仍然有多种方法来提升查询性能.优化扫描的技术包括: 1.  通过让表变小来减少扫描所需的逻辑块读取的数量 2.  通过提高数据库IO的效率降低扫描所需要的物理块读取的数量 3.  通过缓存或抽样降低扫描开销 4.  通过使用并行查询选项为扫描分配更多的资源 5.  执行快速全索引扫描来替代全表扫描 6.  对表进行分区,只读取所选

sql中select语句详解及用途

SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ] * | expression [ AS output_name ] [, ...] [ FROM from_item [, ...] ] [ WHERE condition ] [ GROUP BY expression [, ...] ] [ HAVING condition [, ...] ] [ { UNION | INTERSECT | EXCEPT } [ ALL ] sel

【Oracle】SQL 中Select语句完整的执行顺序

SQL Select语句完整的执行顺序: 1.from子句组装来自不同数据源的数据: 2.where子句基于指定的条件对记录行进行筛选: 3.group by子句将数据划分为多个分组: 4.使用聚集函数进行计算: 5.使用having子句筛选分组: 6.计算所有的表达式: 7.select 的字段: 8.使用order by对结果集进行排序. SQL语言不同于其他编程语言的最明显特征是处理代码的顺序.在大多数据库语言中,代码按编码顺序被处理.但在SQL语句中,第一个被处理的子句式FROM,而不是

sql中select语句的逻辑执行顺序

下面是SELECT语句的逻辑执行顺序: FROMONJOINWHEREGROUP BYWITH CUBE or WITH ROLLUPHAVINGSELECTDISTINCTORDER BYTOP MICROSOFT指出,SELECT语句的实际物理执行顺序可能会由于查询处理器的不同而与这个顺序有所出入. GROUP BY和HAVING 不能使用别名,就是因为他们先于select执行.

SQL 中 SELECT 语句的执行顺序

好像自已在书写 SQL 语句时由于不清楚各个关键字的执行顺序, 往往组织的 SQL 语句缺少很好的逻辑, 凭感觉 "拼凑" ( 不好意思, 如果您的 SQL 语句也经常 "拼凑", 那您是不是得好好反省一下呢?, 呵呵). 确实是爽了自己, 可苦了机器, 服务器还需要在我们的杂乱无章的 SQL 语句中寻找它下一句需要执行的关键字在哪里. 效率嘛, 由于我们的感觉神经对秒以下的变化实在不敏感, 暂且就认为自已写的 SQL 顺序无关紧要, "反正没什么变化!&

容易被忽略的事----sql语句中select语句的执行顺序

关于Sql中Select语句的执行顺序,一直很少注意这个问题,对于关键字的使用也很随意,至于效率问题,因为表中的数据量都不是很大,所以也不是很在意. 今天在一次面试的时候自己见到了,感觉没一点的印象,所以也就没有答上来,现在整理一下吧,希望提醒自己,也能够帮到其他的朋友.如下: (8) SELECT (9)DISTINCT (11) <TOP_specification> <select_list> (1) FROM <left_table> (3) <join_

SQL SERVER中关于OR会导致索引扫描或全表扫描的浅析

原文:SQL SERVER中关于OR会导致索引扫描或全表扫描的浅析 在SQL SERVER的查询语句中使用OR是否会导致不走索引查找(Index Seek)或索引失效(堆表走全表扫描 (Table Scan).聚集索引表走聚集索引扫描(Clustered Index Seek))呢?是否所有情况都是如此?又该如何优化呢? 下面我们通过一些简单的例子来分析理解这些现象.下面的实验环境为SQL SERVER 2008,如果在不同版本有所区别,欢迎指正. 堆表单索引 首先我们构建我们测试需要实验环境,

SQL SERVER SELECT语句中加锁选项的详细说明 [转]

SQL Server提供了强大而完备的锁机制来帮助实现数据库系统的并发性和高性能.用户既能使用SQL Server的缺省设置也可以在select 语句中使用“加锁选项”来实现预期的效果. 本文介绍了SELECT语句中的各项“加锁选项”以及相应的功能说明. 功能说明: NOLOCK(不加锁) 此选项被选中时,SQL Server 在读取或修改数据时不加任何锁. 在这种情况下,用户有可能读取到未完成事务(Uncommited Transaction)或回滚(Roll Back)中的数据, 即所谓的“

SQL 数据优化索引建suo避免全表扫描

首先什么是全表扫描和索引扫描?全表扫描所有数据过一遍才能显示数据结果,索引扫描就是索引,只需要扫描一部分数据就可以得到结果.如果数据没建立索引. 无索引的情况下搜索数据的速度和占用内存就会比用索引的检索慢和高.下面是一个例子 1:无索引的情况 Product表,里面没有任何索引,如下图: 从上图中,我悲剧的看到了,物理读是9次,也就说明走了9次硬盘,你也可以想到,走硬盘的目的是为了拿数据,逻辑读有1636次,要注意的是这里 的”次“是“页”的意思,也就是在内存中走了1636个数据页,我用dbcc