Thursday, 6 March 2014

Oracle Install Base Query

/* Formatted on 3/6/2014 2:10:52 PM (QP5 v5.256.13226.35510) */
--INSTALLED BASE ROOT ITEM QUERY
--ENTER A PARTY NUMBER AND GET RESULTS

SELECT SYSDATE,
       cipv.instance_number AS "Instance Number",
       (SELECT hp.party_name
          FROM ar.hz_parties hp
         WHERE hp.party_id = cipv.party_id)
          AS "Owner Name",
       (SELECT hp.party_number
          FROM ar.hz_parties hp
         WHERE hp.party_id = cipv.party_id)
          AS "Owner Party",
       (SELECT hca.account_number
          FROM ar.hz_cust_accounts hca
         WHERE hca.cust_account_id = cipv.party_account_id)
          AS "Owner Account",
       cidv.concatenated_segments AS "Item",
       cidv.description AS "Item Description",
       cidv.quantity AS "Qty",
       cidv.unit_of_measure AS "UOM",
       cidv.status_name AS "ISB Status",
       cidv.external_reference AS "External Reference (Tag)",
       cidv.instance_description AS "Instance Name",
       cidv.instance_usage_code AS "ISB Usage Code",
       cidv.serial_number AS "Serial",
       cidv.lot_number AS "Lot",
       cidv.instance_type_code AS "ISB Instance Type",
       cidv.install_date "Install Date",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'ALTITUDE')
          AS "Altitude (Value and Unit)",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'BACNET')
          AS "BACNET (Device, Protocol)",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'CELLULAR')
          AS "Celluar (Type, Carrier, #)",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'CONFIG_CODE')
          AS "Configuration Code",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'CONFIG_COMMENT')
          AS "Configuration Comment",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'ELEVATION')
          AS "Elevation (Value and Unit)",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'ETHERNET')
          AS "Ethernet (Type, IP Address)",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'HIGHWAY_LOCATION')
          AS "Highway Location",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'ICAO_CODE')
          AS "ICAO Code",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'LATITUDE')
          AS "Latitude (DDD MM.MMM)",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'LOCAL_PARTNER')
          AS "Local Partner",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'LONGITUDE')
          AS "Longitude (DDD MM.MMM)",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'MAGNETIC_DECLINATION')
          AS "Magnetic Declination (Deg)",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'MAINS_TYPE')
          AS "Mains Type",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'MAST_HEIGHT')
          AS "Mast Height (m)",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'MODBUS')
          AS "Modbus (Device, Protocol)",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'PHONE_PSTN')
          AS "Phone/PSTN (Type, Carrier, #)",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'RADIO')
          AS "Radio (Type, Freq)",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'ROAD_NUMBER')
          AS "Road Number",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'SATELLITE')
          AS "Satellite (Type, Provider)",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'SENSOR_PROTOCOL')
          AS "Sensor Protocol (Type)",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'SERVICE_PROVIDER')
          AS "Service Provider",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'SITE_NAME')
          AS "Site Name",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'STATION_ID')
          AS "Station ID",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'XXVAI_ITEM_REV')
          AS "Vaisala Item Revision",
       (SELECT cieav.attribute_value
          FROM APPS.CSI_INST_EXTEND_ATTRIB_V cieav
         WHERE     cieav.instance_id = cipv.instance_id
               AND cieav.attribute_code = 'WMO_CODE')
          AS "WMO Code",
       DECODE (
          cidv.location_type_code,
          'HZ_PARTY_SITES',    (SELECT DISTINCT hpsv.address1
                                  FROM apps.hz_party_sites_v hpsv
                                 WHERE hpsv.party_site_id = cidv.location_id)
                            || '--'
                            || (SELECT DISTINCT hpsv.city
                                  FROM apps.hz_party_sites_v hpsv
                                 WHERE hpsv.party_site_id = cidv.location_id)
                            || '--'
                            || (SELECT DISTINCT hpsv.state
                                  FROM apps.hz_party_sites_v hpsv
                                 WHERE hpsv.party_site_id = cidv.location_id),
          'INVENTORY',    'VAISALA -- '
                       || (SELECT ionv.organization_name
                             FROM APPS.INV_ORGANIZATION_NAME_V ionv
                            WHERE ionv.organization_id =
                                     cidv.inv_organization_id)
                       || '--'
                       || cidv.inv_subinventory_name,
          'UNKNOWN')
          "Current_Location",
       DECODE (
          cidv.install_location_type_code,
          'HZ_PARTY_SITES',    (SELECT DISTINCT hpsv.address1
                                  FROM apps.hz_party_sites_v hpsv
                                 WHERE hpsv.party_site_id =
                                          cidv.install_location_id)
                            || '--'
                            || (SELECT DISTINCT hpsv.city
                                  FROM apps.hz_party_sites_v hpsv
                                 WHERE hpsv.party_site_id =
                                          cidv.install_location_id)
                            || '--'
                            || (SELECT DISTINCT hpsv.state
                                  FROM apps.hz_party_sites_v hpsv
                                 WHERE hpsv.party_site_id =
                                          cidv.install_location_id),
          NULL, 'NULL',
          'UNKNOWN')
          "Install_Location",
       (SELECT DISTINCT
               hpsv.address1 || '--' || hpsv.city || '--' || hpsv.state
          FROM apps.hz_party_sites_v hpsv
         WHERE hpsv.party_site_id =
                  (SELECT hcasa.party_site_id
                     FROM ar.hz_cust_acct_sites_all hcasa
                    WHERE hcasa.cust_acct_site_id =
                             (SELECT hcsua.cust_acct_site_id
                                FROM ar.hz_cust_site_uses_all hcsua
                               WHERE cipv.bill_to_address = hcsua.site_use_id)))
          AS "Bill To",
       (SELECT DISTINCT
               hpsv.address1 || '--' || hpsv.city || '--' || hpsv.state
          FROM apps.hz_party_sites_v hpsv
         WHERE hpsv.party_site_id =
                  (SELECT hcasa.party_site_id
                     FROM ar.hz_cust_acct_sites_all hcasa
                    WHERE hcasa.cust_acct_site_id =
                             (SELECT hcsua.cust_acct_site_id
                                FROM ar.hz_cust_site_uses_all hcsua
                               WHERE cipv.ship_to_address = hcsua.site_use_id)))
          AS "Ship To",
       DECODE ( (SELECT COUNT (*)
                   FROM CSI.CSI_II_RELATIONSHIPS CIR
                  WHERE CIR.OBJECT_ID = cipv.INSTANCE_ID),
               0, 'No BOM Components',
               'BOM Components Exist')
          AS "BOM?"
  FROM APPS.CSI_INSTANCE_PARTY_V cipv, apps.csi_instance_details_v cidv
 WHERE     1 = 1
       AND cidv.instance_id = cipv.instance_id
       AND cipv.instance_usage_code <> 'IN_RELATIONSHIP' --ROOT INSTANCES ONLY
       AND ( (cipv.party_account_id =
                 (SELECT hca.cust_account_id
                    FROM ar.hz_cust_accounts hca
                   WHERE hca.account_number IN TO_CHAR (&AccountNumber))));

