• viralbpandya (5/13/2016)


    is it possible to sort data other way?

    Death by function!

    Functions are overused in this query. The two most significant consequences are obfuscation, which is sometimes good but not in this case, and performance.

    Here's the query reformatted a little and with table aliases in place:

    select

    ol.ORDER_NO,

    ol.STATE,

    WES.CUSTOMER_ORDER_API.get_ORDER_ID(ORDER_NO) TYPE,

    ol.CUSTOMER_NO,

    WES.CUSTOMER_INFO_API.Get_Name(CUSTOMER_No),

    ol.CATALOG_NO,

    ol.CATALOG_DESC,

    ol.REVISED_QTY_DUE,

    TO_CHAR(ol.PROMISED_DELIVERY_DATE,'IW')UGE,

    DECODE(WES.CUSTOMER_ORDER_API.get_ORDER_ID(ORDER_NO),'MNO',1,'KNO',1,0) NON_W,

    DECODE(WES.CUSTOMER_ORDER_API.get_ORDER_ID(ORDER_NO),'RNO',1,0) RES,

    ol.WANTED_DELIVERY_DATE,

    ol.PROMISED_DELIVERY_DATE,

    ol.PLANNED_DELIVERY_DATE,

    ol.DATE_ENTERED,

    LINE_NO,

    WES.CUSTOMER_ORDER_API.get_STATE(ORDER_NO) STATE,

    DECODE(WES.sales_part_API.Get_catalog_group(contract,part_no), '10',1,0) SALES_GROUP

    From WES.CUSTOMER_ORDER_LINE ol

    Where

    (

    UPPER(ol.STATE) like UPPER('Frigivet')

    or

    UPPER(ol.STATE) like UPPER('Released')

    or

    UPPER(ol.STATE) like UPPER('Reserveret')

    )

    and ol.CATALOG_NO not in ('1','4','8','248','251','252','VF','XXXXX','3000','%SERVICE%','DI%','249')

    and ol.CATALOG_NO not like 'DI%'

    and ol.CATALOG_NO not like '%SERVICE%'

    and ol.CATALOG_NO not like 'FRAGT%'

    and ol.CATALOG_NO not like 'CONT%'

    and ol.CATALOG_DESC not like '%FREIGHT%'

    and ol.CATALOG_DESC not like '%FRACHT%'

    and UPPER(ol.CATALOG_DESC) not like UPPER('%Ordretilgang%')

    and WES.CUSTOMER_ORDER_API.get_STATE(ORDER_NO) not in ('Planlagt','Spærret')

    order by

    to_char(ol.PLANNED_DELIVERY_DATE,'YYYY-IW') [ASC],

    DECODE(WES.CUSTOMER_ORDER_API.get_ORDER_ID(ORDER_NO),'MNO',1,'KNO',1,0) [ASC]

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden