Correct my Decode Function

Hi,
I created a table and inserted some records into the table.
I am trying to find the output using decode function using the below query.
select marks,decode(marks,(marks>70),'A',(marks>60 and marks<70),'B',(marks>50 and marks<60),'C') from stud_mrks
But I am getting error as
ERROR at line 1:
ORA-00907: missing right parenthesis
Can anyone please correct me.
Thanks

If you have to use DECODE -- for example teacher has asked to in that way in Homework ;) then this example may help you.
SQL> SELECT ename,sal,DECODE(sign(sal-1000),-1,'LOW',
  2                          DECODE(sign(sal-2000),-1,'MEDIUM','HIGH')) FROM emp;
ENAME                                      SAL DECODE
SMITH                                      800 LOW
ALLEN                                     1600 MEDIUM
WARD                                      1250 MEDIUM
JONES                                     2975 HIGH
MARTIN                                    1250 MEDIUM
BLAKE                                     2850 HIGH
CLARK                                     2450 HIGH
SCOTT                                     3000 HIGH
KING                                      5000 HIGH
TURNER                                    1500 MEDIUM
ADAMS                                     1100 MEDIUM
ENAME                                      SAL DECODE
JAMES                                      950 LOW
FORD                                      3000 HIGH
MILLER                                    1300 MEDIUM
999999                                     100 LOW
ABCDEFGHIJKLMNOPQRSTUVWXYZAAAAAA           100 LOW
MY#@ ' "ABC                                100 LOW
17 rows selected.
{code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Please help in correcting the Decode function

    DECODE(p_resp_key,'||'''AP'''||',LINT_LOGI_STG_ITEM_DETAILS_PKG.GET_AP_ITEM_CATEGORY_DTL(ol.inventory_item_id),ldmf_istore_order_pkg.get_wwdb_prod_description(ol.inventory_item_id)) AS description
    I am getting parsing errors during runtime.I believe that something is incorrect in Decode statement.I am calling this Decopde statement in the package.Please help.
    Regards
    M

    Thanks Sven for replying i am pasting the full function kindly tell me which will be the proper manner to correct teh decode statement.Please look for "--CO73977 iStore product description change start by manish" in the belwo defintion there i have used decode function.Kindly help.
    v_statement := 'SELECT /*+ FIRST_ROWS */ DISTINCT ooh.order_number AS "Order Number",
    NVL(bill_cas.attribute5,hp.party_name) AS "Customer Name",
    TO_CHAR(ooh.ordered_date,'||'''DD-MON-YYYY'''||') AS "Order Date",
    TO_CHAR(ooh.booked_date,'||'''DD-MON-YYYY'''||') AS "Booked Date",
    TO_CHAR(ol.request_date,'||'''DD-MON-YYYY'''||') AS "Requested Date",
    oel.meaning AS "Order Status",
    ooh.cust_po_number AS "PO Number",
    ooh.transactional_curr_code AS currency,
    terms.NAME AS "Payment Terms",
    freight.meaning AS "Freight Term",
    fob.meaning AS "FOB",
    ooh.sales_channel_code AS "Sales Channel",
    bill_to.LOCATION AS "Bill To Location",
    ship_to.LOCATION AS "Ship To Location",
    terr.segment1 AS "Sales Territory - Country",
    ott.NAME AS "Order Type",
    oe_totals_grp.get_order_total (ooh.header_id,NULL,'||'''ALL'''||')* DECODE (ooh.order_category_code, '||'''RETURN'''||', -1, 1) AS "Order Total",
    CONCAT(CONCAT(ol.line_number,'||'''.'''||'),ol.shipment_number) AS "Line Number",
    ol.ordered_item AS "Item Number",
    ldmf_get_customer_item(ol.sold_to_org_id,ol.inventory_item_id,ol.invoice_to_org_id,ol.ship_to_org_id) AS "Customer SKU",
    --ldmf_istore_order_pkg.get_wwdb_prod_description(ol.inventory_item_id) AS description,
                             --CO73977 iStore product description change start by manish
                             --DECODE(p_resp_key,'||'''AP'''||',LINT_LOGI_STG_ITEM_DETAILS_PKG.GET_AP_ITEM_CATEGORY_DTL(ol.inventory_item_id),ldmf_istore_order_pkg.get_wwdb_prod_description(ol.inventory_item_id)) AS description,
              --CO73977 iStore product description change end by manish
                             LINT_LOGI_STG_ITEM_DETAILS_PKG.GET_AP_ITEM_CATEGORY_DTL(ol.inventory_item_id) AS description,
    ol.ordered_quantity AS "Ordered Quantity",
    ol.shipped_quantity AS "Shipped Quantity",
    TO_CHAR(ol.schedule_ship_date,'||'''DD-MON-YYYY'''||') AS "Schedule Ship Date",
    ol.unit_selling_price AS "Unit Price",
    ol.ordered_quantity * ol.unit_selling_price AS "Extended Amount",
    ol.tax_value "taxes_total",
    ldmf_istore_order_pkg.get_freight_charges(ooh.header_id,ol.line_id) AS "Freight Charges",
    ldmf_istore_order_pkg.get_pallet_charges (ooh.header_id,ol.line_id) AS "Pallet Surcharge",
    oe_oe_totals_summary.line_charges (ooh.header_id, ol.line_id ) AS "Total Charges",
    DECODE(oell.meaning,'||'''Awaiting Shipping'''||','||'DECODE(TO_CHAR(LDMF_ISTORE_ORDER_PKG.CHK_DELIVERY_LN_EXISTS(ol.header_id,ol.line_id)),'||
                                                                                                                  '''1'''||','||'''Picked'''||','||
                                                                                                                       '''2'''||','||'''Picked Partial'''||','||'oell.meaning)
                             ,oell.meaning) AS "Line Status",
    TO_CHAR(ol.actual_shipment_date,'||'''DD-MON-YYYY'''||') AS "Ship Date",
    (SELECT ware_house.NAME
    FROM hr_all_organization_units_tl ware_house
    WHERE ware_house.organization_id = NVL(ol.ship_from_org_id,ooh.ship_from_org_id)) AS WAREHOUSES,
    LDMF_ISTORE_ORDER_PKG.GET_TRACKING_NUMBER(ol.header_id,ol.line_id) AS "Tracking Number",
    LDMF_ISTORE_ORDER_PKG.GET_WAYBILL_NUMBER(ol.header_id,ol.line_id) AS "Waybill Number",
    LDMF_ISTORE_ORDER_PKG.GET_DELIVERY_NUMBER(ol.header_id,ol.line_id) delivery_number,
    LDMF_ISTORE_ORDER_PKG.GET_PRO_NUMBER(ol.header_id,ol.line_id) AS "Pro Number",
    LDMF_ISTORE_SALESREP_PKG.LDMF_ISTORE_CHECK_HOLDS(hcaa.cust_account_id,ooh.header_id,ol.line_id) AS "Hold Applied",
    LDMF_ISTORE_ORDER_PKG.GET_CONV_RATE(ol.ordered_item_id,ooh.org_id) AS "Pallet Qty",
    ROUND(ol.ordered_quantity/DECODE(LDMF_ISTORE_ORDER_PKG.GET_CONV_RATE(ol.ordered_item_id,ooh.org_id),0,1,LDMF_ISTORE_ORDER_PKG.GET_CONV_RATE(ol.ordered_item_id,ooh.org_id)),2) AS "Pallet#",
    ldmf_istore_order_pkg.get_invoice_number(ooh.order_number,ol.line_id) AS "Invoice Number",
    ldmf_istore_salesrep_pkg.get_promonum(ooh.header_id,ol.line_id) AS "Promo Number",
    ol.line_number,ol.shipment_number,ooh.header_id,ooh.ordered_date,
    LDMF_ISTORE_ORDER_PKG.GET_SHIP_METHOD_MEANING(ol.header_id,ol.line_id) AS SHIP_METHOD_CODE,
    terms.description AS "Payment_Term_Desc",
    TO_CHAR((LDMF_ISTORE_ORDER_PKG.GET_ESTI_ARR_DATE(ol.ACTUAL_SHIPMENT_DATE,
                             ol.SHIP_FROM_ORG_ID,
                             ol.SHIP_TO_ORG_ID,
                             ol.SHIPPING_METHOD_CODE )),'||'''DD-MON-YYYY'''||') AS "Arrival_Date",
                             DECODE (LDMF_ISTORE_ORDER_PKG.GET_ORD_AMDMT_STATUS(ooh.header_id,ol.line_id),1 ,'||'''YES'''||',NULL) AS "Pending_Approval"
    FROM oe_order_headers_all ooh,
    oe_order_lines_all ol,
    hz_cust_accounts_all hcaa,
    oe_transaction_types_all otta,
    oe_transaction_types_tl ott,
    hz_parties hp,
    hz_party_sites hps,
    oe_lookups oel,
    oe_lookups oell,
    ra_terms terms,
    fnd_lookup_values freight,
    fnd_lookup_values fob,
    wsh_new_deliveries dl,
    wsh_delivery_details dd,
    wsh_delivery_assignments da,
    oe_order_holds_all holds,
    hz_cust_site_uses_all bill_to,
    hz_cust_acct_sites_all bill_cas,
    hz_cust_site_uses_all ship_to,
    hz_cust_acct_sites_all ship_cas,
    hz_locations loc,
    ra_territories terr,
    org_organization_definitions ware_house,
    wsh_carrier_services wcs
    WHERE ooh.header_id = ol.header_id
    AND ooh.sold_to_org_id = hcaa.cust_account_id
    AND wcs.ship_method_code(+) = ol.shipping_method_code
    AND hcaa.party_id = hp.party_id
    AND hps.party_id = hp.party_id
    AND loc.location_id = hps.location_id
    AND ship_cas.party_site_id = hps.party_site_id
    AND ooh.order_type_id = otta.transaction_type_id
    AND ooh.order_type_id = ott.transaction_type_id
    AND terms.term_id(+) = ooh.payment_term_id
    AND da.delivery_id = dl.delivery_id (+)
    AND dd.delivery_detail_id = da.delivery_detail_id(+)
    AND ship_to.cust_acct_site_id = ship_cas.cust_acct_site_id
    AND ship_to.site_use_id = ooh.ship_to_org_id
    AND ware_house.organization_id(+) = ol.ship_from_org_id
    AND bill_to.cust_acct_site_id = bill_cas.cust_acct_site_id
    AND bill_to.site_use_id = ooh.invoice_to_org_id
    AND bill_to.territory_id = terr.territory_id
    AND ol.header_id = dd.source_header_id(+)
    AND ol.line_id = dd.source_line_id(+)
    AND ol.line_id = holds.line_id(+)
    AND freight.lookup_type = '||'''FREIGHT_TERMS'''||'
    AND freight.LANGUAGE =USERENV('||'''LANG'''||')
    AND freight.lookup_code = ooh.freight_terms_code
    AND ott.LANGUAGE = USERENV('||'''LANG'''||')
    AND fob.lookup_code = ooh.fob_point_code
    AND fob.lookup_type = '||'''FOB'''||'
    AND fob.LANGUAGE =USERENV('||'''LANG'''||')
    AND NVL(otta.attribute10,'||'''Y'''||') <> '||'''N'''||'
    AND oel.lookup_code = ooh.flow_status_code
    AND oel.lookup_type = '||'''FLOW_STATUS'''||'
    AND oell.lookup_code = ol.flow_status_code
    AND oell.lookup_type = '||'''LINE_FLOW_STATUS'''||'
    AND ol.line_category_code <> '||'''RETURN'''||'
    AND ooh.order_category_code IN ('||'''ORDER'''||','||'''MIXED'''||')
    AND ooh.sold_to_org_id = '||p_sold_to_org_id
    || ' AND TRUNC(ooh.ordered_date) >= TRUNC(SYSDATE - '||p_no_of_days||')';
    v_statement := v_statement || ' ORDER BY ooh.ordered_date DESC,ooh.header_id,ol.line_number,ol.shipment_number ';
    OPEN p_data FOR v_statement;
    EXCEPTION
    WHEN OTHERS THEN
    errbuf := SQLERRM ;
    retcode := SQLCODE ;
    END ORDER_TRACKER_DAYS;
    --This Procedure fetches the Order details between the given from date and to date.
    PROCEDURE ORDER_TRACKER_BETWEEN_DAYS( p_sold_to_org_id IN NUMBER
    ,p_search_by IN VARCHAR2
    ,p_start_date IN DATE
    ,p_end_date IN DATE
                             ,p_resp_key IN VARCHAR2
    ,p_data OUT shop_cartdownload
    ,errbuf OUT VARCHAR2
    ,retcode OUT NUMBER
    ) AS
    v_start_date VARCHAR2(1000);
    v_end_date VARCHAR2(1000);
    v_search_by VARCHAR2(1000);
    BEGIN
    SELECT ''''||p_start_date||'''' INTO v_start_date FROM dual;
    SELECT ''''||p_end_date||'''' INTO v_end_date FROM dual;
    v_statement := NULL;
    v_statement := 'SELECT /*+ FIRST_ROWS */ DISTINCT ooh.order_number AS "Order Number",
    NVL(bill_cas.attribute5,hp.party_name) AS "Customer Name",
    TO_CHAR(ooh.ordered_date,'||'''DD-MON-YYYY'''||') AS "Order Date",
    TO_CHAR(ooh.booked_date,'||'''DD-MON-YYYY'''||') AS "Booked Date",
    TO_CHAR(ol.request_date,'||'''DD-MON-YYYY'''||') AS "Requested Date",
    oel.meaning AS "Order Status",
    ooh.cust_po_number AS "PO Number",
    ooh.transactional_curr_code AS currency,
    terms.NAME AS "Payment Terms",
    freight.meaning AS "Freight Term",
    fob.meaning AS "FOB",
    ooh.sales_channel_code AS "Sales Channel",
    bill_to.LOCATION AS "Bill To Location",
    ship_to.LOCATION AS "Ship To Location",
    terr.segment1 AS "Sales Territory - Country",
    ott.NAME AS "Order Type",
    oe_totals_grp.get_order_total (ooh.header_id,NULL,'||'''ALL'''||')* DECODE (ooh.order_category_code, '||'''RETURN'''||', -1, 1) AS "Order Total",
    CONCAT(CONCAT(ol.line_number,'||'''.'''||'),ol.shipment_number) AS "Line Number",
    ol.ordered_item AS "Item Number",
    ldmf_get_customer_item(ol.sold_to_org_id,ol.inventory_item_id,ol.invoice_to_org_id,ol.ship_to_org_id) AS "Customer SKU",
    --ldmf_istore_order_pkg.get_wwdb_prod_description(ol.inventory_item_id) AS description,
                             --CO73977 iStore product description change start by manish
                             DECODE(p_resp_key,'||'''AP'''||',LINT_LOGI_STG_ITEM_DETAILS_PKG.GET_AP_ITEM_CATEGORY_DTL(ol.inventory_item_id),ldmf_istore_order_pkg.get_wwdb_prod_description(ol.inventory_item_id)) AS description,
              --CO73977 iStore product description change end by manish
    ol.ordered_quantity AS "Ordered Quantity",
    ol.shipped_quantity AS "Shipped Quantity",
    TO_CHAR(ol.schedule_ship_date,'||'''DD-MON-YYYY'''||') AS "Schedule Ship Date",
    ol.unit_selling_price AS "Unit Price",
    ol.ordered_quantity * ol.unit_selling_price AS "Extended Amount",
    ol.tax_value "taxes_total",
    ldmf_istore_order_pkg.get_freight_charges(ooh.header_id,ol.line_id) AS "Freight Charges",
    ldmf_istore_order_pkg.get_pallet_charges (ooh.header_id,ol.line_id) AS "Pallet Surcharge",
    oe_oe_totals_summary.line_charges (ooh.header_id, ol.line_id ) AS "Total Charges",
    DECODE(oell.meaning,'||'''Awaiting Shipping'''||','||'DECODE(TO_CHAR(LDMF_ISTORE_ORDER_PKG.CHK_DELIVERY_LN_EXISTS(ol.header_id,ol.line_id)),'||
                                                                                         '''1'''||','||'''Picked'''||','||
                                                                                              '''2'''||','||'''Picked Partial'''||','||'oell.meaning)
                             ,oell.meaning) AS "Line Status",
    TO_CHAR(ol.actual_shipment_date,'||'''DD-MON-YYYY'''||') AS "Ship Date",
    (SELECT ware_house.NAME
    FROM hr_all_organization_units_tl ware_house
    WHERE ware_house.organization_id = NVL(ol.ship_from_org_id,ooh.ship_from_org_id)) AS WAREHOUSES,
    LDMF_ISTORE_ORDER_PKG.GET_TRACKING_NUMBER(ol.header_id,ol.line_id) AS "Tracking Number",
    LDMF_ISTORE_ORDER_PKG.GET_WAYBILL_NUMBER(ol.header_id,ol.line_id) AS "Waybill Number",
    LDMF_ISTORE_ORDER_PKG.GET_DELIVERY_NUMBER(ol.header_id,ol.line_id) delivery_number,
    LDMF_ISTORE_ORDER_PKG.GET_PRO_NUMBER(ol.header_id,ol.line_id) AS "Pro Number",
    LDMF_ISTORE_SALESREP_PKG.LDMF_ISTORE_CHECK_HOLDS(hcaa.cust_account_id,ooh.header_id,ol.line_id) AS "Hold Applied",
    LDMF_ISTORE_ORDER_PKG.GET_CONV_RATE(ol.ordered_item_id,ooh.org_id) AS "Pallet Qty",
    ROUND(ol.ordered_quantity/DECODE(LDMF_ISTORE_ORDER_PKG.GET_CONV_RATE(ol.ordered_item_id,ooh.org_id),0,1,LDMF_ISTORE_ORDER_PKG.GET_CONV_RATE(ol.ordered_item_id,ooh.org_id)),2) AS "Pallet#",
    ldmf_istore_order_pkg.get_invoice_number(ooh.order_number,ol.line_id) AS "Invoice Number",
    ldmf_istore_salesrep_pkg.get_promonum(ooh.header_id,ol.line_id) AS "Promo Number",
    ol.line_number,ol.shipment_number,ooh.header_id,ooh.ordered_date,
    LDMF_ISTORE_ORDER_PKG.GET_SHIP_METHOD_MEANING(ol.header_id,ol.line_id) AS SHIP_METHOD_CODE,
    terms.description AS "Payment_Term_Desc",
    TO_CHAR((LDMF_ISTORE_ORDER_PKG.GET_ESTI_ARR_DATE(ol.ACTUAL_SHIPMENT_DATE,
                             ol.SHIP_FROM_ORG_ID,
                             ol.SHIP_TO_ORG_ID,
                             ol.SHIPPING_METHOD_CODE )),'||'''DD-MON-YYYY'''||') AS "Arrival_Date",
                             DECODE (LDMF_ISTORE_ORDER_PKG.GET_ORD_AMDMT_STATUS(ooh.header_id,ol.line_id),1 ,'||'''YES'''||',NULL) AS "Pending_Approval"
    FROM oe_order_headers_all ooh,
    oe_order_lines_all ol,
    hz_cust_accounts_all hcaa,
    oe_transaction_types_all otta,
    oe_transaction_types_tl ott,
    hz_parties hp,
    hz_party_sites hps,
    oe_lookups oel,
    oe_lookups oell,
    ra_terms terms,
    fnd_lookup_values freight,
    fnd_lookup_values fob,
    wsh_new_deliveries dl,
    wsh_delivery_details dd,
    wsh_delivery_assignments da,
    oe_order_holds_all holds,
    hz_cust_site_uses_all bill_to,
    hz_cust_acct_sites_all bill_cas,
    hz_cust_site_uses_all ship_to,
    hz_cust_acct_sites_all ship_cas,
    hz_locations loc,
    ra_territories terr,
    org_organization_definitions ware_house,
    wsh_carrier_services wcs
    WHERE ooh.header_id = ol.header_id
    AND ooh.sold_to_org_id = hcaa.cust_account_id
    AND wcs.ship_method_code(+) = ol.shipping_method_code
    AND hcaa.party_id = hp.party_id
    AND hps.party_id = hp.party_id
    AND loc.location_id = hps.location_id
    AND ship_cas.party_site_id = hps.party_site_id
    AND ooh.order_type_id = otta.transaction_type_id
    AND ooh.order_type_id = ott.transaction_type_id
    AND terms.term_id(+) = ooh.payment_term_id
    AND da.delivery_id = dl.delivery_id (+)
    AND dd.delivery_detail_id = da.delivery_detail_id(+)
    AND ship_to.cust_acct_site_id = ship_cas.cust_acct_site_id
    AND ship_to.site_use_id = ooh.ship_to_org_id
    AND ware_house.organization_id(+) = ol.ship_from_org_id
    AND bill_to.cust_acct_site_id = bill_cas.cust_acct_site_id
    AND bill_to.site_use_id = ooh.invoice_to_org_id
    AND bill_to.territory_id = terr.territory_id
    AND ol.header_id = dd.source_header_id(+)
    AND ol.line_id = dd.source_line_id(+)
    AND ol.line_id = holds.line_id(+)
    AND freight.lookup_type = '||'''FREIGHT_TERMS'''||'
    AND freight.LANGUAGE =USERENV('||'''LANG'''||')
    AND freight.lookup_code = ooh.freight_terms_code
    AND ott.LANGUAGE = USERENV('||'''LANG'''||')
    AND fob.lookup_code = ooh.fob_point_code
    AND fob.lookup_type = '||'''FOB'''||'
    AND fob.LANGUAGE =USERENV('||'''LANG'''||')
    AND NVL(otta.attribute10,'||'''Y'''||') <> '||'''N'''||'
    AND oel.lookup_code = ooh.flow_status_code
    AND oel.lookup_type = '||'''FLOW_STATUS'''||'
    AND ol.line_category_code <> '||'''RETURN'''||'
    AND ooh.order_category_code IN ('||'''ORDER'''||','||'''MIXED'''||')
    AND oell.lookup_code = ol.flow_status_code
    AND oell.lookup_type = '||'''LINE_FLOW_STATUS'''||'
    AND ooh.sold_to_org_id = '||p_sold_to_org_id ;
    IF p_search_by = '1' THEN
    v_search_by := ' AND TRUNC(ooh.ordered_date) ';
    ELSIF p_search_by = '2' THEN
    v_search_by := ' AND TRUNC(ol.request_date) ';
    ELSIF p_search_by = '3' THEN
    v_search_by := ' AND TRUNC(ol.actual_shipment_date) ';
    ELSIF p_search_by = '4' THEN
    v_search_by := ' AND TRUNC(ol.schedule_ship_date) ';
    END IF;
    v_statement := v_statement || v_search_by;
    v_statement := v_statement ||' >= '|| v_start_date || v_search_by ||' <= '||v_end_date;
    v_statement := v_statement || ' ORDER BY ooh.ordered_date DESC,ooh.header_id,ol.line_number,ol.shipment_number ';
    OPEN p_data FOR v_statement;
    EXCEPTION
    WHEN OTHERS THEN
    errbuf := SQLERRM ;
    retcode := SQLCODE ;
    END ORDER_TRACKER_BETWEEN_DAYS;

  • Decode Function issue

    Hi all,
    i want compare two rows in a table. so i used decode function to compare the values, whether its matched or not.
    One of my table column has Long data type.
    Decode(a.col1,b.col1,'Match','NotMatch')
    col1 - is long data type.
    when i use long data type, i got below error,
    is there anyway to rectify this error.
    SQL Error: ORA-00932: inconsistent datatypes: expected NUMBER got LONG
    00932. 00000 - "inconsistent datatypes: expected %s got %s"
    Thanks in advance.
    Regards,
    Santhosh

    >
    You can't use ANY function on a LONG column. This restriction is not limited to DECODE.
    >
    Not quite correct.
    You can use TO_LOB on a LONG column but only in the select list of a subquery in an INSERT statement.
    See TO_LOB in the SQL Language doc
    http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions205.htm#SQLRF06134
    >
    TO_LOB converts LONG or LONG RAW values in the column long_column to LOB values. You can apply this function only to a LONG or LONG RAW column, and only in the select list of a subquery in an INSERT statement.
    Before using this function, you must create a LOB column to receive the converted LONG values. To convert LONG values, create a CLOB column. To convert LONG RAW values, create a BLOB column.
    You cannot use the TO_LOB function to convert a LONG column to a LOB column in the subquery of a CREATE TABLE ... AS SELECT statement if you are creating an index-organized table. Instead, create the index-organized table without the LONG column, and then use the TO_LOB function in an INSERT ... AS SELECT statement.
    You cannot use this function within a PL/SQL package. Instead use the TO_CLOB or TO_BLOB functions.

  • DECODE Function in Oracle Froms 6.0

    I have discovered that in Oracle Forms 6.0 (Version 6.0.5.34.0) the DECODE Function performs an implicit TO_CHAR conversion that the DECODE Function in the Oracle 8 database does not.
    I discovered this when working with dates on the form. Dates prior to 2000 were not formatting correctly and all dates were not sorting correctly. By adding TO_DATE with the correct format mask outside of the DECODE statement the correct results were returned.
    When trouble shooting this through SQL Navigator connected directly to the database, the correct results were returned without having to use the TO_DATE function.

    Why don't you have any join conditions specified for your two inline views cr and de?
    If you want help with a query you should post DDL and inserts statements to create enough test data for someone to produce the set of results that you are looking for.
    HTH -- Mark D Powell --

  • Decode function involving 2 fields (urgent)

    Hi .. I am trying to use the decode function involving 2 fields.
    The query runs but does not produce the correct results. If
    anyone knows, please reply .. Usually decode function involves
    one column only but I have more
    than one. The situation is : If ins_code = 2 or special_code =
    MMI, put a 'Y', otherwise, it's a 'N'. Does anyone know how to
    put this in a decode statement? Thanks

    Thanks, Suresh ... but I have to put this condition using the
    decode statement because that's how the rest of the program is
    written. It's part of the script that I have to change. The
    current statement is this: decode(ins_code, '2', 'Y', 'N'). I
    have to change it to ins_code =2 or special_feature = MMI.
    Please reply ... thanks a lot....

  • DECODE function in Oracle gives duplicate data

    Hi,
    I want to retrieve distinct result using decode function and given below are the queries for that.
    SELECT DISTINCT O.*, DECODE(TA,'AP',AMT,'AC1',AMT,'AC2',AMT,'AC3',AMT,'AC4',AMT,NULL) AS CA,
    DECODE(TA,'AD1',AMT,NULL) AS DA FROM HT O, HIS H, V_CV
    WHERE O.HID=H.HID AND H.HTYP='TRN' AND O.HID = V.HID AND V.CID = '5' ORDER BY CA ASC;
    which gives me
    HID   TA      PT     AMT     CA         DA
    2     A     V     4.1     4.1     null
    3     C     V     14.02 14.02     null
    1     D     V 5.1     null          5.1
    4     D     V     6.21     null      6.21
    which is correct but i want to do sorting on two different column which do not exit in the database and they are dynamic.So i Modified the Query but i am getting duplicate results
    SELECT DISTINCT O.*,
    DECODE(o.TA,cr.TA,o.AMT,NULL) AS CA,
    DECODE(o.TA,de.TA,o.AMT,NULL) AS DA
    FROM HT O,
    HIS H,
    V_CV,
    (select TA from RTD where Ttype= 'C') cr,
    (select TA from RTD where Ttype= 'D') de
    WHERE
    O.HID=H.HID
    AND H.HTYP='TRN'
    AND O.HID = V.HID
    AND V.CID = '5'
    ORDER BY CA ASC
    which gives me
    HID   TA      PT     AMT     CA         DA
    2     A     V     4.1     4.1     null
    3     C     V     14.02 14.02     null
    3     C     V     14.02 null      null
    1     D     V 5.1     null          5.1
    1     D     V 5.1     null          null
    4     D     V     6.21     null      6.21
    2     A     V     4.1     null     null
    which is obviously giving HID 2,3,1 as duplicate value since DECODE select a value and compares with all item where i want only single comparison.
    Any help regarding this would be appreciated.
    Edited by: Pawanchoure on Jul 5, 2011 7:14 AM

    Why don't you have any join conditions specified for your two inline views cr and de?
    If you want help with a query you should post DDL and inserts statements to create enough test data for someone to produce the set of results that you are looking for.
    HTH -- Mark D Powell --

  • Decode Function I asked this in the wrong section so I hope Im right now!

    select
    a11.SEQ_MEMB_ID,
    a11.Auth_Number,
    a11.Admit_Primary_Date,
    a11.Reviewer,
    Decode (a11.Reviewer,
    CLC, '2',
    HBR, '3',
    RAB, '4')
    a11.admit_primary_date
    from windsoradm.auth_master a11;
    I am trying to get if the Reviewer is CLC then they are code 2 HBR Code 3 etc and it does not work. I take out the decode function and the query works. I am getting ORA-00923 FROM KEYWORD NOT FOUND WHERE EXPECTED.

    Hi,
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    Simplify the problem as much as possible. Remove all tables and columns that play no role in this problem.
    Always say which version of Oracle you're using.
    This is the right forum for this question. Mark your question in the other forum {message:id=10266930} as "Answered", so people won't waste their time.
    925518 wrote:
    select
    a11.SEQ_MEMB_ID,
    a11.Auth_Number,
    a11.Admit_Primary_Date,
    a11.Reviewer,
    Decode (a11.Reviewer,
    CLC, '2',
    HBR, '3',
    RAB, '4')
    a11.admit_primary_date
    from windsoradm.auth_master a11;
    I am trying to get if the Reviewer is CLC then they are code 2 HBR Code 3 etc and it does not work. I take out the decode function and the query works. I am getting ORA-00923 FROM KEYWORD NOT FOUND WHERE EXPECTED.That's the correct DECODE syntax, where CLC, HBR and RAB are columns, and you want to return a string (not a number) such as '2'.
    If 'CLC', 'HBR' and 'RAB' are literal values, then enclose them in single-quotes. If you want to return a number, don't put it in quotes. (Anyhting inside single-quotes is a string literal.)
    Perhaps you meant something like:
    ,     DECODE ( a11.Reviewer
                , 'CLC'          , 1
                , 'HBR'          , 2
                , 'RAB'          , 3
                )      AS reviewer_codeThere's an error right after the DECODE. You can't use a11.admit_primary_date as a column alias. (This is probably what's causing the ORA-00923 error.) Either a11_admit_primary_date (with an underscore instead of a dot) or admit_primary_date would be okay. If a11.admit_priomary_date is the next column in the SELECT clause, put a comma befor it.
    You need a FROM clause.

  • Decode Function Help

    Hi,
    I am new to Oracle Development.
    MY Requirement:
    I need to populate a column 'ISMSG' with YES / NO based on the following condition
    When code = 'S' or 'O'......the column 'ISMSG' should display YES else NO..
    ie output should be like
    CODE ISMSG
    A NO
    S YES
    S YES
    O YES
    My code for Decode function:
    CASE
    WHEN c.code = 'S' THEN decode( c.code, 'S','YES','NO')
    WHEN c.code = 'O' THEN decode( c.code, 'O','YES','NO')
    END ISMSG,
    Is my code correct? If so is this the best way to do it?
    If not please correct the code.
    Is there an efficient way to do it?
    Thanks in advance.

    Hi,
    You can use either CASE or DECODE for that; there's no need to use both.
    Using CASE:
    SELECT  c.code
    ,     CASE
             WHEN  c.code  IN  ('S', '0')  THEN  'YES'
                                               ELSE  'NO'
         END     AS ismsg
    FROM    table_x   c;Using DECODE:
    SELECT  c.code
    ,     DECODE ( c.code 
                , 'S'      , 'YES'
                , '0'      , 'YES'
                              'NO'
                )          AS ismsg
    FROM    table_x   c;I suggest you forget about DECODE, and always use CASE, at least while you're just starting out.
    CASE can do anything that DECODE can do. There are a few, simple situations where DECODE is a little shorter than CASE, and therefore a little clearer, but only a little, and, as I said, these are only simple situations, and CASE is clear enough in them.
    DECODE is never much shorter or clearer than CASE. The converse is not true: there are many situations where CASE is much, much shorter and clearer than DECODE.

  • Help for decode function

    Hi all,
    I want to use decode function in RTF template.
    I know i can use if statement to deal with it ,but if the conditions are over 3, if statement is not good choice.
    Here is the if condition statement
    <?if:answer='Y'?>Yes<?end if?> <?if:answer='N'?>No<?end if?>
    how can i translate this if statement to use decode function
    I tried to use the statement as below, but it doesn't work.
    <?xdofx:decode(:answer,Y,'YES',N,'NO')?>
    using this statement i got empty in this field.
    I appreciate any responds, thanks in advance.
    appcat

    Hi,
    it should work,coz there is no xsl equivalent for this function that i have seen on blogs,
    the syntax that i have got it from other xmlp blogs, sounds like you put correct syntax, try to give multiple conditions to check the result
    <?xdofx:decode(’xxx’,’bbb’,’ccc’,’xxx’,
    ’ddd’)?>
    srinuk

  • Help needed in decode function

    I am trying to use decode function shown below
    select decode(deptid,(select deistinct dept_id from dept),'found') into id from student ;
    it shows error ORA 01427:single-row subquery returns more than one row.
    could you people help me resovle the issue.
    Thanks.

    Funny thing how many mistakes can be in one little line. I try to list what is wrong here. maybe it helps you to understand what is going on.
    select decode(deptid,(select deistinct dept_id from dept),'found') into id from student ;1) "deistinct" => wrong spelling "distinct"
    2) Uniqueness => the typical DEPT table has DEPT_ID as a primary key. So DISTINCT would do nothing here. "select distinct dept_id from dept" is the same as "select dept_id from dept".
    3) decode with a multi-row subquery => the decode function only accepts single values. e.g: ,"decode(deptid,(select max(dept_id) from dept),..." => THis is not really useful, just an example.
    4) decode without handling other values => it is better to say what should happen, when the values does not match. decode(deptid,:x,'found','notfound')
    5) select .. into ... from. => INTO is only used in a PL/SQL . So I assume this statement is part of a larger PL/SQL block. In that case "into id " is a problem. The select would return many values, but your ID variable could probably hold only one value.
    6) Identification of values => For all students that could be returned, you only would know 'found'. At least select the ID for the student too, else you wouldn't know which student was found. select id, 'found' ... from student.
    7) Don't select everthing and check for each row later. Select only relevent rows. That means do your checks in the WHERE clause of a select statement not in the SELECT clause. Example: "select id from student where dept_id in (select dept_id from dept);" Possible in this case is also a join "select student.id from student, dept where student.dept_id=dept.dept_id"
    8) referential integrity. Why do have to do this check anyway? On table student there should be a FK constraint, so that only values can be inserted where the DEPT_ID is correct. Then you select would be "select id from student;".

  • Question regarding decode function.

    Hi friends,
    I have a question regarding using decode.
    I'm try'g to explain my problem using emp table.
    Can you guys please help me out.
    For example consider emp table, now i want to get all manager id's concatenated for 2 employees.
    I tried using following code
    declare
    v_mgr_code  number(10);
    v_mgr1      number(4);
    v_mgr2      number(4);
    begin
    select  mgr into    v_mgr1
    from    scott.emp
    where   empno = 7369;
    select  mgr into    v_mgr2
    from    scott.emp
    where   empno = 7499;
    select v_mgr1||'-'||v_mgr2 into v_mgr_code from dual;
    end;now instead of writing 2 select statements can i write one select statement using decode function ?
    Edited by: user642856 on Mar 8, 2009 11:18 PM

    i don't know wheter your looking for this or not.if i am wrong correct me.
    SELECT Ename||' '||initcap('manager is ')||
    DECODE(MGR,
            7566, (SELECT Ename
                    FROM Emp
                    WHERE Empno = 7566),
            7698, (SELECT Ename
                    FROM Emp
                    WHERE Empno = 7698),
            7782, (SELECT Ename
                    FROM Emp
                    WHERE Empno = 7782),
            7788, (SELECT Ename
                    FROM Emp
                    WHERE Empno = 7788),
            7839, (SELECT Ename
                    FROM Emp
                    WHERE Empno = 7839),
            7902, (SELECT Ename
                    FROM Emp
                    WHERE Empno = 7902),
            'Do Not Know')  Manager from empor
    SELECT Ename||' '||initcap('manager is ')||
    DECODE(MGR,
            7566, (SELECT empno
                    FROM Emp
                    WHERE Empno = 7566),
            7698, (SELECT empno
                    FROM Emp
                    WHERE Empno = 7698),
            7782, (SELECT empno
                    FROM Emp
                    WHERE Empno = 7782),
            7788, (SELECT empno
                    FROM Emp
                    WHERE Empno = 7788),
            7839, (SELECT empno
                    FROM Emp
                    WHERE Empno = 7839),
            7902, (SELECT empno
                    FROM Emp
                    WHERE Empno = 7902)) manager
    from empEdited by: user4587979 on Mar 8, 2009 9:52 PM

  • Logical Operations in SQL decode function ?

    Hi,
    Is it possible to do Logical Operations in SQL decode function
    like
    '>'
    '<'
    '>='
    '<='
    '<>'
    not in
    in
    not null
    is null
    eg...
    select col1 ,order_by,decode ( col1 , > 10 , 0 , 1)
    from tab;
    select col1 ,order_by,decode ( col1 , <> 10 , 0 , 1)
    from tab;
    select col1 ,order_by,decode ( col1 , not in (10,11,12) , 0 , 1)
    from tab;
    select col1 ,order_by,decode ( col1 ,is null , 0 , 1)
    from tab;
    Regards,
    infan
    Edited by: user780731 on Apr 30, 2009 12:07 AM
    Edited by: user780731 on Apr 30, 2009 12:07 AM
    Edited by: user780731 on Apr 30, 2009 12:08 AM
    Edited by: user780731 on Apr 30, 2009 12:08 AM
    Edited by: user780731 on Apr 30, 2009 12:09 AM

    example:
    select col1 ,order_by,case when col1 > 10 then 0 else 1 end
    from tab;
    select col1 ,order_by,case when col1 &lt;&gt; 10 then 0 else 1 end
    from tab;
    select col1 ,order_by,case when col1 not in (10,11,12) then 0 else 1 end
    from tab;As for testing for null, decode handles that by default anyway so you can have decode or case easily..
    select col1 ,order_by,decode (col1, null , 0 , 1)
    from tab;
    select col1 ,order_by,case when col1 is null then 0 else 1 end
    from tab;

  • SQL Expression in decode function or case statement?

    Can I put SQL expressions in decode function or case statement?
    For example,
    select le.profile, decode( select count(1) from profile_data where NAME= 'XXXX_AFTER' and object_id = le.profile, 0, 'N', 'Y')
    from element le;
    or
    select le.profile, case WHEN ( select count(1) from profile_data where NAME= 'XXXX_AFTER' and object_id = le.profile) = 0 THEN 'N'
    ELSE 'Y'
    from element le;
    None of the above work.
    Can anyone tell me how to make it work?
    Is there any workaround?
    Thanks,
    J

    You simply needed and END to your CASE statement;
    SQL> with profile_data as (
       select 'XXXX_AFTER' name, 1 object_id from dual),
         element as (
       select 1 profile from dual union all
       select 2 from dual)
    select le.profile,
       case WHEN ( select count(1) from profile_data where NAME= 'XXXX_AFTER' and object_id = le.profile) = 0
       THEN 'N'
       ELSE 'Y'
       END new_col
    from element le
       PROFILE N
             1 Y
             2 N

  • SQL DECODE function

    Oracle version: 9.2.0.1.0
    Procob version: 9.2.0.1.0
    Cobol version: 3.1.11
    O.S. version: Windows XP
    We have a pro*cobol file with the next conversion rule into a select defined with a cursor.
    NVL(TO_CHAR(A.F_ALTA,'YYYYMMDD'),' '),     
    NVL(TO_CHAR(A.F_ESTADO,'YYYYMMDD'),' '),
    we store the result data through a fetch of the cursor into two variables (W-F-ALTA and W-F-ESTADO) When the program executes an insert of these two values in a target table, we define the next conversion rule:
    TO_DATE(DECODE(:W-F-ALTA,' ',NULL,:W-F-ALTA),'YYYYMMDD'),
    TO_DATE(DECODE(:W-F-ESTADO,' ',NULL,:W-F-ESTADO),'YYYYMMDD')
    Pro*Cobol and Cobol does not have errors when we precompile and compile the program but, when we execute the generated exe file, Oracle displays the next error:
    ORA-01841 (full) year must be between -4713 and +9999, and not be 0
    We think that the DECODE function is not understood by the cobol or pro*cobol interpreter. If we execute the same code without the DECODE function (only with TO_DATE function) there is no errors in the execution of the program
    somebody knows if there are reported problems with this DECODE function in Pro*Cobol or Cobol and how to solve them?
    Thanks

    TO_DATE(DECODE(:W-F-ALTA,' ',NULL,:W-F-ALTA),'YYYYMMDD'),
    TO_DATE(DECODE(:W-F-ESTADO,' ',NULL,:W-F-ESTADO),'YYYYMMDD')The problem is with the input values of :W-F-ALTA and :W-F-ESTADO. Using the first line as an example, what you are saying is if :W-F-ALTA is ' ', substitute it with NULL, any other value should be :W-F-ALTA, then output the TO_DATE value of whatever the result is.
    So if the value of :W-F-ALTA is the wrong charater or in the wrong input format, TO_DATE function does not understand it.
    See examples of success and failures below with your Bind variables substituted with typical values.
    SQL> select TO_DATE(DECODE(' ',' ',NULL,'20060830'),'YYYYMMDD') from dual;
    TO_DATE(D
    SQL> select TO_DATE(DECODE('1999-01-01',' ','NULL','20060830'),'YYYYMMDD') from dual;
    TO_DATE(D
    30-AUG-06
    SQL> select TO_DATE(DECODE('SHOULD_ERROR',' ','NULL','SHOULD_ERROR'),'YYYYMMDD') from dual;
    select TO_DATE(DECODE('SHOULD_ERROR',' ','NULL','SHOULD_ERROR'),'YYYYMMDD') from dual
    ERROR at line 1:
    ORA-01841: (full) year must be between -4713 and +9999, and not be 0
    SQL> select TO_DATE(DECODE('20060830',' ','NULL','20060830'),'YYYYMMDD') from dual;
    TO_DATE(D
    30-AUG-06
    SQL> select TO_DATE(DECODE('12345678',' ','NULL','12345678'),'YYYYMMDD') from dual;
    select TO_DATE(DECODE('12345678',' ','NULL','12345678'),'YYYYMMDD') from dual
    ERROR at line 1:
    ORA-01843: not a valid month
    SQL>

  • Problem using DECODE() function with a Query of Queries

    I
    posted
    on my blog about an issue I was having trying to use the PL/SQL
    DECODE() function with a Coldfusion Query of Queries. This function
    works fine when you query a database for information. However, when
    you query another query, it seems that CF doesn't recognize it. I
    got errors stating that it found a left parenthesis where it
    expected a FROM key word. Here is a simplified version of what I am
    trying to do:
    quote:
    <!--- Simulated query; similar to what I was calling from
    my database --->
    <cfscript>
    qOriginal = queryNew("Name,Email,CountryCode",
    "VarChar,VarChar,VarChar");
    newRow = queryAddRow(qOriginal, 5);
    querySetCell(qOriginal, "Name", "Joe", 1);
    querySetCell(qOriginal, "Email", "[email protected]", 1);
    querySetCell(qOriginal, "CountryCode", "AMER", 1);
    querySetCell(qOriginal, "Name", "Sally", 2);
    querySetCell(qOriginal, "Email", "[email protected]", 2);
    querySetCell(qOriginal, "CountryCode", "AMER", 2);
    querySetCell(qOriginal, "Name", "Bob", 3);
    querySetCell(qOriginal, "Email", "[email protected]", 3);
    querySetCell(qOriginal, "CountryCode", "ASIA", 3);
    querySetCell(qOriginal, "Name", "Mary", 4);
    querySetCell(qOriginal, "Email", "[email protected]", 4);
    querySetCell(qOriginal, "CountryCode", "EURO", 4);
    querySetCell(qOriginal, "Name", "John", 5);
    querySetCell(qOriginal, "Email", "[email protected]", 5);
    querySetCell(qOriginal, "CountryCode", "EURO", 5);
    </cfscript>
    <cfquery name="qCountries" dbtype="query">
    SELECT DISTINCT(CountryCode) AS CountryCode,
    DECODE(states, "AMER", "North America &amp; Canada",
    "EURO", "Europe &amp; Africa", "ASIA", "Japan &amp;
    Asia","") CountryName
    FROM qOriginal
    ORDER BY CountryCode
    </cfquery>
    <cfdump var="#qCountries#">
    <!--- ========== END OF CODE ========== --->
    So running this returned the following error:
    Query Of Queries syntax error.
    Encountered "(. Incorrect Select Statement, Expecting a
    'FROM', but encountered '(' instead, A select statement should have
    a 'FROM' construct.
    Does anybody know why this doesn't work? Is it just not
    supported? Please note that I have also tried to use the CASE()
    function instead of DECODE() and that resulted in basically the
    same error. For now I an looping over my distinct query with a
    switch statement and manually loading a new query with the data how
    I want it. But it would be a lot cleaner and less code to have the
    DECODE() to work. Thx!

    DECODE() is an Oracle function, not generic SQL. Q-of-Q is a
    very limited subset of SQL and lacks many functions and clauses
    available in standard SQL, especially what you may be used to using
    in your particular RDBMS.
    See
    Query
    of Queries user guide
    Phil

Maybe you are looking for

  • A/C document

    Hi all, when iam trying to create an invoice document and when iam clicking the accounting button the error is dispalyed as a/c doc not yet been created pls help me what to do.

  • Ipod nano version 1.2 update problem

    After many hours and checking out tthe help provided in Discussions Forum I finally manage to install iTunes 7.0 (although I wish I hadn't)I was then prompted to update my ipod to version 1.2 ... Now when I connect the ipod it appears in the source a

  • Optimal communication strategy for poker game

    Hi, I'm designing a client/server poker game, and I'm trying to decide on the best protocol for client/sever comms. It's a personal project, so it doesn't need to be 100% robust or extensible. I was thinking of the following model: Client(s) and serv

  • How do I convert images to whatever icon MAc uses?

    Client: Mac OS 10.6.6 Hi All, I am coming from the Linux side. In Linux, if I an find an Image I like, I can use it on my desktop Icons. Format is not an issue. Questions: 1) in Mac, I have found it wants a particular format. How do I convert Images

  • CS6 corrupt after installing quicktime

    Exports in CS6 premiere, AE and mediaencoder fails horribly. When I open projects in premiere, ALL sound is panned to the left and exports from ME give me videos with audio 'left' only. After 3 weeks of headaches I found the 'solution'. I did full re