Monday, 10 February 2014

Query to Find Junk Characters in table

SELECT   okh.contract_number, okl.line_number, okl.attribute6, okl.sts_code
    FROM okc_k_headers_all_b okh, okc_k_lines_b okl
   WHERE okh.ID = okl.dnz_chr_id AND okl.attribute6 IS NOT NULL
  HAVING REGEXP_COUNT(okl.attribute6, '[''~!@#$%^&*(),+=}{;:><?]') >= 1

GROUP BY okh.contract_number, okl.line_number, okl.attribute6, okl.sts_code



once it is identified remove it by updating table using below query  

REGEXP_REPLACE(okl.attribute6,'[''~!@#$%^&*(),+=}{;:><?]',NULL)

Thursday, 23 January 2014

Sales Order Details

SELECT wdd.source_header_number order_number,
       mtrh.request_number move_order_number,
       wnd.global_attribute14 actual_delivery_date,
       mtrh.creation_date move_order_date, wdd.creation_date,
       wdd.source_header_type_name order_type, hp.party_name bill_to_customer,
       hps.party_site_number ship_to_loc_num,
       hps.party_site_name ship_to_loc_name, oel.ordered_item,
       msi.description, oel.order_quantity_uom,
       wdd.src_requested_quantity ordered_quantity, wdd.shipped_quantity,
       CASE when oel.SOURCE_DOCUMENT_ID is null then
             wdd.cancelled_quantity
             else 
       null
       end as cancelled_quantity
       , oel.unit_selling_price unit_selling_price,
       (oel.ordered_quantity * oel.unit_selling_price) extended_price,
       oeh.ordered_date, ood.organization_code,
       CASE
          WHEN (wdd.src_requested_quantity - wdd.shipped_quantity
               ) = 0
             THEN 'CLOSED'
          WHEN wdd.shipped_quantity IS NULL
             THEN 'AWAITING SHIPPING'
          WHEN wdd.shipped_quantity > 0
          AND wdd.shipped_quantity < wdd.src_requested_quantity
             THEN 'PARTIALLY SHIPED'
       END AS order_status,
       rct.trx_number, rct.trx_date, rct.status_trx,
       DECODE (wdd.released_status,
               'D', 'Cancelled',
               'C', 'Shipped',
               'R', 'Ready to Release',
               'N', 'Not Ready to Release',
               'S', 'Released to Warehouse',
               'Y', 'Staged/Pick Confirmed',
               'X', 'Not Applicable'
              ) released_status_name,
       ROUND (DECODE ((oel.ordered_quantity - wdd.shipped_quantity),
                      0, NULL,
                      TRUNC (SYSDATE) - mtrh.creation_date
                     ),
              0
             ) pending_since,
       wdd.released_status, NULL, NULL
  FROM wsh_delivery_details wdd,
       wsh_delivery_assignments wda,
       wsh_new_deliveries wnd,
       oe_order_headers_all oeh,
       oe_order_lines_all oel,
       hz_parties hp,
       hz_cust_accounts hca,
       hz_party_sites hps,
       mtl_system_items_b msi,
       ra_customer_trx_lines_all rctl,
       ra_customer_trx_all rct,
       org_organization_definitions ood,
       mtl_txn_request_lines mtrl,
       mtl_txn_request_headers mtrh
