orcal substr instr使用

SELECT   substr(t3.name,instr(t3.name,' ',1,1),instr(t3.name,' ',2,2)-2)  project,substr(t3.name,4,6) model, t1.VALUE po, NVL (t4.asusso, t5.asusso) so,
       NVL (t4.asussoline, t5.asussoline) soline, t5.part_no client_no,
       t2.NAME bydpn, stock.shoporder,
       NVL (t4.quantity_new, t5.quantity) quantity,
       NVL (t6.region, t7.region) region,
       NVL (t6.destination, t7.destination) destination,
       NVL (t6.deliverydate, t7.deliverydate) deliverydate, t.begin_date,
       t.end_date, t9.actual_begin_date,t9.put_in_qty, t10.actual_qty,
       stock.stocknum, t.order_end_date,
       TO_CHAR (t9.actual_begin_date, 'IW') week,
       CASE
          WHEN stock.stocknum = t9.put_in_qty
          AND t.order_end_date IS NOT NULL
             THEN t.order_end_date - t9.actual_begin_date
          ELSE NULL
       END daynum,t11.USAGETYPE
  FROM (SELECT   shoporder, SUM (ct_sfc_num) stocknum
            FROM mes2_d_pro_stock@zk
           WHERE warehouse_id = ''
             AND client_id = ''
             AND pro_level = 1
             AND (state = 1 OR state = 2)
        GROUP BY shoporder) stock
       LEFT JOIN
       mes2_byd_shoporder t ON stock.shoporder = t.shoporder
       LEFT JOIN mes2_byd_custom_data t1
       ON t1.parent_id = t.ID AND t1.TYPE = 3 AND t1.NAME = 'PO'
       LEFT JOIN
       (SELECT   shoporder, COUNT (ID) actual_qty
            FROM mes2_byd_sfc
           WHERE shoporder IN (SELECT DISTINCT shoporder
                                          FROM mes2_d_pro_stock@zk
                                         WHERE warehouse_id = ''
                                           AND pro_level = 1)
             AND sfc_state = 'C'
        GROUP BY shoporder) t10 ON t10.shoporder = t.shoporder
       LEFT JOIN mes2_byd_product t2 ON t.product_id = t2.ID
       LEFT JOIN mes2_byd_project t3 ON t2.project_id = t3.ID
       LEFT JOIN mes2_edi_ztsd121 t4 ON t1.VALUE = t4.ponumber
       LEFT JOIN mes2_edi_ztsd119 t5 ON t1.VALUE = t5.ponumber
       LEFT JOIN mes2_edi_ztsd120 t6 ON t1.VALUE = t6.ponumber
       LEFT JOIN mes2_edi_ztsd118 t7 ON t1.VALUE = t7.ponumber
       LEFT JOIN MES2_EDI_ZTSD123 t11 ON T1.VALUE = t11.ponumber
 
       LEFT JOIN
       (SELECT   t8.shoporder, MIN (t8.actual_begin_date) actual_begin_date,
                 MAX (t8.actual_end_date) actual_end_date,
                 SUM (t8.put_in_qty) put_in_qty,
                 SUM (t8.actual_qty) actual_qty
            FROM mes2_byd_shoporder_scheduling t8
        GROUP BY t8.shoporder) t9 ON t9.shoporder = t.shoporder

猜你喜欢

转载自qq1988627.iteye.com/blog/2285179