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 PM

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;
--

Similar Messages

  • SQL query using LIKE

    I want to do an SQL query which uses a parameter. This is the query: Find the books which contains the string "strTitle". I do this (it does not work):
    String strSQL="SELECT * FROM Books WHERE Title LIKE %'"+strTitle+"'% ";
    I know it is not correct, but anyone any idea of how i can do it?
    Thanks

    Hi,
    You can also use a PreparedStatement, for not-worrying about quotes:
    PreparedStatetment ps=con.prepareStatement(theQuery);
    ps.setString(1, likeString);
    ResultSet r=theQuery.execute();
    // etc...
    where :
    String theQuery=new String("SELECT * FROM PERSON WHERE NAME LIKE ?;");
    likeString='\%'+theStringSearching+'\%';
    also, likeString could be a custom method for making more complicated searches by one Like Statement,
    that needs reeding about RegExpressions.
    cheers, Thanasis

  • 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 ?
    reagrds

    kindly 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

  • How to obtain the transformed SQL query using SEM_MATCH

    Dear all,
    Is it possible to get the transformed relational SQL query when using the SEM_MATCH prefix, by querying directly on the database. We are able to obtain the relational SQL query using Joseki/Jena, however this is not the way to go for us. We would like (if possible) to get it straight from the oracle database by logging or something.
    Kind regards.
    Max

    Hi Max,
    Just to clarify. What SEM_MATCH prefix are you talking about?
    A SEM_MATCH based query is indeed a SQL query as SEM_MATCH is a SQL table function. So if you don't want to go through Java APIs or web service endpoint, then running SEM_MATCH directly should give you what you need. Or maybe you just want to see the underlying generated (from SEM_MATCH) SQL query. If that is true, can you please tell us why?
    Thanks,
    Zhe Wu

  • SQL 2012 DBCC CHECKDB Run Very Slow

    Does anyone experience this? SQL 2012 DBCC CHECKDB runs very slow on one of the server. I monitored the server and it seems DBCC CHECKDB does not hit the disk hard enough.
    It can read 100 mb per second on of my slower server, but on this particular server, it only read 1 mb per second. I saw parallel processes, but it just not read disk hard enough. I am curious what causes this? There is no user using the server when I run
    DBCC command. The full database restore took 3 hours, but DBCC CHECKDB took more than 11 hours.  Thanks for any input.
    Lijun

    Hi,
    Have you made the change of 'cost threshold for parallelism'? The default value of this is 5. Increasing the cost threshold for parallelism would cause most of the queries including CHECKDB to not execute parallel and hence will tend to
    take time to complete. This could be one of the issue contributing to the CHECKDB slow run.
    Also, please check if the antivirus is checking SQL Database files:
    http://support.microsoft.com/kb/309422
    Here is a good article on CHECKDB time taken to complete.
    http://blogs.msdn.com/b/sqlserverstorageengine/archive/2007/01/24/how-long-will-checkdb-take-to-run.aspx
    Thanks.
    Tracy Cai
    TechNet Community Support

  • How to find sql query using sqlid

    Hi
    I am not aware of that sqlid .DBA is saying a particular sqlid is making problem .how to find the particular sql query using sql_id ?

    Are you aware of modplsql when i executed the query the result is like
    DECLARE
       rc__             NUMBER;
       simple_list__    OWA_UTIL.vc_arr;
       complex_list__   OWA_UTIL.vc_arr;
    BEGIN
       OWA.init_cgi_env (:n__, :nm__, :v__);
       HTP.htbuf_len := 84;
       NULL;
       NULL;
       simple_list__ (1) := 'sys.%';
       simple_list__ (2) := 'dbms\_%';
       simple_list__ (3) := 'utl\_%';
       simple_list__ (4) := 'owa\_%';
       simple_list__ (5) := 'owa.%';
       simple_list__ (6) := 'htp.%';
       simple_list__ (7) := 'htf.%';
       simple_list__ (8) := 'wpg_docload.%';
       IF ((owa_match.match_pattern ('Oly_browse.oly_pattern ',
                                     simple_list__,
                                     complex_list__,
                                     TRUE
       THEN
          rc__ := 2;
       ELSE
          NULL;
          NULL;
         oly_browse.oly_pattern (search_phrase      => :search_phrase,           --Oly_browse.oly_pattern is package name
                                btn                => :btn,
                                p_qual             => :p_qual,
                                p_bcat             => :p_bcat,
                                p_stdy             => :p_stdy,
                                p_bloc             => :p_bloc,
                                z                  => :z
          IF (WPG_DOCLOAD.is_file_download)
          THEN
             rc__ := 1;
             WPG_DOCLOAD.get_download_file (:doc_info);
             NULL;
             NULL;
             NULL;
             COMMIT;
          ELSE
             rc__ := 0;
             NULL;
             NULL;
             NULL;
             COMMIT;
             OWA.get_page (:data__, :ndata__);
          END IF;
       END IF;
       :rc__ := rc__;
    END; Edited by: vishnu prakash on Sep 8, 2010 10:16 PM

  • Download using wifi is very slow for my ipad may i know what is the problem?

    Downloading using wifi is very slow for my ipad may i know what is the problem

    Maybe your internet speed is slow. Check your download speed.
    https://itunes.apple.com/sg/app/speedtest.net-mobile-speed/id300704847?mt=8

  • Set TIMEOUT on OCCI sql query using ?

    Is there a way to set a timeout on a sql query using OCCI ?

    OCCI does not provide an API to set timeouts on SQL Queries.
    You can use the CREATE PROFILE command and assign resources at
    a user level. The restrictions may be applied to memory/resources which
    in turn would control the SQL execution time. Please check the
    CREATE PROFILE command.
    Rgds
    Amogh

  • 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

  • Creating sql query using 3 tables

    There is database (supposed to be relational but it is not) and
    I cannot change the tables and it is very difficult to create SQL query.
    Please, help!
    First table T1
    a1 char 20
    time timestamp
    a2 char 7 (the same as t2.a2 when is trimmed)
    a3 number 5,0
    a4 number 8,4
    a5 number 7,3
    Second table T2
    a2 char 15
    b1 number 1,0
    b2 char 1,0
    b3 char 4
    a3 number 5,0
    Third table T3
    b3 char 4
    c1 char 4
    c2 number 7,3
    c3 number 8,4
    So, I need to create query (is it possible at all!?) from those 3 tables (a1, a2, b1,b2,b3, a4, a5, c2,c3
    where time is within interval (from, to), a3 in interval (1,2,3,4), t2.b3=t3.b3, t1.a2=t2.a2
    group by or sorted by a1, then, a2.
    Any suggestion is welcome!
    Thanks!
    By the way, I will use this query in Crystal Reports.

    As I already mentioned, I received another conditions for the query, and when I create a new one, I
    First table T1
    a1 number 5,0
    a2 char 7 (the same as t2.a2 when is trimmed)
    a3 number 8,4
    a4 number 7,3
    a_time timestamp
    Second table T2
    a2 char 15
    b1 number 1,0
    b2 char 1,0
    b3 char 4
    b4 char 4
    Third table T3
    c1 char 4
    c2 number 7,3
    c3 number 8,4
    b3 char 4
    where if c1='MIN' c2, c3 return min values,
    and if c1='MAX' c2,c3 return max values
    SQL query:
    select t1.a1, t1.a2, t2.b1, t2.b2, t2.b3, t1.a3, t1.a4, t3.c1,
    t3.c2, t3.c3, t2.b4
    from t1, t2, t3
    where (TRIM(t1.a2)=TRIM(t2.a2)
    and t1.a1=19
    and ((to_char(t1.a_time, 'YYYY-MM-DD') >= '2006-03-15')
    and (to_char(t1.a_time, 'YYYY-MM-DD') <= '2006-03-16')))
    and t3.b3=t2.b3)
    order by t1.a_time
    Result set:
    a1, a2, b1, b2, b3, a3, a4, c1('MAX'), c2', c3', b4
    a1, a2, b1, b2, b3, a3, a4, c1('MIN'), c2", c3", b4
    So when I executed SQL query it returns 2 rows for the same a2.
    I want to get 1 row for each a2 together with c3 (c4) min and c3 (c4) max values.
    How to name columns for c2 min and c2 max (the same for c3) in order to retreive 1 row per a2 value, something like this:
    a1, a2, b1, b2, b3, a3, a4, c2min, c2max, c3min, c3max, b4
    Thanks

  • Need SQL query using View - Please help

    Hi,
    I have similar requirement like below.
    I have two tables DEPT and EMP and some departments may not have employees. I have created below view, which displays all DEPT records, even though there are no emplyees.
    CREATE OR REPLACE VIEW dept_emp_vw AS
    SELECT deptno, empid, 0 AS selected
    FROM dept d, emp e
    WHERE d.deptno = e.deptnno (+);
    Ex.
    DEPTNO         EMPID        SELECTED
    10 101 0
    10 102 0
    20 103 0
    30 103 0
    40 104 0
    50 <null> 0
    Application will pass "empid" to the view (for ex. empid = 103) and I want result like below.
    Ex.
    DEPTNO         EMPID        SELECTED
    10 101 0
    10 102 0
    20 103 1
    30 103 1
    40 104 0
    50 <null> 0
    Can you please let me know the query using "dept_emp_vw" view. We have Oracle 11g Release 2.
    Thanks a lot for the help.

    Not possible using normal SQL - as SQL is not a procedure language and does not support variable declaration and use (e.g. passing empid as a variable and using it both as a predicate and as a condition in the SQL projection).
    That said - SQL can be "+parameterised+". An approach that is ugly and contrary to the basic design and use of SQL. But it can support the (very weird) view definition of yours.
    E.g.
    SQL> create or replace procedure SetVariable( name varchar2, value varchar2 ) is
      2  begin
      3          DBMS_SESSION.set_context( 'MyVariables', name, value );
      4  end;
      5  /
    Procedure created.
    SQL>
    SQL>
    SQL> create or replace context MyVariables using SetVariable;
    Context created.
    SQL>
    SQL> create or replace view my_funky_weird_view as
      2  select
      3          e.empno,
      4          e.ename,
      5          e.job,
      6          case e.empno
      7                  when to_number(sys_context( 'MyVariables', 'empid' )) then
      8                          0
      9                  else
    10                          1
    11          end     as "SELECTED"
    12  from       emp e
    13  /
    View created.
    SQL>
    SQL> exec SetVariable( 'empid', 7499 )
    PL/SQL procedure successfully completed.
    SQL>
    SQL> select * from session_context where namespace = 'MYVARIABLES';
    NAMESPACE            ATTRIBUTE            VALUE
    MYVARIABLES          EMPID                7499
    SQL>
    SQL> select * from my_funky_weird_view order by selected;
         EMPNO ENAME      JOB               SELECTED
          7499 ALLEN      SALESMAN                 0
          7521 WARD       SALESMAN                 1
          7566 JONES      MANAGER                  1
          7654 MARTIN     SALESMAN                 1
          7698 BLAKE      MANAGER                  1
          7934 MILLER     CLERK                    1
          7788 SCOTT      ANALYST                  1
          7839 KING       PRESIDENT                1
          7844 TURNER     SALESMAN                 1
          7876 ADAMS      CLERK                    1
          7900 JAMES      CLERK                    1
          7902 FORD       ANALYST                  1
          7369 SMITH      CLERK                    1
          7782 CLARK      MANAGER                  1
    14 rows selected.
    SQL>But I will N\OT recommend doing it this way. It is not natural SQL as PL/SQL is needed to "+inject+" name-value pairs into the context for the SQL view to use. It is ugly. It is not standard. It cannot scale. It is complex to use. Etc.
    Yes, there are instances when this approach is exactly what one needs - when for example dealing with a trusted context and using the contents for implementing a security layer. But in the above case - I would rather want to see the actual business requirement first, as I think you're barking up the wrong tree with the view solution you have imagined.

  • Can Portal Report from SQL Query use where column IN (:bind_variable)

    I would like to create a portal report from sql query with IN (:bind_variable) in the where clause. The idea is that the user would enter comma-separated or comma-quote-separated values for the bind_variable. I have tried this several ways but nothing seems to work. Can this be done?
    Trenton

    Hi,
    Which version of portal are you using. This is a bug. It has been fixed in 30984.
    Thanks,
    Sharmila

  • SQL query using Group by and Aggregate function

    Hi All,
    I need your help in writing an SQL query to achieve the following.
    Scenario:
    I have table with 3 Columns. There are 3 possible values for col3 - Success, Failure & Error.
    Now I need a query which can give me the summary counts for distinct values of col3 for each GROUP BY of col1 and col2 values. When there are no values for col3 then it should return ZERO count.
    Example Data:
    Col1 Col2 Col3
    abc 01 success
    abc 02 success
    abc 01 success
    abc 01 Failure
    abc 01 Error
    abc 02 Failure
    abc 03 Error
    xyz 07 Failure
    Required Output:
    c1 c2 s_cnt F_cnt E_cnt (Heading)
    abc 01 2 1 1
    abc 02 1 1 0
    abc 03 0 0 1
    xyz 07 0 1 0
    s_cnt = Success count; F_cnt = Failure count; E_cnt = Error count
    Please note that the output should have 5 columns with col1, col2, group by (col1,col2)count(success), group by (col1,col2)count(failure), group by (col1,col2)count(error)
    and where ever there are NO ROWS then it should return ZERO.
    Thanks in advance.
    Regards,
    Shiva

    Hi,
    user13015050 wrote:
    Thanks TTT. Unfortunately I cannot use this solution because I have huge data for this.T's solution is basically the same as mine. The first 23 lines just simulates your table. Since you actually have a table, you would start with T's line 24:
    SELECT col1 c1, col2 c2, SUM(decode(col3, 'success', 1, 0)) s_cnt, ...
    user13015050 wrote:Thanks a lot Frank. It helped me out. I just did some changes to this as below and have no issues.
    SELECT     col1
    ,     col2
    ,     COUNT ( CASE
              WHEN col3 = 'SUCCESS'
              THEN 1
              END
         )          AS s_cnt
    ,     COUNT ( CASE
              WHEN col3 = 'FAILED'
              THEN 1
              END
         )          AS f_cnt
    ,     COUNT ( CASE
              WHEN col3 = 'ERROR'
              THEN 1
              END
         )          AS e_cnt
    FROM     t1
    WHERE c2 in ('PURCHASE','REFUND')
    and c4 between to_date('20091031000000','YYYYMMDDHH24MISS') AND to_date('20100131235959','YYYYMMDDHH24MISS')
    GROUP BY c1, c2
    ORDER BY c1, c2;
    Please let me know if you see any issues in this query.It's very hard to read.
    This site normally compresses spaces. Whenever you post formatted text (such as queries or results) on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
    Also, post exactly what you're using.  The code above is SELECTing col1 and col2, but there's no mention of either in the GROUP BY clause, so I don't believe it's really what you're using.
    Other than that, I don't see anything wrong or suspicious in the query.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Optimizing an SQL Query using Oracle SQL Developer

    Hi ,
    Currently i am using Oracle SQL Developer as my Database IDE .
    Is it possible to use Orqcles SQLDeveloper for the purpose of Optimizing an SQL Query ??
    For example assume i am having a query as :
    Select from Tranac_Master where CUST_STATAUS='Y' and JCC_REPORT='N'*
    Could anybody please tell me how can i use Oracle SQL Developer to optimize this query or any other SQL queries ??
    Please share your ideas , thanks in advance .

    1. Your query looks very simplistic as it is, so I fail to see how you can better optimise it (unless 'Tranac_Master' is a view, in which case I'd need to see the view details).
    2. No tool can automagically optimise your SQL to any degree of practical use. Very minor adjustments may be possible automatically, but really it is a question of you knowing your data & database design accurately, and then you applying your expert knowledge to tune it.

  • About SQL Query using joins

    Hi,
    I want to write a SQL statement using Joins. The base table "A" has about 100 fields and the join table "B" a few. I would like to fetch all fields from table "A" and a few from table "B".
    Is there a way to write a query wherein I can use "Select * " for table "A" rather than writing all 100 field name in the query? Please keep in mind that I want to use a Join.
    Thanks.

    Hi Thomas,
    but if there are some fields which are in both tables, SELECT * will be not sufficient. E.g. fields ERNAM, ERDAT, AENAM, AEDAT are such fields which can occur in more tables. In case that a target area will contain these fields, by * with addition INTO CORRESPONDING FIELDS OF, you are not able to specify from which table these values should be taken. In such case, it can be solved by specifying field list dynamically. If it is not that case SELECT * is sufficient. You should check intersection of common fields for tables you are joining. Thereafter you should decide if you can use SELECT *.
    Maybe for better understanding, what exactly I am talking about, look at this example:
    TYPES: BEGIN OF ts_data,
            ernam TYPE mara-ernam,
           END OF ts_data.
    DATA: ls_data TYPE ts_data,
          ls_mara TYPE mara,
          ls_mchb TYPE mchb.
    START-OF-SELECTION.
      ls_mara-matnr = '1'.
      ls_mchb-matnr = ls_mara-matnr.
      ls_mara-ernam = 'A'.
      ls_mchb-ernam = 'B'.
      INSERT mara FROM ls_mara.
      INSERT mchb FROM ls_mchb.
      SELECT SINGLE * FROM mara INNER JOIN mchb ON mara~matnr = mchb~matnr INTO CORRESPONDING FIELDS OF ls_data.
      ROLLBACK WORK.
    You as a developer are not able to tell from which table common fields should be selected. But maybe this is really too specific case...
    Regards,
    Adrian

Maybe you are looking for

  • Error message when I try to open the "help" files.

    When I try to open the help files in Elements Photoshop 10, I get the following error message in a pop up box.  At the top, the box is labeled "Adobe AIR"  The message:  "Application descriptor could not be found for this application.  Try re-install

  • Problem with sockets

    This is my Server: import java.io.*; import java.net.*; public class Server {      public static void main (String [] a) throws Exception {      String status = null;      try {                ServerSocket s = new ServerSocket(1111);                b

  • Sent notes uncomplete from ibooks

    When i send by email annotations (comments) or underlined text from an book from ibooks, it doesn't send all my annotations.

  • Flash CS5 Help runs Lotus Notes???

    Hi, I just got Flash CS5 installed on my desktop and when I click Help on the menubar it kicks off my default mail program, Lotus Notes! I don't see anything in preferences to control this. Do I need a reinstall? Thanks!

  • Login Password

    A friend on mine cannot remember her login password on her MacBook Air. What is the best process in getting it back for her?