WHERE wda.delivery_detail_id = wdd.delivery_detail_id
   AND wda.delivery_id = wnd.delivery_id(+)
   AND NVL (wdd.line_direction, 'O') IN ('O', 'IO')
   AND NVL (wda.TYPE, 'S') IN ('S', 'C')
   AND wdd.source_header_id = oeh.header_id
   AND wdd.source_line_id = oel.line_id
   AND oeh.header_id = oel.header_id
   AND hp.party_id = hca.party_id
   AND oeh.sold_to_org_id = hca.cust_account_id
   AND hps.location_id(+) = oel.ship_to_org_id
   AND msi.inventory_item_id = oel.inventory_item_id
   AND msi.organization_id = oel.ship_from_org_id
   ------------following join to get those order whose invoices are not created--------
   AND rctl.interface_line_attribute6(+)=oel.line_id
   AND rct.customer_trx_id(+) = rctl.customer_trx_id
   --AND rctl.interface_line_attribute1 = TO_CHAR (oeh.order_number)
   AND wdd.move_order_line_id = mtrl.line_id
   AND oel.ship_from_org_id = ood.organization_id
   AND mtrh.header_id = mtrl.header_id
   AND wdd.move_order_line_id = mtrl.line_id
    --and wdd.source_header_number=112104873 --112909588 --112400057
    AND TO_DATE (oeh.ordered_date) BETWEEN NVL (:f_date, oeh.ordered_date)
                                      AND NVL (:t_date, oeh.ordered_date)
