SQL Query With Like Operator - Performance is very poor - Oracle Apps Table
Hi,
I'm querying one of the Oracle Applications Standard Table. The performance is very slow when like operator is used in the query condition. The query uses a indexed column in the where clause.
The query is..
select * from hz_parties
where upper(party_name) like '%TOY%'
In the above case, It is not using the index and doing full table scan. I have checked the explain plan and the cost is 4496.
select * from hz_parties
where upper(party_name) like 'TOY%'
If I remove the '%' at the begining of the string, the performance is good and it is using the index. In this case, the cost is 5.
Any ideas to improve the performance of the above query. I have to retrieve the records whose name contains the string. I have tried hints to force the use of index. But it is of no use.
Thanks,
Rama
If new indexes are disallowed, not a lot of good ones, no.
If you know what keyword(s) are going to be searched for, a materialized view might help, but I assume that you're searching based on user input. In that case, you'd have to essentially build your own Text index using materialized views, which will almost certainly be less efficient and require more maintenance than the built-in functionality.
There may not be much you could do to affect the query plan in a reasonable way. Depending on the size of the table, how much RAM you're willing to throw at the problem, how your system is administered, and what Oracle Apps requires/ prohibits in terms of database configuration, you might be able to force Oracle to cache this table so that your full table scans are at least more efficient.
Justin
Similar Messages
-
How to pass variable into lov sql query using like operator
hi.
i want to use a lov where i want to pass a variable using like operator.
my query is
select empno,name from table where empno like ':ed%';
my empno is A001 TO A199 AND B001 TO B199 so i want show either A% or B% empno
how can i do this ?
reagrdskindly press Shift+F1 at a time you face this error to see the exact Oracle error message.
and provide us with that detail
and its better if you start new topic for that error... because that will be new error,,,
-- Aamir Arif
Edited by: Aamiz on Apr 7, 2010 12:27 PM -
MAKING A SQL QUERY WITH LIKE SINTAX
Im trying to make a string with a sql query.
the object is return a select statement in the var string and the select statement must be return a string like that :
select item1, item2, item3 from table where
item1 like '%PEPE%' and item2 like '%COSA2%';
then I make a string like that :
lq_sql := 'select item1, item2, item3 from table where item1 like '||'%'||:P1_NOMBRE||'%'
but this give errors.
Any help? thanks in advanced and regards everybody.Hello,
If you check your statement in sql*plus this is how it will look like:
select 'select item1, item2, item3 from table where item1 like '||'%'||&P1_NOMBRE||'%' txt
from dual
Enter value for p1_nombre: 3
result:
TXT
select item1, item2, item3 from table where item1 like %3%
***You are missing single quotes before and after the % statement, as follows:
select 'select item1, item2, item3 from table where item1 like '||'''%'||&P1_NOMBRE||'%''' txt
from dual
Enter value for p1_nombre: 3
result:
TXT
select item1, item2, item3 from table where item1 like '%3%'BTW, i changed colon (:) to ampersand (&) to run it in SQL*plus but it should be a colon.
-Marilyn -
Need sql query for like operation.
Hi All,
i have table like name column and contain the data like
ibm 100
ibm 200
ibm 300
a2b
a
b
c
like this ....
but sql query need search using like or any regular expression---
select * from table where name like (ibm 200 and ibm 300).
and i don't want use like this select * from table where name like' ibm 200' or name like 'ibm 300').
can you please any body help to correct the above query...
Edited by: anbarasan on Oct 16, 2011 10:02 PMWITH t AS
(SELECT 'ibm 100' NAME
FROM DUAL
UNION ALL
SELECT 'ibm 200' NAME
FROM DUAL
UNION ALL
SELECT 'ibm 300' NAME
FROM DUAL
UNION ALL
SELECT 'a2b' NAME
FROM DUAL)
SELECT *from t where REGEXP_LIKE (name, 'ibm')
and REGEXP_LIKE (name, '100|200') -
Hi,
Its amazing i could not able to understand that the results returned from my query
Here is my query,
SELECT * FROM TABLE1,TABLE2 WHRE TABLE1.ID = TABLE2.TABLE1_ID AND TABLE1.ID IN (5,4);
This query returns the records of Id 4 first and then for the Id 5.
I do no what happens, i need to use IN Operator in my Select query and i want to get the datas of the Id
as per the Order I give
How can i get the solutionBut in the query i can give any number of values like (7,2,1,4,8,..n)You can use global temporary table or collection to specify the order of
numbers. In this case you have to use the join instead of IN:
SQL> create global temporary table pos_tab (id number, position number);
Table created.
SQL> create table t_test as select rownum col from dict where rownum <=10;
Table created.
SQL> begin
2 insert into pos_tab values(7,1);
3 insert into pos_tab values(5,2);
4 insert into pos_tab values(9,3);
5 end;
6 /
PL/SQL procedure successfully completed.
SQL> select t_test.col from t_test, pos_tab where t_test.col = pos_tab.id
2 order by pos_tab.position;
COL
7
5
9Simple collection example:
SQL> create type pos_obj is object(id number, pos number);
2 /
Type created.
SQL> create type pos_t is table of pos_obj;
2 /
Type created.
SQL> select col from t_test, table(pos_t(pos_obj(7,1),pos_obj(5,2),pos_obj(9,3))) pos
2 where pos.id = t_test.col order by pos.pos
3 /
COL
7
5
9Rgds.
Consider - IN-list operators are limited by 1000 explicit elements.
Message was edited by:
dnikiforov -
Sql query using LIKE is very slow
Hi,
I am running SQL query with LIKE on two table with more than two million records on oracle 10g and sun solaris OS. Does anybody have any idea or alternative to improve this query?
it will never use index because i m using LIKE '%xyz%'. I Have posted query below
PROCEDURE order_search
v_search_type_in IN VARCHAR2
,v_search_value1_in IN VARCHAR2 DEFAULT 'NONE'
,v_search_value2_in IN VARCHAR2 DEFAULT 'NONE'
,v_group_id_in IN bcf_groups.group_id%TYPE DEFAULT 0
,v_open_in IN NUMBER DEFAULT 0
,v_requested_in IN NUMBER DEFAULT 0
,v_cancelled_in IN NUMBER DEFAULT 0
,v_closed_in IN NUMBER DEFAULT 0
,v_employee_id_in IN sxweb00.customer.customer_id%TYPE DEFAULT 0
,outcursor IN OUT FulfillmentCurType
IS
v_status_code NUMBER;
v_upper_search_value1 VARCHAR2(500);
v_lower_search_value1 VARCHAR2(500);
v_open_status VARCHAR2(10);
v_closed_status VARCHAR2(10);
v_cancelled_status VARCHAR2(10);
v_requested_status VARCHAR2(10);
v_group_for_search bcf_groups.group_id%TYPE;
v_sql_select VARCHAR2(4000);
v_sql_from VARCHAR2(4000);
v_sql_where VARCHAR2(4000);
v_sql_order_by VARCHAR2(4000);
v_group_where VARCHAR2(100);
v_status_where VARCHAR2(500);
BEGIN
IF v_open_in = 1 THEN
v_open_status := 'OPEN';
END IF;
IF v_closed_in = 1 THEN
v_closed_status := 'CLOSED';
END IF;
IF v_cancelled_in = 1 THEN
v_cancelled_status := 'CANCELLED';
END IF;
IF v_requested_in = 1 THEN
v_requested_status := 'REQUESTED';
END IF;
IF UPPER(v_search_type_in) = 'GROUP'
THEN
v_group_for_search := v_search_value1_in;
ELSE
v_group_for_search := v_group_id_in;
END IF;
-- This is the select statement used for all search types
v_sql_select := ' '
|| 'po.order_id order_id '
|| ',decode('||v_group_id_in||',4,substr(bcf_locator.get_first_location(po.order_id,'||v_group_id_in||'),3),null) first_location '
|| ',TO_CHAR(po.order_date, ''mm/dd/yyyy'') order_date '
|| ',' || v_group_for_search || ' group_id '
|| ',TRIM(TO_CHAR(bcf_fulfillment.get_shipping_total(po.order_id,' || v_group_for_search || ') + bcf_fulfillment.get_tax_total(po.order_id,' || v_group_for_search || ') + bcf_fulfillment.get_subtotal(po.order_id,' || v_group_for_search || ') ,''$999,999,999,999,999,990.99'')) total '
|| ',bcf_fulfillment.get_billing_name (po.customer_id) billing_name '
|| ',bcf_fulfillment.get_open_and_assigned_count(po.order_id,' || v_group_for_search || ') open_and_assigned_count '
|| ',bcf_fulfillment.get_divisions(po.order_id,' || v_group_for_search || ') divisions '
|| ',bcf_fulfillment.get_division_count (po.order_id,' || v_group_for_search || ' ) division_count '
|| ',bcf_fulfillment.get_picker_list (po.order_id,' || v_group_for_search || ') picker_name '
|| ',bcf_fulfillment.get_picker_count (po.order_id,' || v_group_for_search || ') picker_count '
|| ',bcf_fulfillment.get_order_status(po.order_id,' || v_group_for_search || ') order_status '
|| ',po.customer_id customer_id '
-- IF there is only one unique picker then that means there are no unassigned or NULL pickers
-- therefore by default the checkbox should not be selected else the count picker_count is
-- 0 or > 1 meaning that at least one line item has an unassigned employee_id and by default
-- the checkbox should be selected
|| ',DECODE(bcf_fulfillment.get_picker_count(po.order_id,' || v_group_for_search || '),1 ,0,1) print_cb '
|| ',bcf_fulfillment.get_fulfillment_codes(po.order_id,' || v_group_for_search || ') fulfillment_types '
|| ',bcf_fulfillment.has_group_been_reassigned(po.order_id,' || v_group_for_search || ') group_reassigned_flag '
|| ',bcf_fulfillment.get_chain_codes(po.order_id,' || v_group_for_search || ') chain_codes '
|| ',po.status_id order_status_id '
|| ',bcf_fulfillment.get_viewed_by_picker_flag(po.order_id,' || v_group_for_search || ') viewed_by_picker_flag '
|| ',bcf_fulfillment.get_picker_list (po.order_id,' || v_group_for_search || ', ''N'') pickers_without_unassigned '
|| ',bcf_fulfillment.get_group_list (po.order_id) group_list '
|| ',bcf_fulfillment.get_line_item_count(po.order_id,' || v_group_for_search || ') line_item_count '
|| ',bcf_fulfillment.get_shipping_priority(po.order_id,' || v_group_for_search || ') shipping_priority'
-- Anna wants all users to know and always wants to know no matter what the status of the auth or order
|| ',(SELECT decode(count(*),0,''N'',''Y'') FROM bcf_payment WHERE ics_rflag = ''DAVSNO'' AND order_id = po.order_id AND status_code IN (''ATH2'',''FUL2'',''CPT0'',''CPT2'')) avs_failed'
|| ',trunc(po.order_date) date_for_sort'
-- When we need to look at all orders then the v_group_for_search will be zero i.e. customer service rep
IF v_group_for_search = 0 THEN
-- This is the core tables used by most search types
v_sql_from := ' '
|| 'FROM product_order po'
-- || ',bcf_lookup lu'
-- This is the core table join needed for most search types
v_sql_where := ' '
|| 'WHERE 1 = 1 '
-- No orders will be looked at for fulfillment purposes that occurred before the minimum
-- shipping cost functionality was added
-- || 'AND po.order_date >= lu.implement_date '
|| 'AND po.order_date >= (SELECT min(implement_date) FROM bcf_lookup) '
|| 'AND po.submitted_flag = 1 '
|| 'AND po.channel_code = ''BCF'' '
-- When we are looking at all orders then we are not going to restrict it by group
v_group_where := ' ';
-- This is used where the search type requires searching by the Open, Closed, and Cancelled status.
-- We are binding the three status variables so that they can be cached in Oracle and not need to be parsed after
-- the first search of a search type is done.
v_status_where := ' '
|| 'AND bcf_fulfillment.get_order_status(po.order_id,' || v_group_for_search|| ') '
|| 'IN (:v_open_status, :v_requested_status, :v_cancelled_status, :v_closed_status) '
ELSE
-- This is the core tables used by most search types
v_sql_from := ' '
|| 'FROM product_order po'
|| ',bcf_product_order_groups pog '
-- This is the core table join needed for most search types
v_sql_where := ' '
|| 'WHERE 1 = 1 '
|| 'AND po.order_id = pog.order_id '
|| 'AND po.channel_code = ''BCF'' '
-- This is used only where the search type requires searching by a group.
v_group_where := ' '
|| 'AND pog.group_id = ' || v_group_for_search
-- This is used where the search type requires searching by the Open, Closed, and Cancelled status.
-- We are binding the three status variables so that they can be cached in Oracle and not need to be parsed after
-- the first search of a search type is done.
v_status_where := ' '
|| 'AND pog.dn_status IN (:v_open_status, :v_requested_status, :v_cancelled_status, :v_closed_status) '
END IF;
-- If an employee_id is provided then we need to add in a where clause so that only orders that belong to that
-- employee are pulled
IF v_employee_id_in > 0
THEN
v_sql_where := v_sql_where
|| 'AND pog.dn_employee_id = ' || TO_CHAR(v_employee_id_in) || ' '
END IF;
IF v_group_id_in = get_group_fulfillment_center1
THEN
v_sql_order_by := 'ORDER BY '
|| 'bcf_fulfillment.get_division_count (po.order_id,' || v_group_for_search || ') '
|| ',bcf_fulfillment.get_divisions(po.order_id,' || v_group_for_search || ') '
|| ',po.order_id '
ELSIF v_group_id_in = c_GROUP_FULFILLMENT_CENTER_212
THEN
v_sql_order_by := 'ORDER BY '
|| 'bcf_fulfillment.get_shipping_priority(po.order_id,' || v_group_for_search || ') DESC'
|| ',TRUNC(po.order_date)'
|| ',bcf_fulfillment.get_line_item_count(po.order_id,' || v_group_for_search || ')'
|| ',decode('||v_group_id_in||',4,substr(bcf_locator.get_first_location(po.order_id,'||v_group_id_in||'),3),null)'
|| ',po.order_id'
ELSE
v_sql_order_by := 'ORDER BY '
|| ' bcf_fulfillment.get_shipping_priority(po.order_id,' || v_group_for_search || ') DESC'
|| ',chain_codes DESC'
|| ',po.order_id '
END IF;
IF UPPER(v_search_type_in) = 'ORDERNUMBER'
THEN
v_sql_where := v_sql_where || v_group_where
|| 'AND po.order_id = :v_search_value1_in '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where
USING v_search_value1_in;
ELSIF UPPER(v_search_type_in) = 'STATUSONLY'
THEN
v_sql_where := v_sql_where || v_group_where || v_status_where
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status;
ELSIF UPPER(v_search_type_in) = 'BILLINGNAME'
THEN
v_upper_search_value1 := UPPER(v_search_value1_in);
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.upper_billing_name LIKE ''%'' || :v_upper_search_value1 || ''%'' '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_upper_search_value1;
ELSIF UPPER(v_search_type_in) = 'GROUP'
THEN
IF v_search_value1_in = '0' -- Unassigned
THEN
v_sql_from := v_sql_from || ' ,product_order_detail_actv_v pod ';
v_sql_where := v_sql_where || ' ' || v_status_where
|| 'AND po.order_id = pod.order_id '
|| 'AND pod.group_id IS NULL '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT DISTINCT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status;
ELSE
v_sql_where := v_sql_where || ' ' || v_status_where
|| 'AND pog.group_id = :v_group_for_search '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status, v_group_for_search;
END IF;
ELSIF UPPER(v_search_type_in) = 'SHIPPINGNAME'
THEN
v_upper_search_value1 := UPPER(v_search_value1_in);
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.upper_shipping_name LIKE ''%'' || :v_upper_search_value1 || ''%'' '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_upper_search_value1;
ELSIF UPPER(v_search_type_in) = 'USERNAME'
THEN
v_lower_search_value1 := LOWER(v_search_value1_in);
v_sql_from := v_sql_from || ' ,sxweb01.customer c ';
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.customer_id = c.customer_id '
|| 'AND c.username LIKE ''%'' || :v_lower_search_value1 || ''%'' '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_lower_search_value1;
ELSIF UPPER(v_search_type_in) = 'BILLINGADDRESS1'
THEN
v_upper_search_value1 := UPPER(v_search_value1_in);
v_sql_from := v_sql_from || ' ,order_payment op '
|| ' ,credit_card cc '
|| ' ,om_address oma '
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.order_id = op.business_object_id '
|| 'AND op.business_object_type = ''ORDR'' '
|| 'AND op.payment_method = ''CRCD'' '
|| 'AND op.payment_method_id = cc.credit_card_id '
|| 'AND cc.address_id = oma.address_id '
|| 'AND UPPER(oma.address1) LIKE ''%'' || :v_upper_search_value1 || ''%'' '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_upper_search_value1;
ELSIF UPPER(v_search_type_in) = 'SHIPPINGADDRESS1'
THEN
v_upper_search_value1 := UPPER(v_search_value1_in);
v_sql_from := v_sql_from || ' ,shipping_info si '
|| ' ,om_address oma '
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.order_id = si.order_id '
|| 'AND si.ship_to_address_id = oma.address_id '
|| 'AND UPPER(oma.address1) LIKE ''%'' || :v_upper_search_value1 || ''%'' '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_upper_search_value1;
ELSIF UPPER(v_search_type_in) = 'BILLINGPHONE'
THEN
v_sql_from := v_sql_from || ' ,order_payment op '
|| ' ,credit_card cc '
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.order_id = op.business_object_id '
|| 'AND op.business_object_type = ''ORDR'' '
|| 'AND op.payment_method = ''CRCD'' '
|| 'AND op.payment_method_id = cc.credit_card_id '
|| 'AND cc.home_phone = :v_search_value1_in '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_search_value1_in;
ELSIF UPPER(v_search_type_in) = 'SHIPPINGPHONE'
THEN
v_sql_from := v_sql_from || ' ,shipping_info si '
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.order_id = si.order_id '
|| 'AND si.ship_phone = :v_search_value1_in '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_search_value1_in;
ELSIF UPPER(v_search_type_in) = 'CREDITCARDNUMBER'
THEN
v_sql_from := v_sql_from || ' ,order_payment op '
|| ' ,credit_card cc '
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.order_id = op.business_object_id '
|| 'AND op.business_object_type = ''ORDR'' '
|| 'AND op.payment_method = ''CRCD'' '
|| 'AND op.payment_method_id = cc.credit_card_id '
|| 'AND cc.credit_card_number = :v_search_value1_in '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_search_value1_in;
ELSIF UPPER(v_search_type_in) = 'PONUMBER'
THEN
v_sql_from := ' '
|| 'FROM ' || ' product_order_detail_actv_v pod ,' || SUBSTR(v_sql_from, 6);
v_sql_where := v_sql_where || v_group_where
|| 'AND pod.po_no = :v_search_value1_in '
|| 'AND po.order_id = pod.order_id '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT /*+ ORDERED */ DISTINCT ' || v_sql_select || v_sql_from || v_sql_where
USING v_search_value1_in;
ELSIF UPPER(v_search_type_in) = 'USERASSIGNED'
THEN
IF v_search_value1_in = '0' -- 'Unassigned'
THEN
v_sql_where := v_sql_where || ' ' || v_group_where || ' ' || v_status_where
|| 'AND pog.unassigned_flag = ''Y'' '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status;
ELSE
v_sql_where := v_sql_where || ' ' || v_group_where || ' ' || v_status_where
|| 'AND pog.dn_employee_id = :v_search_value1_in '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status, v_search_value1_in;
END IF;
ELSIF UPPER(v_search_type_in) = 'ORDERDATE'
THEN
v_sql_where := v_sql_where || ' ' || v_group_where || ' ' || v_status_where
|| 'AND po.order_date BETWEEN TO_DATE( :v_search_value1_in, ''MON DD YYYY HH24:MI:SS'') AND TO_DATE( :v_search_value2_in ,''MON DD YYYY HH24:MI:SS'') '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status, v_search_value1_in, v_search_value2_in;
ELSIF UPPER(v_search_type_in) = 'PRINTJOB'
THEN
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select
|| ' '
|| 'FROM product_order po '
|| ' ,bcf_print_jobs pj '
|| 'WHERE 1 = 1 '
|| 'AND pj.order_id = po.order_id '
|| 'AND pj.username = :v_search_value1_in '
|| 'AND pj.create_date = TO_DATE( :v_search_value2_in,''MON DD YYYY HH24:MI:SS'') '
|| v_sql_order_by
USING v_search_value1_in, v_search_value2_in;
ELSIF UPPER(v_search_type_in) = 'FULFILLMENTTYPE'
THEN
v_sql_from := v_sql_from || ' ,product_order_detail_actv_v pod ';
v_sql_where := v_sql_where || ' ' || v_group_where || ' ' || v_status_where
|| 'AND pod.order_id = po.order_id '
-- Because we have to drill down the the POD level
-- we now need to ensure the pod records match on group
|| 'AND pod.group_id = ' || v_group_for_search
-- We curr. have 3 fufillment types FC165, FC212, FCBABY
-- so substr on 1st char works for Garry
|| 'AND UPPER(SUBSTR(pod.fulfillment_type,1,1)) = UPPER(:v_search_value1_in) '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT DISTINCT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status, v_search_value1_in;
ELSIF UPPER(v_search_type_in) = 'INSUFFICIENTAUTHORIZATION'
THEN
v_sql_where := v_sql_where
|| 'AND bcf_get_authorization_amount(po.order_id) > 0'
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by;
END IF;
END order_search;
Thanks
V
Edited by: vishal patel on Oct 23, 2008 3:59 PMPROCEDURE order_search
v_search_type_in IN VARCHAR2
,v_search_value1_in IN VARCHAR2 DEFAULT 'NONE'
,v_search_value2_in IN VARCHAR2 DEFAULT 'NONE'
,v_group_id_in IN bcf_groups.group_id%TYPE DEFAULT 0
,v_open_in IN NUMBER DEFAULT 0
,v_requested_in IN NUMBER DEFAULT 0
,v_cancelled_in IN NUMBER DEFAULT 0
,v_closed_in IN NUMBER DEFAULT 0
,v_employee_id_in IN sxweb00.customer.customer_id%TYPE DEFAULT 0
,outcursor IN OUT FulfillmentCurType
IS
v_status_code NUMBER;
v_upper_search_value1 VARCHAR2(500);
v_lower_search_value1 VARCHAR2(500);
v_open_status VARCHAR2(10);
v_closed_status VARCHAR2(10);
v_cancelled_status VARCHAR2(10);
v_requested_status VARCHAR2(10);
v_group_for_search bcf_groups.group_id%TYPE;
v_sql_select VARCHAR2(4000);
v_sql_from VARCHAR2(4000);
v_sql_where VARCHAR2(4000);
v_sql_order_by VARCHAR2(4000);
v_group_where VARCHAR2(100);
v_status_where VARCHAR2(500);
BEGIN
IF v_open_in = 1 THEN
v_open_status := 'OPEN';
END IF;
IF v_closed_in = 1 THEN
v_closed_status := 'CLOSED';
END IF;
IF v_cancelled_in = 1 THEN
v_cancelled_status := 'CANCELLED';
END IF;
IF v_requested_in = 1 THEN
v_requested_status := 'REQUESTED';
END IF;
IF UPPER(v_search_type_in) = 'GROUP'
THEN
v_group_for_search := v_search_value1_in;
ELSE
v_group_for_search := v_group_id_in;
END IF;
-- This is the select statement used for all search types
v_sql_select := ' '
|| 'po.order_id order_id '
|| ',decode('||v_group_id_in||',4,substr(bcf_locator.get_first_location(po.order_id,'||v_group_id_in||'),3),null) first_location '
|| ',TO_CHAR(po.order_date, ''mm/dd/yyyy'') order_date '
|| ',' || v_group_for_search || ' group_id '
|| ',TRIM(TO_CHAR(bcf_fulfillment.get_shipping_total(po.order_id,' || v_group_for_search || ') + bcf_fulfillment.get_tax_total(po.order_id,' || v_group_for_search || ') + bcf_fulfillment.get_subtotal(po.order_id,' || v_group_for_search || ') ,''$999,999,999,999,999,990.99'')) total '
|| ',bcf_fulfillment.get_billing_name (po.customer_id) billing_name '
|| ',bcf_fulfillment.get_open_and_assigned_count(po.order_id,' || v_group_for_search || ') open_and_assigned_count '
|| ',bcf_fulfillment.get_divisions(po.order_id,' || v_group_for_search || ') divisions '
|| ',bcf_fulfillment.get_division_count (po.order_id,' || v_group_for_search || ' ) division_count '
|| ',bcf_fulfillment.get_picker_list (po.order_id,' || v_group_for_search || ') picker_name '
|| ',bcf_fulfillment.get_picker_count (po.order_id,' || v_group_for_search || ') picker_count '
|| ',bcf_fulfillment.get_order_status(po.order_id,' || v_group_for_search || ') order_status '
|| ',po.customer_id customer_id '
-- IF there is only one unique picker then that means there are no unassigned or NULL pickers
-- therefore by default the checkbox should not be selected else the count picker_count is
-- 0 or > 1 meaning that at least one line item has an unassigned employee_id and by default
-- the checkbox should be selected
|| ',DECODE(bcf_fulfillment.get_picker_count(po.order_id,' || v_group_for_search || '),1 ,0,1) print_cb '
|| ',bcf_fulfillment.get_fulfillment_codes(po.order_id,' || v_group_for_search || ') fulfillment_types '
|| ',bcf_fulfillment.has_group_been_reassigned(po.order_id,' || v_group_for_search || ') group_reassigned_flag '
|| ',bcf_fulfillment.get_chain_codes(po.order_id,' || v_group_for_search || ') chain_codes '
|| ',po.status_id order_status_id '
|| ',bcf_fulfillment.get_viewed_by_picker_flag(po.order_id,' || v_group_for_search || ') viewed_by_picker_flag '
|| ',bcf_fulfillment.get_picker_list (po.order_id,' || v_group_for_search || ', ''N'') pickers_without_unassigned '
|| ',bcf_fulfillment.get_group_list (po.order_id) group_list '
|| ',bcf_fulfillment.get_line_item_count(po.order_id,' || v_group_for_search || ') line_item_count '
|| ',bcf_fulfillment.get_shipping_priority(po.order_id,' || v_group_for_search || ') shipping_priority'
-- Anna wants all users to know and always wants to know no matter what the status of the auth or order
|| ',(SELECT decode(count(*),0,''N'',''Y'') FROM bcf_payment WHERE ics_rflag = ''DAVSNO'' AND order_id = po.order_id AND status_code IN (''ATH2'',''FUL2'',''CPT0'',''CPT2'')) avs_failed'
|| ',trunc(po.order_date) date_for_sort'
-- When we need to look at all orders then the v_group_for_search will be zero i.e. customer service rep
IF v_group_for_search = 0 THEN
-- This is the core tables used by most search types
v_sql_from := ' '
|| 'FROM product_order po'
-- || ',bcf_lookup lu'
-- This is the core table join needed for most search types
v_sql_where := ' '
|| 'WHERE 1 = 1 '
-- No orders will be looked at for fulfillment purposes that occurred before the minimum
-- shipping cost functionality was added
-- || 'AND po.order_date >= lu.implement_date '
|| 'AND po.order_date >= (SELECT min(implement_date) FROM bcf_lookup) '
|| 'AND po.submitted_flag = 1 '
|| 'AND po.channel_code = ''BCF'' '
-- When we are looking at all orders then we are not going to restrict it by group
v_group_where := ' ';
-- This is used where the search type requires searching by the Open, Closed, and Cancelled status.
-- We are binding the three status variables so that they can be cached in Oracle and not need to be parsed after
-- the first search of a search type is done.
v_status_where := ' '
|| 'AND bcf_fulfillment.get_order_status(po.order_id,' || v_group_for_search|| ') '
|| 'IN (:v_open_status, :v_requested_status, :v_cancelled_status, :v_closed_status) '
ELSE
-- This is the core tables used by most search types
v_sql_from := ' '
|| 'FROM product_order po'
|| ',bcf_product_order_groups pog '
-- This is the core table join needed for most search types
v_sql_where := ' '
|| 'WHERE 1 = 1 '
|| 'AND po.order_id = pog.order_id '
|| 'AND po.channel_code = ''BCF'' '
-- This is used only where the search type requires searching by a group.
v_group_where := ' '
|| 'AND pog.group_id = ' || v_group_for_search
-- This is used where the search type requires searching by the Open, Closed, and Cancelled status.
-- We are binding the three status variables so that they can be cached in Oracle and not need to be parsed after
-- the first search of a search type is done.
v_status_where := ' '
|| 'AND pog.dn_status IN (:v_open_status, :v_requested_status, :v_cancelled_status, :v_closed_status) '
END IF;
-- If an employee_id is provided then we need to add in a where clause so that only orders that belong to that
-- employee are pulled
IF v_employee_id_in > 0
THEN
v_sql_where := v_sql_where
|| 'AND pog.dn_employee_id = ' || TO_CHAR(v_employee_id_in) || ' '
END IF;
IF v_group_id_in = get_group_fulfillment_center1
THEN
v_sql_order_by := 'ORDER BY '
|| 'bcf_fulfillment.get_division_count (po.order_id,' || v_group_for_search || ') '
|| ',bcf_fulfillment.get_divisions(po.order_id,' || v_group_for_search || ') '
|| ',po.order_id '
ELSIF v_group_id_in = c_GROUP_FULFILLMENT_CENTER_212
THEN
v_sql_order_by := 'ORDER BY '
|| 'bcf_fulfillment.get_shipping_priority(po.order_id,' || v_group_for_search || ') DESC'
|| ',TRUNC(po.order_date)'
|| ',bcf_fulfillment.get_line_item_count(po.order_id,' || v_group_for_search || ')'
|| ',decode('||v_group_id_in||',4,substr(bcf_locator.get_first_location(po.order_id,'||v_group_id_in||'),3),null)'
|| ',po.order_id'
ELSE
v_sql_order_by := 'ORDER BY '
|| ' bcf_fulfillment.get_shipping_priority(po.order_id,' || v_group_for_search || ') DESC'
|| ',chain_codes DESC'
|| ',po.order_id '
END IF;
IF UPPER(v_search_type_in) = 'ORDERNUMBER'
THEN
v_sql_where := v_sql_where || v_group_where
|| 'AND po.order_id = :v_search_value1_in '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where
USING v_search_value1_in;
ELSIF UPPER(v_search_type_in) = 'STATUSONLY'
THEN
v_sql_where := v_sql_where || v_group_where || v_status_where
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status;
ELSIF UPPER(v_search_type_in) = 'BILLINGNAME'
THEN
v_upper_search_value1 := UPPER(v_search_value1_in);
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.upper_billing_name LIKE ''%'' || :v_upper_search_value1 || ''%'' '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_upper_search_value1;
ELSIF UPPER(v_search_type_in) = 'GROUP'
THEN
IF v_search_value1_in = '0' -- Unassigned
THEN
v_sql_from := v_sql_from || ' ,product_order_detail_actv_v pod ';
v_sql_where := v_sql_where || ' ' || v_status_where
|| 'AND po.order_id = pod.order_id '
|| 'AND pod.group_id IS NULL '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT DISTINCT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status;
ELSE
v_sql_where := v_sql_where || ' ' || v_status_where
|| 'AND pog.group_id = :v_group_for_search '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status, v_group_for_search;
END IF;
ELSIF UPPER(v_search_type_in) = 'SHIPPINGNAME'
THEN
v_upper_search_value1 := UPPER(v_search_value1_in);
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.upper_shipping_name LIKE ''%'' || :v_upper_search_value1 || ''%'' '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_upper_search_value1;
ELSIF UPPER(v_search_type_in) = 'USERNAME'
THEN
v_lower_search_value1 := LOWER(v_search_value1_in);
v_sql_from := v_sql_from || ' ,sxweb01.customer c ';
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.customer_id = c.customer_id '
|| 'AND c.username LIKE ''%'' || :v_lower_search_value1 || ''%'' '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_lower_search_value1;
ELSIF UPPER(v_search_type_in) = 'BILLINGADDRESS1'
THEN
v_upper_search_value1 := UPPER(v_search_value1_in);
v_sql_from := v_sql_from || ' ,order_payment op '
|| ' ,credit_card cc '
|| ' ,om_address oma '
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.order_id = op.business_object_id '
|| 'AND op.business_object_type = ''ORDR'' '
|| 'AND op.payment_method = ''CRCD'' '
|| 'AND op.payment_method_id = cc.credit_card_id '
|| 'AND cc.address_id = oma.address_id '
|| 'AND UPPER(oma.address1) LIKE ''%'' || :v_upper_search_value1 || ''%'' '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_upper_search_value1;
ELSIF UPPER(v_search_type_in) = 'SHIPPINGADDRESS1'
THEN
v_upper_search_value1 := UPPER(v_search_value1_in);
v_sql_from := v_sql_from || ' ,shipping_info si '
|| ' ,om_address oma '
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.order_id = si.order_id '
|| 'AND si.ship_to_address_id = oma.address_id '
|| 'AND UPPER(oma.address1) LIKE ''%'' || :v_upper_search_value1 || ''%'' '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_upper_search_value1;
ELSIF UPPER(v_search_type_in) = 'BILLINGPHONE'
THEN
v_sql_from := v_sql_from || ' ,order_payment op '
|| ' ,credit_card cc '
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.order_id = op.business_object_id '
|| 'AND op.business_object_type = ''ORDR'' '
|| 'AND op.payment_method = ''CRCD'' '
|| 'AND op.payment_method_id = cc.credit_card_id '
|| 'AND cc.home_phone = :v_search_value1_in '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_search_value1_in;
ELSIF UPPER(v_search_type_in) = 'SHIPPINGPHONE'
THEN
v_sql_from := v_sql_from || ' ,shipping_info si '
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.order_id = si.order_id '
|| 'AND si.ship_phone = :v_search_value1_in '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_search_value1_in;
ELSIF UPPER(v_search_type_in) = 'CREDITCARDNUMBER'
THEN
v_sql_from := v_sql_from || ' ,order_payment op '
|| ' ,credit_card cc '
v_sql_where := v_sql_where || ' ' || v_group_where
|| 'AND po.order_id = op.business_object_id '
|| 'AND op.business_object_type = ''ORDR'' '
|| 'AND op.payment_method = ''CRCD'' '
|| 'AND op.payment_method_id = cc.credit_card_id '
|| 'AND cc.credit_card_number = :v_search_value1_in '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_search_value1_in;
ELSIF UPPER(v_search_type_in) = 'PONUMBER'
THEN
v_sql_from := ' '
|| 'FROM ' || ' product_order_detail_actv_v pod ,' || SUBSTR(v_sql_from, 6);
v_sql_where := v_sql_where || v_group_where
|| 'AND pod.po_no = :v_search_value1_in '
|| 'AND po.order_id = pod.order_id '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT /*+ ORDERED */ DISTINCT ' || v_sql_select || v_sql_from || v_sql_where
USING v_search_value1_in;
ELSIF UPPER(v_search_type_in) = 'USERASSIGNED'
THEN
IF v_search_value1_in = '0' -- 'Unassigned'
THEN
v_sql_where := v_sql_where || ' ' || v_group_where || ' ' || v_status_where
|| 'AND pog.unassigned_flag = ''Y'' '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status;
ELSE
v_sql_where := v_sql_where || ' ' || v_group_where || ' ' || v_status_where
|| 'AND pog.dn_employee_id = :v_search_value1_in '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status, v_search_value1_in;
END IF;
ELSIF UPPER(v_search_type_in) = 'ORDERDATE'
THEN
v_sql_where := v_sql_where || ' ' || v_group_where || ' ' || v_status_where
|| 'AND po.order_date BETWEEN TO_DATE( :v_search_value1_in, ''MON DD YYYY HH24:MI:SS'') AND TO_DATE( :v_search_value2_in ,''MON DD YYYY HH24:MI:SS'') '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status, v_search_value1_in, v_search_value2_in;
ELSIF UPPER(v_search_type_in) = 'PRINTJOB'
THEN
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select
|| ' '
|| 'FROM product_order po '
|| ' ,bcf_print_jobs pj '
|| 'WHERE 1 = 1 '
|| 'AND pj.order_id = po.order_id '
|| 'AND pj.username = :v_search_value1_in '
|| 'AND pj.create_date = TO_DATE( :v_search_value2_in,''MON DD YYYY HH24:MI:SS'') '
|| v_sql_order_by
USING v_search_value1_in, v_search_value2_in;
ELSIF UPPER(v_search_type_in) = 'FULFILLMENTTYPE'
THEN
v_sql_from := v_sql_from || ' ,product_order_detail_actv_v pod ';
v_sql_where := v_sql_where || ' ' || v_group_where || ' ' || v_status_where
|| 'AND pod.order_id = po.order_id '
-- Because we have to drill down the the POD level
-- we now need to ensure the pod records match on group
|| 'AND pod.group_id = ' || v_group_for_search
-- We curr. have 3 fufillment types FC165, FC212, FCBABY
-- so substr on 1st char works for Garry
|| 'AND UPPER(SUBSTR(pod.fulfillment_type,1,1)) = UPPER(:v_search_value1_in) '
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT DISTINCT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by
USING v_open_status, v_requested_status, v_cancelled_status, v_closed_status, v_search_value1_in;
ELSIF UPPER(v_search_type_in) = 'INSUFFICIENTAUTHORIZATION'
THEN
v_sql_where := v_sql_where
|| 'AND bcf_get_authorization_amount(po.order_id) > 0'
IF (outcursor%ISOPEN) THEN
CLOSE outcursor;
END IF;
OPEN outcursor FOR
'SELECT ' || v_sql_select || v_sql_from || v_sql_where || v_sql_order_by;
END IF;
END order_search;
-- -
How could I replace hard coded value in my sql query with constant value?
Hi all,
Could anyone help me how to replace hardcoded value in my sql query with constant value that might be pre defined .
PROCEDURE class_by_day_get_bin_data
in_report_parameter_id IN NUMBER,
in_site_id IN NUMBER,
in_start_date_time IN TIMESTAMP,
in_end_date_time IN TIMESTAMP,
in_report_level_min IN NUMBER,
in_report_level_max IN NUMBER
IS
bin_period_length NUMBER(6,0);
BEGIN
SELECT MAX(period_length)
INTO bin_period_length
FROM bin_data
JOIN site_to_data_source_lane_v
ON bin_data.data_source_id = site_to_data_source_lane_v.data_source_id
JOIN bin_types
ON bin_types.bin_type = bin_data.bin_type
WHERE site_to_data_source_lane_v.site_id = in_site_id
AND bin_data.start_date_time >= in_start_date_time - numtodsinterval(1, 'DAY')
AND bin_data.start_date_time < in_end_date_time + numtodsinterval(1, 'DAY')
AND bin_data.bin_type = 2
AND bin_data.period_length <= 60;
--Clear the edr_class_by_day_bin_data temporary table and populate it with the data for the requested
--report.
DELETE FROM edr_class_by_day_bin_data;
SELECT site_to_data_source_lane_v.site_id,
site_to_data_source_lane_v.site_lane_id,
site_to_data_source_lane_v.site_direction_id,
site_to_data_source_lane_v.site_direction_name,
bin_data_set.start_date_time,
bin_data_set.end_date_time,
bin_data_value.bin_id,
bin_data_value.bin_value
FROM bin_data
JOIN bin_data_set
ON bin_data.bin_serial = bin_data_set.bin_serial
JOIN bin_data_value
ON bin_data_set.bin_data_set_serial = bin_data_value.bin_data_set_serial
JOIN site_to_data_source_lane_v
ON bin_data.data_source_id = site_to_data_source_lane_v.data_source_id
AND bin_data_set.lane = site_to_data_source_lane_v.data_source_lane_id
JOIN (
SELECT CAST(report_parameter_value AS NUMBER) lane_id
FROM report_parameters
WHERE report_parameters.report_parameter_id = in_report_parameter_id
AND report_parameters.report_parameter_group = 'LANE'
AND report_parameters.report_parameter_name = 'LANE'
) report_lanes
ON site_to_data_source_lane_v.site_lane_id = report_lanes.lane_id
JOIN (
SELECT CAST(report_parameter_value AS NUMBER) class_id
FROM report_parameters
WHERE report_parameters.report_parameter_id = in_report_parameter_id
AND report_parameters.report_parameter_group = 'CLASS'
AND report_parameters.report_parameter_name = 'CLASS'
) report_classes
ON bin_data_value.bin_id = report_classes.class_id
JOIN edr_rpt_tmp_inclusion_table
ON TRUNC(bin_data_set.start_date_time) = TRUNC(edr_rpt_tmp_inclusion_table.date_time)
WHERE site_to_data_source_lane_v.site_id = in_site_id
AND bin_data.start_date_time >= in_start_date_time - numtodsinterval(1, 'DAY')
AND bin_data.start_date_time < in_end_date_time + numtodsinterval(1, 'DAY')
AND bin_data_set.start_date_time >= in_start_date_time
AND bin_data_set.start_date_time < in_end_date_time
AND bin_data.bin_type = 2
AND bin_data.period_length = bin_period_length;
END class_by_day_get_bin_data;In the above code I'm using the hard coded value 2 for bin type
bin_data.bin_type = 2But I dont want any hard coded number or string in the query.
How could I replace it?
I defined conatant value like below inside my package body where the actual procedure comes.But I'm not sure whether I have to declare it inside package body or inside the procedure.
bin_type CONSTANT NUMBER := 2;But it does't look for this value. So I'm not able to get desired value for the report .
Thanks.
Edited by: user10641405 on May 29, 2009 1:38 PMDeclare the constant inside the procedure.
PROCEDURE class_by_day_get_bin_data(in_report_parameter_id IN NUMBER,
in_site_id IN NUMBER,
in_start_date_time IN TIMESTAMP,
in_end_date_time IN TIMESTAMP,
in_report_level_min IN NUMBER,
in_report_level_max IN NUMBER) IS
bin_period_length NUMBER(6, 0);
v_bin_type CONSTANT NUMBER := 2;
BEGIN
SELECT MAX(period_length)
INTO bin_period_length
FROM bin_data
JOIN site_to_data_source_lane_v ON bin_data.data_source_id =
site_to_data_source_lane_v.data_source_id
JOIN bin_types ON bin_types.bin_type = bin_data.bin_type
WHERE site_to_data_source_lane_v.site_id = in_site_id
AND bin_data.start_date_time >=
in_start_date_time - numtodsinterval(1, 'DAY')
AND bin_data.start_date_time <
in_end_date_time + numtodsinterval(1, 'DAY')
AND bin_data.bin_type = v_bin_type
AND bin_data.period_length <= 60;
--Clear the edr_class_by_day_bin_data temporary table and populate it with the data for the requested
--report.
DELETE FROM edr_class_by_day_bin_data;
INSERT INTO edr_class_by_day_bin_data
(site_id,
site_lane_id,
site_direction_id,
site_direction_name,
bin_start_date_time,
bin_end_date_time,
bin_id,
bin_value)
SELECT site_to_data_source_lane_v.site_id,
site_to_data_source_lane_v.site_lane_id,
site_to_data_source_lane_v.site_direction_id,
site_to_data_source_lane_v.site_direction_name,
bin_data_set.start_date_time,
bin_data_set.end_date_time,
bin_data_value.bin_id,
bin_data_value.bin_value
FROM bin_data
JOIN bin_data_set ON bin_data.bin_serial = bin_data_set.bin_serial
JOIN bin_data_value ON bin_data_set.bin_data_set_serial =
bin_data_value.bin_data_set_serial
JOIN site_to_data_source_lane_v ON bin_data.data_source_id =
site_to_data_source_lane_v.data_source_id
AND bin_data_set.lane =
site_to_data_source_lane_v.data_source_lane_id
JOIN (SELECT CAST(report_parameter_value AS NUMBER) lane_id
FROM report_parameters
WHERE report_parameters.report_parameter_id =
in_report_parameter_id
AND report_parameters.report_parameter_group = 'LANE'
AND report_parameters.report_parameter_name = 'LANE') report_lanes ON site_to_data_source_lane_v.site_lane_id =
report_lanes.lane_id
JOIN (SELECT CAST(report_parameter_value AS NUMBER) class_id
FROM report_parameters
WHERE report_parameters.report_parameter_id =
in_report_parameter_id
AND report_parameters.report_parameter_group = 'CLASS'
AND report_parameters.report_parameter_name = 'CLASS') report_classes ON bin_data_value.bin_id =
report_classes.class_id
JOIN edr_rpt_tmp_inclusion_table ON TRUNC(bin_data_set.start_date_time) =
TRUNC(edr_rpt_tmp_inclusion_table.date_time)
WHERE site_to_data_source_lane_v.site_id = in_site_id
AND bin_data.start_date_time >=
in_start_date_time - numtodsinterval(1, 'DAY')
AND bin_data.start_date_time <
in_end_date_time + numtodsinterval(1, 'DAY')
AND bin_data_set.start_date_time >= in_start_date_time
AND bin_data_set.start_date_time < in_end_date_time
AND bin_data.bin_type = v_bin_type
AND bin_data.period_length = bin_period_length;
END class_by_day_get_bin_data; -
How to write sql query with many parameter in ireport
hai,
i'm a new user in ireport.how to write sql query with many parameters in ireport's report query?i already know to create a parameter like(select * from payment where entity=$P{entity}.
but i don't know to create query if more than 1 parameter.i also have parameter such as
$P{entity},$P{id},$P{ic}.please help me for this.
thanksYou are in the wrong place. The ireport support forum may be found here
http://www.jasperforge.org/index.php?option=com_joomlaboard&Itemid=215&func=showcat&catid=9 -
Wrong result for query with like and %
I have a strange problem with query with like and %.
When I run this script:
ALTER SESSION SET NLS_SORT = 'BINARY_CI';
ALTER SESSION SET NLS_COMP = 'LINGUISTIC';
-- SELECT * FROM NLS_SESSION_PARAMETERS;
-- drop table test1;
CREATE TABLE TEST1(K1 NVARCHAR2(80));
INSERT INTO TEST1 VALUES ('gsdk');
INSERT INTO TEST1 VALUES ('ąxyz');
INSERT INTO TEST1 VALUES ('ŁFa');
INSERT INTO TEST1 VALUES ('ła');
INSERT INTO TEST1 VALUES ('Śab');
INSERT INTO TEST1 VALUES ('Śrrrb');
commit;
select * from TEST1 where k1 like N'Ł%';
I get this:
K1
ŁFa
ła
Śab <- WRONG
Śrrrb <- WRONG
4 rows selected
When i change datatype to varchar2 this code work correct.
Is this a bug or what ?
The execution plan:
PLAN_TABLE_OUTPUT
SQL_ID d3d64aupz4bb5, child number 2
select * from TEST1 where k1 like N'Ł%'
Plan hash value: 4122059633
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | | | 2 (100)| |
|* 1 | TABLE ACCESS FULL| TEST1 | 1 | 82 | 2 (0)| 00:00:01 |
Predicate Information (identified by operation id):
1 - filter((NLSSORT("K1",'nls_sort=''BINARY_CI''')>=HEXTORAW('014200'
) AND NLSSORT("K1",'nls_sort=''BINARY_CI''')<HEXTORAW('01610100') ))
Note
- dynamic sampling used for this statement (level=2)DATABASE NLS CONFIGURATION:
NLS_CHARACTERSET AL32UTF8
NLS_NCHAR_CHARACTERSET AL16UTF16
NLS_COMP BINARY
NLS_SORT BINARY
Oracle version 11.2.0.2.0 -
Need help with SQL Query with Inline View + Group by
Hello Gurus,
I would really appreciate your time and effort regarding this query. I have the following data set.
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
Please Ignore '----', added it for clarity
I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
The query should return the following data set
Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
The following is my query. I am kind of lost.
select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
from (
select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
from INVOICE
group by sequence_id,check_date, check_number, invoice_number, vendor_number
) A, INVOICE B
where A.sequence_id = B.sequence_id
Thanks,
NickIt looks like it is a duplicate thread - correct me if i'm wrong in this case ->
Need help with SQL Query with Inline View + Group by
Regards.
Satyaki De. -
Extract Sql Query with Actual Parameters from Report
Hi
I am able to extract query from Crystal Report using the following code :
ReportDocument.ReportClientDocument.RowSetController.GetSqlStatement(new GroupPath, out tmp);
But the sql query retrieve comes in the following format :
select name , trans_code, account_code from command_query.accounts
where account_code = {?Command_query_Prompt0} and effective_date < '{?Command_query_prompt1 }'
The parameters which I m using in the reports are :
Account_Code and Effective_Date .
Why does my extracted sql translates it into {?Command_query_Prompt0} and '{?Command_query_prompt1 }' .
Is there any way to map this to the actual parameter values ?
OR
Can we extract the query after assigning the values ?
Any help is appreciated ...
Thanks
Sanchethi,
You can create nested sql query with conditional parameters,
For example
Select Code From OITT Where Code IN (Select ItemCode From OITM
Where ItemName LIKE '[%0]' + '%%')
Edited by: Jeyakanthan A on Jun 9, 2009 12:31 PM -
Simple query with like return wrong result
Hi,
I run simple query with like.
If I use parameter I get wrong results.
If I use query without parameter results are ok.
My script:
ALTER SESSION SET NLS_SORT=BINARY_CI;
ALTER SESSION SET NLS_COMP=LINGUISTIC;
-- drop table abcd;
create table abcd (col1 varchar2(10));
INSERT INTO ABCD VALUES ('122222');
insert into abcd values ('111222');
SELECT * FROM ABCD WHERE COL1 LIKE :1; -- wrong result with value 12%
COL1
122222
*111222*
select * from abcd where col1 like '12%'; -- result ok
COL1
122222
I use Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
and query run in Oracle SQL Developer 3.1.07.Hi,
welcome to the forum.
When you put some code please enclose it between two lines starting with {noformat}{noformat}
i.e.:
{noformat}{noformat}
SELECT ...
{noformat}{noformat}
You should specify exactly how you run your code.
If I run this statement in SQL Plus:SQL> ALTER SESSION SET NLS_SORT=BINARY_CI;
Session altered.
SQL> ALTER SESSION SET NLS_COMP=LINGUISTIC;
Session altered.
SQL>
SQL> -- drop table abcd;
SQL> create table abcd (col1 varchar2(10));
Table created.
SQL>
SQL> INSERT INTO ABCD VALUES ('122222');
1 row created.
SQL> insert into abcd values ('111222');
1 row created.
SQL>
SQL> SELECT * FROM ABCD WHERE COL1 LIKE :1;
SP2-0552: Bind variable "1" not declared.
SQL>
I got this error. So I wonder how you set value 12%
Please specify exactly how you run your test as we cannot reproduce your problem.
Regards.
Al -
SQL query with Bind variable with slower execution plan
I have a 'normal' sql select-insert statement (not using bind variable) and it yields the following execution plan:-
Execution Plan
0 INSERT STATEMENT Optimizer=CHOOSE (Cost=7 Card=1 Bytes=148)
1 0 HASH JOIN (Cost=7 Card=1 Bytes=148)
2 1 TABLE ACCESS (BY INDEX ROWID) OF 'TABLEA' (Cost=4 Card=1 Bytes=100)
3 2 INDEX (RANGE SCAN) OF 'TABLEA_IDX_2' (NON-UNIQUE) (Cost=3 Card=1)
4 1 INDEX (FAST FULL SCAN) OF 'TABLEB_IDX_003' (NON-UNIQUE)
(Cost=2 Card=135 Bytes=6480)
Statistics
0 recursive calls
18 db block gets
15558 consistent gets
47 physical reads
9896 redo size
423 bytes sent via SQL*Net to client
1095 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
55 rows processed
I have the same query but instead running using bind variable (I test it with both oracle form and SQL*plus), it takes considerably longer with a different execution plan:-
Execution Plan
0 INSERT STATEMENT Optimizer=CHOOSE (Cost=407 Card=1 Bytes=148)
1 0 TABLE ACCESS (BY INDEX ROWID) OF 'TABLEA' (Cost=3 Card=1 Bytes=100)
2 1 NESTED LOOPS (Cost=407 Card=1 Bytes=148)
3 2 INDEX (FAST FULL SCAN) OF TABLEB_IDX_003' (NON-UNIQUE) (Cost=2 Card=135 Bytes=6480)
4 2 INDEX (RANGE SCAN) OF 'TABLEA_IDX_2' (NON-UNIQUE) (Cost=2 Card=1)
Statistics
0 recursive calls
12 db block gets
3003199 consistent gets
54 physical reads
9448 redo size
423 bytes sent via SQL*Net to client
1258 bytes received via SQL*Net from client
3 SQL*Net roundtrips to/from client
1 sorts (memory)
0 sorts (disk)
55 rows processed
TABLEA has around 3million record while TABLEB has 300 records. Is there anyway I can improve the speed of the sql query with bind variable? I have DBA Access to the database
Regards
IvanMany thanks for your reply.
I have run the statistic already for the both tableA and tableB as well all the indexes associated with both table (using dbms_stats, I am on 9i db ) but not the indexed columns.
for table I use:-
begin
dbms_stats.gather_table_stats(ownname=> 'IVAN', tabname=> 'TABLEA', partname=> NULL);
end;
for index I use:-
begin
dbms_stats.gather_index_stats(ownname=> 'IVAN', indname=> 'TABLEB_IDX_003', partname=> NULL);
end;
Is it possible to show me a sample of how to collect statisc for INDEX columns stats?
regards
Ivan -
Hi,
I have a SQL Query object which selects the nextval of an Oracle sequence, as follows:
select Onwer.SequenceName.nextval from dual
But, when I try to get the value inside a method (as follows) it returns nothing. Why?
seq = SQLQueryObject()
varDecimal = seq.nextval
Thanks in advance.Hi user634269,
guessing that MyQueryObjSeq is the name of your SQL Query Object, try something like:
id as Decimal
for each row in MyQueryObjSeq do
id = row.nextval
endBye,
Luca -
SQL query with JSP and WML-parameters
Hey,
Could you help me?
I'm trying to do the following. WML deck card 1 send parameter to same WML deck's card help. I try to read the parameter with JSP in card help by putting the parameter to SQL query, but it doesn't work. I can read the parameter with WML in card help. I can also print the value of the parameter with JSP if I generate WML with JSP.
/*parameter sending from card 1 to card help*/
out.println("<go href='#helpcard'>");
out.println("<setvar name='valittukurssi' value='$(valittukurssi)'/>");
/*parameter read with WML in card help */
<p>Valitse kurssi.
$valittukurssi</p>
/'parameter read with JSP by generating WML with JSP*/
out.println("<p>$valittukurssi</p>");
/* SQL query with JSP */
ResultSet uudettulokset = uusilause.executeQuery("select * from kurssi where lyhenne='$valittukurssi'");
Thanks,
RampeYou're problem is easy to fix. You're confusing WML variables with JSP variables. See below:
>
/*parameter sending from card 1 to card help*/
out.println("<go href='#helpcard'>");
out.println("<setvar name='valittukurssi'
value='$(valittukurssi)'/>");
Above you set a var that will work on the phone, not in JSP.
/*parameter read with WML in card help */
<p>Valitse kurssi.
$valittukurssi</p>
Yes the above does display the parameter, because it is a client side WML var, but you cannot use this variable in the JSP code (that's why your SWL fails).
/'parameter read with JSP by generating WML with
JSP*/
out.println("<p>$valittukurssi</p>");Here's you're problem, the above line is EXACTLY the same as the one before it. When the container parses through this JSP code it translates the above line to:
<p>$valittukurssi</p> on the WML page and the CLIENT uses it's local variable to display it.
What you need and want is to have a variable that can be used in JSP code and output to your WML page. Here's how it's done:
out.println("<go href='#helpcard'>");
String some_name = "valittukurssi";
out.println("<setvar name='"+some_name+"'
value='$("+some_name+")'/>");
//note that you may have to escape the ( and ) with a \
//so we displayed the variable above into the WML page, now we can use it in the SQL query:
/* SQL query with JSP */
ResultSet uudettulokset =
uusilause.executeQuery("select * from kurssi where
lyhenne='"+some_name+"'");//the end of the command is: " ' " ) ;
Frank Krul
Got Node?
Maybe you are looking for
-
Lockbox Issue with payment on exact day as Cash Discount Days 1 Due Date
Dear Gurus We are running into an issue in as much as when we receive a payment against our Lockbox on the exact day as the Cash Discount Days 1 due date the system posts this as an on account posting as opposed to applying the cash against the open
-
I take back anything I ever said about the Creative support being go
All the emails you get back from them do is lead you in circles or give you answers to completely different problems. Stupid automated things. My mediasource/other creative software is painfully slow, but transfers are fast in wmp and yahoo so I know
-
No Content When Sending Emails
Hi, This is very frustrating! I thought I replied to several email but the receiver says they were empty. When I look in my sent folder the email says "no content". Anyone seen this from the iPhone and come up with a fix? Thanks.
-
Help me open photoshop files created in '97
I have archives of photoshop format files that were created in '96-2000 that CS5 will not open. Is there a translator or updater that will enable these files to be opened?
-
FCS 2 upgrade- do you need the original prog to be installed?
I'm just about to take delivery of a brand spanking new Mac Pro, 3.2GHz etc (and very excited I am). Planning to install FCS2 as an upgrade from my existing copy of FCP3. Will the FCS2 upgrade package require that FCP3 is installed on the machine alr