Help on Decode function in Toplink
Hi,
I have a sql statement like this:
select field1, field2 from table1 where upper(field1) like 'ADELPHI%'
order by field1,
DECODE(TO_CHAR(NVL(LENGTH(TRANSLATE(field1,'A1234567890','A')),0)),'0',LPAD(field1 ,50),field1)
How would I converted this to toplink query?
I appreciate any help you guys can extend to me.
I just spent about a half hour writing a response here, and the damned forum timed out on me. #$^!@$#!^!@$%.
Here is the summary:
- Using TL Expressions and EJBQL are to allow Java developers who don't necessarily know SQL to write queries and to facilitate portability/maintainability of the apps. For REALLY gnarly queries, using TL Expressions or EJBQL won't buy you this. I.e., SQL is more expressive and easier for this kind of quer, so it's not easier to use, and frankly with the code needed to support it, it won't be easier to maintain or port... Bottom line, maybe SQL is the best option here?
- If you want to experiment, search for TO_CHAR on this forum, and the decode function in the javadoc. You need to build the expressions in pieces and you can treat expressions as arguments to other expressions -- in other words, you can build an expression like builder.leftPad(50, builder.get("field1")) and use it as one of the key/values in the hashtable to the decode function (in theory).
- Don
Similar Messages
-
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.
appcatHi,
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 -
Need help with DECODE function
Hello,
I am trying to use default within the decode function and every time I get a missing expression. I have searched everywhere and cant figure out what I'm doing wrong. Thanks
select decode (request_id,0,'No files found', DEFAULT)Hi,
Welcome to the forum!
When you use a default value, the last argument to DECODE is the actual value you want as a default.
For example:
SELECT ename
, deptno
, DECODE ( deptno
, 30 , 'Sales'
, 'All others' -- Default value
) AS dname
FROM scott.emp
ORDER BY ename
;Output:
ENAME DEPTNO DNAME
ADAMS 20 All others
ALLEN 30 Sales
BLAKE 30 Sales
CLARK 10 All others
FORD 20 All others
JAMES 30 Sales
JONES 20 All others
KING 10 All others
MARTIN 30 Sales
MILLER 10 All others
SCOTT 20 All others
SMITH 20 All others
TURNER 30 Sales
WARD 30 Sales
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
If you can show the problem using commonly available tables (such as those in the scott schema) then you don't need to post any sample data; just the results and the explanation.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
Hello!!
Can anyone please help me with the decode statement
Table 1 Table2 Table3
Id Id Code
Volume Code
For each of the codes in Table3 I need to find the corresponding Volume. Can I use decode in the select statement to this,
Eg Code Volume
ABC 20
XYZ 10 etc etc.
Thankyou all in advance.Your table structure is a little unclear from your post. I am assuming that what you posted was:
Table 1
Id
Table2
Id
Code
Table3
Volume
Code You can use decode if there are only a few values for table3. For example,
SELECT table2.code,
DECODE(table2.code,'ABC',10,'XYZ',20,'UNKNOWN') volume
FROM table2
or even
SELECT code,DECODE(code,null,'NONE',
(SELECT volume FROM table3 where code=table2.code)) volume
FROM table2However, the first will break, or at least be incorrect, if anyone adds a new code/volume pair, and is tedious if you have more than a few values. The second will likely be pretty slow if there are a large number of records in table3. The best solution would be to use a simple join rather than decode. Something like:
SELECT table1.id, table2.code, table3.volume
FROM table1, table2, table3
WHERE table1.id = table2.id and
table2.code = table3.code -
How to convert rows into columns with decode function
Hi,
How to convert rows into columns with the help of decode function in oracle.
thanks and regards
P Prakashsay
col1 col2
1 10
2 20
3 30
then use
select col1,
sum(decode(col2,10,10)) "new1"
sum(decode(col2,20,20))"new2"
sum(decode(col2,30,30))"new3"
from table_name
group by col1;
we used sum u can use ny function if wont u have to give the column name i.e col2 name also
so i think u got it nw
regards -
I need help in decode function.
I have a scenario like if range is between 0 and 20 then display field,
if range is >20 and <40 then display field2,
if range is > 40 and <60 the display field 3
Can i do in decode ?Hi,
If you have to ask how to use DECODE, the answer is "Use CASE instead."
CASE
WHEN range_val BETWEEN 0
AND 20 THEN field
WHEN range_val BETWEEN 20
AND 40 THEN field2
WHEN range_val BETWEEN 40
AND 60 THEN field3
END "Range" is an Oracle keyword, so it's not a good idea to use it as a column name.
What do you want ot do if range_val is exactly 20 or 40?
The example above includes 20 in the 0-20 group, not the 20-40 group. That's because the WHEN clauses are evaluated in order. The condition "range_val BETWEEN 20 AND 40" would return TRUE for range_val=20, but that condition will only be evaluated if the earlier condition "range_val BETWEEN 0 AND 20" is not TRUE.
You can do this just using DECODE. The general way to check for ranges is to use the SIGN function to isolate one range, and a nested DECODE to test for the others. If the values are equally spaced, as in this example, you can get by with just FLOOR, or something similar.
Unless you're using Oracle 8.0 (or earlier) there is no reason to do this. -
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;". -
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
MThanks 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; -
SQL Loader : Trim and Decode functions help please
Hi,
I have to load data from a flat file, for some columns i need to use TRIM and DECODE functions.It is a pipe delimited file.
I get syntax errors (one is below) same error listed for TRIM.
SQL*Loader-350: Syntax error at line xx.
Expecting "," or ")", found "DECODE".
===========
,FINAL_BILL_DATE CHAR(30) "TRIM(:FINAL_BILL_DATE)"
,BUSINESS_ID "DECODE(:BUSINESS_ID,'B',1,'C',2,'E',3,'G',4,'O',5,'R',6,'T',7,'U',8,'H',9,-1)"
Can anyone please help.
Thanks
CherrishHello Cherrish.
The error you are receiving leads me to believe that at some point prior to the DECODE on the line for BUSINESS_ID, probably some line even before the FINAL_BILL_DATE line, there a syntactical error causing the quotes before the DECODE to actually terminate some other syntax. Without all of the lines that could actually contribute to this, including the header details, this is the best I can advise.
Hope this helps,
Luke
Please mark the answer as helpful or answered if it is so. If not, provide additional details.
Always try to provide create table and insert table statements to help the forum members help you better. -
Wat is wrong in this decode function, it doesn get executed,please help me
wat is wrong in this decode function, it doesn get executed,please help me
decode(DVI.COMPANY||'.')||
DECODE(DVI.COST_CENTRE||'.')||
DECODE(DVI.ACCOUNT||'.')||
DECODE(DVI.LOCATION||'.')||
DECODE(DVI.PRODUCT||'.')||
DECODE(DVI.FUTURE)company_id,Hi,
I could not understand what you are trying to do with decode here.
The standard way of using the decode is like :
SQL>SELECT DECODE (1 , 1 ,'TRUE','FALSE') FROM DUAL;
DECO
TRUE
1 row selected.
1* SELECT DECODE (1 , 0 ,'TRUE','FALSE') FROM DUAL
SQL>/
DECOD
FALSE
1 row selected.
Please explain what you want to do with DECODE ?
Regards -
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. -
Error while replacing IF statements with DECODE function in procedure
Hi All,
I have created a procedure which has nested IF statements. Now I want to replace the IF statements with DECODE functions to improve performance.
Procedure:
IF (var_int_sev = '0')
THEN
var_sev := '2';
ELSE
SELECT sev
INTO var_int_sev
FROM errorconfig
WHERE errorcode = var_errorcode;
var_sev := var_int_sev;
END IF;
I converted the above IF statement into DECODE function as mentioned below:
var_Sev := DECODE(var_int_sev,0,2,SELECT severity FROM errorconfig WHERE errorcode=var_ErrorCode)
But it throws below error at the select statement used inside DECODE.
Error(58,51): PLS-00103: Encountered the symbol "SELECT" when expecting one of the following: ( - + case mod new not null others <an identifier> <a double-quoted delimited-identifier> <a bind variable> avg count current exists max min prior sql stddev sum variance execute forall merge time timestamp interval date <a string literal with character set specification> <a number> <a single-quoted SQL string> pipe <an alternatively-quoted string literal with character set specification> <an alternativ
Can someone help me in converting the IF to DECODE in the above case. Also how can we use a select statement inside decode.instead of trying to rewrite all your code and hoping that the performance will be better, it's a better option to investigate and find out which part of your application is slow
read this:
When your query takes too long ... -
Converting Decode function in OBIEE
Hi Guru's
we are converting some BO reports to OBIEE and need to convert Decode function
Below is the Decode function they are using:
Decode ( sign(nvl(BOOKINGS_DATA_UDTC.qty_shipped,0)), 0,decode(BOOKINGS_DATA_UDTC.DELIVERY_NUMBER, 0,decode(BOOKINGS_DATA_UDTC.Schd_Ship_date_fk,to_date('1/1/1990','mm/dd/yyyy'),'Next Month Backlog',decode(sign(nvl(BOOKINGS_DATA_UDTC.Schd_Ship_date_fk, '01-JAN-90') -PAR.PAR_DATE), 1, 'Next Month Backlog', 'Current month will ship')) ,'Awaiting for collection') ,'MTD Shipped')
i have tried converting into case :
case when sign(IFNULL("BOOKINGS_DATA_UDTC"."Qty Shipped",0)) = 0 then (case when "BOOKINGS_DATA_UDTC"."Delivery Number" = 0 then (case when "BOOKINGS_DATA_UDTC"."SCHD_SHIP_DATE_FK" = '01-JAN-1990' then 'Next Month Backlog' else (case when Timestampdiff(SQL_TSI_DAY, cast('@{ParDate}{28-DEC-2012}' as Date),(case when "BOOKINGS_DATA_UDTC"."SCHD_SHIP_DATE_FK" IS NULL then CAst('01-JAN-1990' as DATE) else "BOOKINGS_DATA_UDTC"."SCHD_SHIP_DATE_FK" end)) > 1 then 'Next Month Backlog' else 'Current Month Will Ship' end) end) else 'Awaiting For Collection' end) else 'MTD Shipped' end
But it is not workign as expected.
Can some one please help me with this.
Thanks,you can achieve it by using CASE WHEN condition END function in obiee. nested case also supported by obiee.
check the below link Decode Join Condition in OBIEE RPD
Thanks
Jay.
Edited by: Jay on Apr 3, 2012 12:56 PM -
Decode function in OracleXMLQuery
selectStr = "SELECT DECODE(email,null,'',email), FROM mytable WHERE user_id=\'" + search_id + "\'";
using this select statement in conjunction with OracleXMLQuery produces the following exception.
oracle.xml.sql.OracleXMLSQLException: Character ')' is not allowed in an XML tag name.
any hints why ')' ist not supported?
nullsolved, renaming the decode function helps
like
selectStr = "SELECT DECODE(email,null,'',email) email, FROM mytable WHERE user_id=\'" + search_id + "\'";
null -
Decode function in Update statement
Hello everyone,
I'm trying to write a query where I can update a pastdue_fees column in a book_trans table based on a difference between return_dte and due_dte columns.
I am using Oracle SQL. This is what I have so far for my decode function:
SQL> SELECT
2 DECODE(SIGN((return_dte - due_dte)*2),
3 '-1', '0',
4 '1', '12', 'Null')
5 FROM book_trans;
DECO
Null
12
Null
0
So the logic is that if the sign is -1, the value in return_dte column should be 0; if it's +1 then it's 12 and everything else is Null.
So now, I need to enter my decode function into the update statement to update the columns. However, I get error messages.
The logic should be:
UPDATE book_trans SET PastDue_fees = decode(expression)
I've given it a couple of different tries with the following results:
SQL> UPDATE book_trans
2 SET pastdue_fees = SELECT
3 DECODE(SIGN((return_dte - due_dte)*2),
4 '-1', '0',
5 '1', '12', 'Null')
6 FROM book_trans;
SET pastdue_fees = SELECT
ERROR at line 2:
ORA-00936: missing expression
SQL> UPDATE book_trans
2 SET pastdue_fees =
3 DECODE(SIGN((return_dte - due_dte)*2),
4 '-1', '0',
5 '1', '12', 'Null')
6 FROM book_trans;
FROM book_trans
ERROR at line 6:
ORA-00933: SQL command not properly ended
Any help or tips would be greatly appreciated as I've been taking SQL for about six weeks and not very proficient!
Thanks!882300 wrote:
Hello everyone,
I'm trying to write a query where I can update a pastdue_fees column in a book_trans table based on a difference between return_dte and due_dte columns.
I am using Oracle SQL. This is what I have so far for my decode function:
SQL> SELECT
2 DECODE(SIGN((return_dte - due_dte)*2),
3 '-1', '0',
4 '1', '12', 'Null')
5 FROM book_trans;
DECO
Null
12
Null
0
So the logic is that if the sign is -1, the value in return_dte column should be 0; if it's +1 then it's 12 and everything else is Null.
So now, I need to enter my decode function into the update statement to update the columns. However, I get error messages.
The logic should be:
UPDATE book_trans SET PastDue_fees = decode(expression)
I've given it a couple of different tries with the following results:
SQL> UPDATE book_trans
2 SET pastdue_fees = SELECT
3 DECODE(SIGN((return_dte - due_dte)*2),
4 '-1', '0',
5 '1', '12', 'Null')
6 FROM book_trans;
SET pastdue_fees = SELECT
ERROR at line 2:
ORA-00936: missing expression
SQL> UPDATE book_trans
2 SET pastdue_fees =
3 DECODE(SIGN((return_dte - due_dte)*2),
4 '-1', '0',
5 '1', '12', 'Null')
6 FROM book_trans;
FROM book_trans
ERROR at line 6:
ORA-00933: SQL command not properly ended
Any help or tips would be greatly appreciated as I've been taking SQL for about six weeks and not very proficient!
Thanks!If you really really really want to update the entire table, the syntax would be...
UPDATE book_trans
SET
pastdue_fees = DECODE(SIGN((return_dte - due_dte)*2), -1, 0, 1, 12, Null);I took out all the single quotes. If you actually have a string column and you're storing entirely numbers in it then it should be declared as a NUMBER column and not a character (varchar2) column.
ALWAYS use the proper data type, it'll save you a ton of headaches in the future.
Also, since you're new to the forum, please read the FAQ so you learn the etiquette and what not.
http://wikis.sun.com/display/Forums/Forums+FAQ
Maybe you are looking for
-
Actually we use Application Server 10g (version 10.1.2.3.0) for different Forms 10g Applications (roundabout 1000 Forms) and want to change to Forms 11g and Weblogic Server 11g (version 10.3.6.0). A Test-Application on the Weblogic Server works fine,
-
HP Officejet Pro 8500A Premium will not print docs from computer, but will print a test page. I continually get a message that the computer cannot communicate with the printer. Not only will it not print docs, it will not print web pages using IE
-
PDF Document Display Issue - iPad Mini iOS 8.1
I use my iPad heavily doing in-home sales. I rely on a combination of Box, PDF Expert, and Notability to retrieve and create information/documents. After updating my iPad Mini to iOS 8, I started having a display issue when trying to pull up my price
-
hi experts , i need a logic i have a internal table itab_equi in that i am getting 11 values when i pass this internal table to another table using for all entries i will get 4 values in int_bmgkobj . i need logic for how to get the deleted values i
-
Tried to install the newest version and lost all itunes on this computer. Followed instructions about removing and reinstalling iTunes, Quicktime, etc. Now I get message "Could not open key: UNKNOWN\Components|" and several letters/numbers afterward.