union
SELECT wdd.source_header_number order_number,
       mtrh.request_number move_order_number,
       wnd.global_attribute14 actual_delivery_date, mtrh.creation_date move_order_date,
       wdd.creation_date, wdd.source_header_type_name order_type,
       hp.party_name bill_to_customer, hps.party_site_number ship_to_loc_num,
       hps.party_site_name ship_to_loc_name, oel.ordered_item,
       msi.description, oel.order_quantity_uom,
       wdd.src_requested_quantity ordered_quantity, wdd.shipped_quantity,
       CASE when oel.SOURCE_DOCUMENT_ID is null then
             wdd.cancelled_quantity
             else 
       null
       end as cancelled_quantity
       , oel.unit_selling_price unit_selling_price,
       (oel.ordered_quantity * oel.unit_selling_price) extended_price,
       oeh.ordered_date, ood.organization_code,
       CASE
          WHEN (wdd.src_requested_quantity - wdd.shipped_quantity) =
                                                            0 AND wdd.released_status<>'D'
             THEN 'CLOSED'
          WHEN wdd.shipped_quantity IS NULL
             THEN 'AWAITING SHIPPING'
          WHEN wdd.shipped_quantity > 0
          AND wdd.shipped_quantity < wdd.src_requested_quantity
             THEN 'PARTIALLY SHIPPED'
             WHEN (wdd.src_requested_quantity - wdd.shipped_quantity) =
                                                            0 AND wdd.released_status='D'
             THEN 'CANCELLED'
       END AS order_status,
       NULL, NULL, NULL, NULL,
       ROUND (DECODE ((oel.ordered_quantity - wdd.shipped_quantity),
                      0, NULL,
                      TRUNC (SYSDATE) - wdd.creation_date
                     ),
              0
             ) pending_since,
       wdd.released_status,null,null/*, oer.reason_code, oer.comments*/
  FROM wsh_delivery_details wdd,
       wsh_delivery_assignments wda,
       wsh_new_deliveries wnd,
       oe_order_headers_all oeh,
       oe_order_lines_all oel,
       hz_parties hp,
       hz_cust_accounts hca,
        hz_party_sites hps,
       mtl_system_items_b msi,
       org_organization_definitions ood,
       mtl_txn_request_lines mtrl,
       mtl_txn_request_headers mtrh   
WHERE wda.delivery_detail_id = wdd.delivery_detail_id
   AND wda.delivery_id = wnd.delivery_id(+)
  -- AND NVL (wdd.line_direction, 'O') IN ('O', 'IO')
   AND wdd.source_header_id = oeh.header_id
   AND wdd.source_line_id = oel.line_id
   AND oeh.header_id = oel.header_id
   AND hp.party_id = hca.party_id
   AND oeh.sold_to_org_id = hca.cust_account_id
   AND hps.location_id(+) = oel.ship_to_org_id
   AND msi.inventory_item_id = oel.inventory_item_id
   AND msi.organization_id = oel.ship_from_org_id
   AND oel.ship_from_org_id = ood.organization_id
    AND mtrh.header_id = mtrl.header_id
    AND wdd.move_order_line_id =NVL( mtrl.line_id,wdd.move_order_line_id)
  AND wdd.released_status IN ( 'B','S','R')
   --and wdd.source_header_number=112104873 --112909588
   AND TO_DATE (oeh.ordered_date) BETWEEN NVL (:f_date, oeh.ordered_date)
                                      AND NVL (:t_date, oeh.ordered_date)
   Union
   SELECT wdd.source_header_number order_number,
       NULL move_order_number,
       wnd.global_attribute14 actual_delivery_date,
       NULL move_order_date, wdd.creation_date,
       wdd.source_header_type_name order_type, hp.party_name bill_to_customer,
       hps.party_site_number ship_to_loc_num,
       hps.party_site_name ship_to_loc_name, oel.ordered_item,
       msi.description, oel.order_quantity_uom,
       wdd.src_requested_quantity ordered_quantity, wdd.shipped_quantity,
       CASE when oel.SOURCE_DOCUMENT_ID is null then
             wdd.cancelled_quantity
             else 
       null
       end as cancelled_quantity
       , oel.unit_selling_price unit_selling_price,
       (oel.ordered_quantity * oel.unit_selling_price) extended_price,
       oeh.ordered_date, ood.organization_code,
       CASE
          WHEN (wdd.src_requested_quantity - wdd.shipped_quantity
               ) = 0
          AND wdd.released_status <> 'D'
             THEN 'CLOSED'
          WHEN wdd.shipped_quantity IS NULL
             THEN 'AWAITING SHIPPING'
          WHEN wdd.shipped_quantity > 0
          AND wdd.shipped_quantity < wdd.src_requested_quantity
             THEN 'PARTIALLY SHIPPED'
          WHEN (wdd.src_requested_quantity - wdd.shipped_quantity) = 0
          AND wdd.released_status = 'D'
             THEN 'CANCELLED'
       END AS order_status,
       NULL, NULL, NULL, NULL,
       ROUND (DECODE ((oel.ordered_quantity - wdd.shipped_quantity),
                      0, NULL,
                      TRUNC (SYSDATE) - wdd.creation_date
                     ),
              0
             ) pending_since,
       wdd.released_status, NULL,NULL --oer.reason_code, oer.comments
  FROM wsh_delivery_details wdd,
       wsh_delivery_assignments wda,
       wsh_new_deliveries wnd,
       oe_order_headers_all oeh,
       oe_order_lines_all oel,
       hz_parties hp,
       hz_cust_accounts hca,
       hz_party_sites hps,
       mtl_system_items_b msi,
       org_organization_definitions ood
WHERE wda.delivery_detail_id = wdd.delivery_detail_id
   AND wda.delivery_id = wnd.delivery_id(+)
   -- AND NVL (wdd.line_direction, 'O') IN ('O', 'IO')
   AND wdd.source_header_id = oeh.header_id
   AND wdd.source_line_id = oel.line_id
   AND oeh.header_id = oel.header_id
   AND hp.party_id = hca.party_id
   AND oeh.sold_to_org_id = hca.cust_account_id
   AND hps.location_id(+) = oel.ship_to_org_id
   AND msi.inventory_item_id = oel.inventory_item_id
   AND msi.organization_id = oel.ship_from_org_id
   AND oel.ship_from_org_id = ood.organization_id
   AND wdd.released_status IN   ( 'B','S','R')
   AND wdd.move_order_line_id IS NULL
   --AND wdd.source_header_number = 112104873
   AND TO_DATE (oeh.ordered_date) BETWEEN NVL (:f_date, oeh.ordered_date)
                                      AND NVL (:t_date, oeh.ordered_date) 
   UNION
SELECT wdd.source_header_number order_number,
       mtrh.request_number move_order_number,
       wnd.global_attribute14 actual_delivery_date,
       mtrh.creation_date move_order_date, wdd.creation_date,
       wdd.source_header_type_name order_type, hp.party_name bill_to_customer,
       hps.party_site_number ship_to_loc_num,
       hps.party_site_name ship_to_loc_name, oel.ordered_item,
       msi.description, oel.order_quantity_uom,
       wdd.src_requested_quantity ordered_quantity, wdd.shipped_quantity,
       CASE when oel.SOURCE_DOCUMENT_ID is null then
             wdd.cancelled_quantity
             else 
       null
       end as cancelled_quantity
       , oel.unit_selling_price unit_selling_price,
       (oel.ordered_quantity * oel.unit_selling_price) extended_price,
       oeh.ordered_date, ood.organization_code,
       CASE
          WHEN (wdd.src_requested_quantity - wdd.shipped_quantity
               ) = 0
          AND wdd.released_status <> 'D'
             THEN 'CLOSED'
          WHEN wdd.shipped_quantity IS NULL
             THEN 'AWAITING SHIPPING'
          WHEN wdd.shipped_quantity > 0
          AND wdd.shipped_quantity < wdd.src_requested_quantity
             THEN 'PARTIALLY SHIPPED'
          WHEN (wdd.src_requested_quantity - wdd.shipped_quantity) = 0
          AND wdd.released_status = 'D'
             THEN 'CANCELLED'
       END AS order_status,
       NULL, NULL, NULL, NULL,
       ROUND (DECODE ((oel.ordered_quantity - wdd.shipped_quantity),
                      0, NULL,
                      TRUNC (SYSDATE) - wdd.creation_date
                     ),
              0
             ) pending_since,
       wdd.released_status, oer.reason_code, oer.comments
  FROM wsh_delivery_details wdd,
       wsh_delivery_assignments wda,
       wsh_new_deliveries wnd,
       oe_order_headers_all oeh,
       oe_order_lines_all oel,
       hz_parties hp,
       hz_cust_accounts hca,
       hz_party_sites hps,
       mtl_system_items_b msi,
       org_organization_definitions ood,
       mtl_txn_request_lines mtrl,
       mtl_txn_request_headers mtrh  ,oe_order_lines_history lh ,                                      
                                               oe_reasons oer
WHERE wda.delivery_detail_id = wdd.delivery_detail_id
   AND wda.delivery_id = wnd.delivery_id(+)
   -- AND NVL (wdd.line_direction, 'O') IN ('O', 'IO')
   AND wdd.source_header_id = oeh.header_id
   AND wdd.source_line_id = oel.line_id
   AND oeh.header_id = oel.header_id
   AND hp.party_id = hca.party_id
   AND oeh.sold_to_org_id = hca.cust_account_id
   AND hps.location_id(+) = oel.ship_to_org_id
   AND msi.inventory_item_id = oel.inventory_item_id
   AND msi.organization_id = oel.ship_from_org_id
   AND oel.ship_from_org_id = ood.organization_id
   AND mtrh.header_id(+) = mtrl.header_id
   AND mtrl.line_id(+) = wdd.move_order_line_id
   AND oel.line_id = lh.line_id
    AND lh.reason_id = oer.reason_id
   AND wdd.released_status IN  ('D')
   --AND wdd.source_header_number = 112104873                         --112909588
   AND TO_DATE (oeh.ordered_date) BETWEEN NVL (:f_date, oeh.ordered_date)
                                      AND NVL (:t_date, oeh.ordered_date)
    UNION       
SELECT TO_CHAR (oeh.order_number) order_number, NULL move_order_number,
       NULL actual_delivery_date, NULL move_order_date, NULL, NULL order_type,
       hp.party_name bill_to_customer, hps.party_site_number ship_to_loc_num,
       hps.party_site_name ship_to_loc_name, oel.ordered_item,
       msi.description, oel.order_quantity_uom,
       oel.ordered_quantity ordered_quantity, NULL, NULL,
       oel.unit_selling_price unit_selling_price,
       (oel.ordered_quantity * oel.unit_selling_price) extended_price,
       oeh.ordered_date, ood.organization_code,
       oel.flow_status_code order_status, NULL, NULL, NULL, NULL, NULL, NULL,
       NULL, NULL
  FROM oe_order_headers_all oeh,
       oe_order_lines_all oel,
       hz_parties hp,
       hz_cust_accounts hca,
       hz_party_sites hps,
       mtl_system_items_b msi,
       org_organization_definitions ood
WHERE oeh.header_id = oel.header_id(+)--this join for rows whose line level data is not available
   AND hp.party_id = hca.party_id
   AND oeh.sold_to_org_id = hca.cust_account_id
   AND hps.location_id(+) = oel.ship_to_org_id
   AND msi.inventory_item_id(+)=oel.inventory_item_id--this join for rows whose line level data is not available
   AND msi.organization_id(+) = oel.ship_from_org_id--this join for rows whose line level data is not available
   AND oel.ship_from_org_id = ood.organization_id(+)--this join for rows whose line level data is not available
   --  and wdd.RELEASED_STATUS in('D','B')
     --and oeh.ORDER_NUMBER =112105131 --112909588--112104621
    AND TO_DATE (oeh.ordered_date) BETWEEN NVL (:f_date, oeh.ordered_date)
                                     AND NVL (:t_date, oeh.ordered_date)
      AND oeh.flow_status_code = 'ENTERED' 
      Union
---------this union for order Booked but his transactions are not done in delivery table and for cancelled order
      SELECT to_char(oeh.ORDER_NUMBER)  order_number,
       mtrh.request_number move_order_number,
       wnd.global_attribute14 actual_delivery_date, mtrh.creation_date move_order_date,
       wdd.creation_date, wdd.source_header_type_name order_type,
       hp.party_name bill_to_customer, hps.party_site_number ship_to_loc_num,
       hps.party_site_name ship_to_loc_name, oel.ordered_item,
       msi.description, oel.order_quantity_uom,
       wdd.src_requested_quantity ordered_quantity, wdd.shipped_quantity,
       CASE when oel.SOURCE_DOCUMENT_ID is null then
             wdd.cancelled_quantity
             else 
       null
       end as cancelled_quantity,
        oel.unit_selling_price unit_selling_price,
       (oel.ordered_quantity * oel.unit_selling_price) extended_price,
       oeh.ordered_date, ood.organization_code,
       CASE
          WHEN (wdd.src_requested_quantity - wdd.shipped_quantity) =
                                                            0 AND wdd.released_status<>'D'
             THEN 'CLOSED'
          WHEN wdd.shipped_quantity IS NULL
             THEN 'AWAITING SHIPPING'
          WHEN wdd.shipped_quantity > 0
          AND wdd.shipped_quantity < wdd.src_requested_quantity
             THEN 'PARTIALLY SHIPPED'
             WHEN (wdd.src_requested_quantity - wdd.shipped_quantity) =
                                                            0 AND wdd.released_status='D'
             THEN 'CANCELLED'
       END AS order_status,
       NULL, NULL, NULL, NULL,
       ROUND (DECODE ((oel.ordered_quantity - wdd.shipped_quantity),
                      0, NULL,
                      TRUNC (SYSDATE) - wdd.creation_date
                     ),
              0
             ) pending_since,
       wdd.released_status,null,null/*, oer.reason_code, oer.comments*/
  FROM oe_order_headers_all oeh,
       oe_order_lines_all oel,
       wsh_delivery_details wdd,
       wsh_delivery_assignments wda,
       wsh_new_deliveries wnd,
       hz_party_sites hps,
       hz_cust_accounts hca,
       hz_parties hp,
       mtl_system_items_b msi,
       org_organization_definitions ood,
       mtl_txn_request_lines mtrl,
       mtl_txn_request_headers mtrh
WHERE oeh.header_id = oel.header_id
--AND wdd.source_header_id = oeh.header_id
   AND wdd.source_line_id(+) = oel.line_id
   AND wda.delivery_id = wnd.delivery_id(+)
   AND wda.delivery_detail_id(+) = wdd.delivery_detail_id
   AND hps.location_id(+) = oel.ship_to_org_id
   AND oeh.sold_to_org_id = hca.cust_account_id
   AND hp.party_id = hca.party_id
   AND msi.inventory_item_id = oel.inventory_item_id
   AND msi.organization_id = oel.ship_from_org_id
   AND oel.ship_from_org_id = ood.organization_id
   AND wdd.move_order_line_id = mtrl.line_id(+)
   AND mtrh.header_id(+) = mtrl.header_id
   AND NVL (wdd.released_status, 'N') IN ('N')
   --AND oeh.order_number = 112909462
  AND oeh.flow_status_code in ( 'BOOKED','CANCELLED')
   AND TO_DATE (oeh.ordered_date) BETWEEN NVL (:f_date, oeh.ordered_date)
                                      AND NVL (:t_date, oeh.ordered_date)

Query to find submitted Concurrent requests

  Query to find Concurrent Requests SELECT      user_concurrent_program_name,      responsibility_name,      request_date,      argument_tex...