SQL Statement using LIKE and Subquery?

Hi,
I have two tables, one table is called "Restricted_Words", the other table is called "Content" .   I have a field called "short_desc" in the Content table and a field called "word" in the Restricted Words
table.
I want to write a query that will compare all the words in the restricted words table against the short_desc field in the content table and just return all the records in the content table that contain 1 or more of these words.
I started with this:
SELECT short_desc
FROM Content
WHERE short_desc LIKE ( SELECT word FROM Restricted_Words )
I know the above isn't valid and won't work, but that's what I'm trying to do.
Any help appreciated...

Sorry cannot test it right now...
SELECT short_desc
FROM Content
WHERE short_desc LIKE ( SELECT word FROM Restricted_Words where
word  like '%'+short_desc
+'%' )
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence

Similar Messages

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

  • SQL Statements in ABAP and meaning

    Hello Friends,
    Please, can anybody provide me a documentation on the different ABAP SQL statements and there usage/meanings.
    Thanks,
    Shreekant

    hi,
    goto abapdocu->abap Database access->open Sql you will get examples.
    for documnetation got se38->specify the command and press F1.
    SELECT:
    Put the curson on that word and press F1 . You can see the whole documentation for select statements.
    SELECT result
    FROM source
    INTO|APPENDING target
    [[FOR ALL ENTRIES IN itab] WHERE sql_cond]
    Effect
    SELECT is an Open-SQL-statement for reading data from one or several database tables into data objects.
    The select statement reads a result set (whose structure is determined in result ) from the database tables specified in source, and assigns the data from the result set to the data objects specified in target. You can restrict the result set using the WHERE addition. The addition GROUP BY compresses several database rows into a single row of the result set. The addition HAVING restricts the compressed rows. The addition ORDER BY sorts the result set.
    The data objects specified in target must match the result set result. This means that the result set is either assigned to the data objects in one step, or by row, or by packets of rows. In the second and third case, the SELECT statement opens a loop, which which must be closed using ENDSELECT. For every loop pass, the SELECT-statement assigns a row or a packet of rows to the data objects specified in target. If the last row was assigned or if the result set is empty, then SELECT branches to ENDSELECT . A database cursor is opened implicitly to process a SELECT-loop, and is closed again when the loop is ended. You can end the loop using the statements from section leave loops.
    Up to the INTO resp. APPENDING addition, the entries in the SELECTstatement define which data should be read by the database in which form. This requirement is translated in the database interface for the database system´s programming interface and is then passed to the database system. The data are read in packets by the database and are transported to the application server by the database server. On the application server, the data are transferred to the ABAP program´s data objects in accordance with the data specified in the INTO and APPENDING additions.
    System Fields
    The SELECT statement sets the values of the system fields sy-subrc and sy-dbcnt.
    sy-subrc Relevance
    0 The SELECT statement sets sy-subrc to 0 for every pass by value to an ABAP data object. The ENDSELECT statement sets sy-subrc to 0 if at least one row was transferred in the SELECT loop.
    4 The SELECT statement sets sy-subrc to 4 if the result set is empty, that is, if no data was found in the database.
    8 The SELECT statement sets sy-subrc to 8 if the FOR UPDATE addition is used in result, without the primary key being specified fully after WHERE.
    After every value that is transferred to an ABAP data object, the SELECT statement sets sy-dbcnt to the number of rows that were transferred. If the result set is empty, sy-dbcnt is set to 0.
    Notes
    Outside classes, you do not need to specify the target area with INTO or APPENDING if a single database table or a single view is specified statically after FROM, and a table work area dbtab was declared with the TABLES statement for the corresponding database table or view. In this case, the system supplements the SELECT-statement implicitly with the addition INTO dbtab.
    Although the WHERE-condition is optional, you should always specify it for performance reasons, and the result set should not be restricted on the application server.
    SELECT-loops can be nested. For performance reasons, you should check whether a join or a sub-query would be more effective.
    Within a SELECT-loop you cannot execute any statements that lead to a database commit and consequently cause the corresponding database cursor to close.
    SELECT - result
    Syntax
    ... lines columns ... .
    Effect The data in result defines whether the resulting set consists of multiple rows (table-like structure) or a single row ( flat structure). It specifies the columns to be read and defines their names in the resulting set. Note that column names from the database table can be changed. For single columns, aggregate expressions can be used to specify aggregates. Identical rows in the resulting set can be excluded, and individual rows can be protected from parallel changes by another program.
    The data in result consists of data for the rows lines and for the columns columns.
    SELECT - lines
    Syntax
    ... { SINGLE }
    | { { } } ... .
    Alternatives:
    1. ... SINGLE
    2. ... { }
    Effect
    The data in lines specifies that the resulting set has either multiple lines or a single line.
    Alternative 1
    ... SINGLE
    Effect
    If SINGLE is specified, the resulting set has a single line. If the remaining additions to the SELECT command select more than one line from the database, the first line that is found is entered into the resulting set. The data objects specified after INTO may not be internal tables, and the APPENDING addition may not be used.
    An exclusive lock can be set for this line using the FOR UPDATE addition when a single line is being read with SINGLE. The SELECT command is used in this case only if all primary key fields in logical expressions linked by AND are checked to make sure they are the same in the WHERE condition. Otherwise, the resulting set is empty and sy-subrc is set to 8. If the lock causes a deadlock, an exception occurs. If the FOR UPDATE addition is used, the SELECT command circumvents SAP buffering.
    Note
    When SINGLE is being specified, the lines to be read should be clearly specified in the WHERE condition, for the sake of efficiency. When the data is read from a database table, the system does this by specifying comparison values for the primary key.
    Alternative 2
    Effect
    If SINGLE is not specified and if columns does not contain only aggregate expressions, the resulting set has multiple lines. All database lines that are selected by the remaining additions of the SELECT command are included in the resulting list. If the ORDER BY addition is not used, the order of the lines in the resulting list is not defined and, if the same SELECT command is executed multiple times, the order may be different each time. A data object specified after INTO can be an internal table and the APPENDING addition can be used. If no internal table is specified after INTO or APPENDING, the SELECT command triggers a loop that has to be closed using ENDSELECT.
    If multiple lines are read without SINGLE, the DISTINCT addition can be used to exclude duplicate lines from the resulting list. If DISTINCT is used, the SELECT command circumvents SAP buffering. DISTINCT cannot be used in the following situations:
    If a column specified in columns has the type STRING, RAWSTRING, LCHAR or LRAW
    If the system tries to access pool or cluster tables and single columns are specified in columns.
    Note
    When specifying DISTINCT, note that you have to carry out sort operations in the database system for this.
    SELECT - columns
    Syntax
    | { {col1|aggregate( col1 )}
    {col2|aggregate( col2 )} ... }
    | (column_syntax) ... .
    Alternatives:
    1. ... *
    2. ... {col1|aggregate( col1 )}
    {col2|aggregate( col2 )} ...
    3. ... (column_syntax)
    Effect
    The input in columns determines which columns are used to build the resulting set.
    Alternative 1
    Effect
    If * is specified, the resulting set is built based on all columns in the database tables or views specified after FROM, in the order given there. The columns in the resulting set take on the name and data type from the database tables or views. Only one data object can be specified after INTO.
    Note
    If multiple database tables are specified after FROM, you cannot prevent multiple columns from getting the same name when you specify *.
    Alternative 2
    ... {col1|aggregate( col1 )}
    {col2|aggregate( col2 )} ...
    Effect
    A list of column labels col1 col2 ... is specified in order to build the resulting list from individual columns. An individual column can be specified directly or as an argument of an aggregate function aggregate. The order in which the column labels are specified is up to you and defines the order of the columns in the resulting list. Only if a column of the type LCHAR or LRAW is listed does the corresponding length field also have to be specified directly before it. An individual column can be specified multiple times.
    The addition AS can be used to define an alternative column name a1 a2 ... with a maximum of fourteen digits in the resulting set for every column label col1 col2 .... The system uses the alternative column name in the additions INTO|APPENDING CORRESPONDING FIELDS and ORDER BY. .
    http://help.sap.com/saphelp_nw04/helpdata/en/62/10a423384746e8bf5f15ccdd36e8b1/content.htm

  • Why CBO don't use function-base index when I use like and bind variable

    Hello
    I have litle problem with function-base index and like with bind variable.
    When I use like with bind variable, the CBO don't use my function-base index.
    For example when I create table and index:
    ALTER SESSION SET NLS_SORT='BINARY_CI';
    ALTER SESSION SET NLS_COMP='LINGUISTIC';
    alter session set nls_language='ENGLISH';
    -- DROP TABLE TEST1;
    CREATE TABLE TEST1 (K1 VARCHAR2(32));
    create index test1_idx on test1(nlssort(K1,'nls_sort=BINARY_CI'));
    INSERT INTO TEST1
    SELECT OBJECT_NAME FROM ALL_OBJECTS;
    COMMIT;
    When I run:
    ALTER SESSION SET NLS_SORT='BINARY_CI';
    ALTER SESSION SET NLS_COMP='LINGUISTIC';
    SELECT * FROM TEST1 WHERE K1 = 'abcd';
    or
    SELECT * FROM TEST1 WHERE K1 LIKE 'abcd%';
    CBO use index.
    PLAN_TABLE_OUTPUT
    SQL_ID 4vrmp7cshbvqy, child number 1
    SELECT * FROM TEST1 WHERE K1 LIKE 'abcd%'
    Plan hash value: 1885706448
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | | | 1 (100)| |
    | 1 | TABLE ACCESS BY INDEX ROWID| TEST1 | 2 | 98 | 1 (0)| 00:00:01 |
    |* 2 | INDEX RANGE SCAN | TEST1_IDX | 2 | | 1 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    2 - access("TEST1"."SYS_NC00002$">=HEXTORAW('6162636400') AND
    "TEST1"."SYS_NC00002$"<HEXTORAW('6162636500') )
    but when I run
    SELECT * FROM TEST1 WHERE K1 LIKE :1;
    CBO don't use index
    PLAN_TABLE_OUTPUT
    SQL_ID 9t461s1669gru, child number 0
    SELECT * FROM TEST1 WHERE K1 LIKE :1
    Plan hash value: 4122059633
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | | | 89 (100)| |
    |* 1 | TABLE ACCESS FULL| TEST1 | 2 | 48 | 89 (3)| 00:00:02 |
    Predicate Information (identified by operation id):
    1 - filter("K1" LIKE :1)
    What should I change to force CBO to use index.
    I don't wont use index hint in query.
    My oracle version:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE     11.2.0.1.0     Production
    TNS for 64-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production

    OK. But why if I create normal index (create index test1_idx on test1(K1)) and return to default nls settings this same query use index.
    PLAN_TABLE_OUTPUT
    SQL_ID 9t461s1669gru, child number 0
    SELECT * FROM TEST1 WHERE K1 LIKE :1
    Plan hash value: 598212486
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | | | 1 (100)| |
    |* 1 | INDEX RANGE SCAN| TEST1_IDX | 1 | 18 | 1 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    1 - access("K1" LIKE :1)
    filter("K1" LIKE :1)
    Note
    - dynamic sampling used for this statement (level=2)
    when index is function-base (create index test1_idx on test1(nlssort(K1,'nls_sort=BINARY_CI')))
    PLAN_TABLE_OUTPUT
    SQL_ID 9t461s1669gru, child number 1
    SELECT * FROM TEST1 WHERE K1 LIKE :1
    Plan hash value: 4122059633
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | | | 89 (100)| |
    |* 1 | TABLE ACCESS FULL| TEST1 | 3 | 54 | 89 (3)| 00:00:02 |
    Predicate Information (identified by operation id):
    1 - filter("K1" LIKE :1)
    Note
    - dynamic sampling used for this statement (level=2)
    when I create index with upper function "index test1_idx on test1(upper(K1))" the query use index
    SELECT * FROM TEST1 WHERE upper(K1) LIKE :1
    Plan hash value: 1885706448
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | | | 1 (100)| |
    | 1 | TABLE ACCESS BY INDEX ROWID| TEST1 | 4481 | 157K| 1 (0)| 00:00:01 |
    |* 2 | INDEX RANGE SCAN | TEST1_IDX | 806 | | 1 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    2 - access("TEST1"."SYS_NC00002$" LIKE :1)
    filter("TEST1"."SYS_NC00002$" LIKE :1)
    Note
    - dynamic sampling used for this statement (level=2)

  • How to store pl/sql statement in varchar and call EXEC on it?

    So this statement works:
    SELECT column_name BULK COLLECT INTO table_column_list FROM all_tab_columns WHERE table_name = conv_tablename AND OWNER IN (SELECT USER FROM DUAL);
    However I want to add conditions like " AND column_name <> 'abc' " at the end. So i tried to store this in a varchar and call EXEC on it:
    select_column_value_sql_stmt := 'SELECT column_name BULK COLLECT INTO table_column_list FROM user_tab_columns WHERE table_name = '''|| conv_tablename || '''' || inexclude_column;
              EXECUTE IMMEDIATE select_column_value_sql_stmt;     
    No matter how I concatenate the conv_tablename part, i get an error. either invalid identifier or unimplemented feature.
    so is there a way to do this at all?
    Thanks in advance.

    Welcome to the forum!
    Wheneve you post provide your 4 digit Oracle version (result of SELECT * FROM V$VERSION).
    >
    So this statement works:
    SELECT column_name BULK COLLECT INTO table_column_list FROM all_tab_columns WHERE table_name = conv_tablename AND OWNER IN (SELECT USER FROM DUAL);
    However I want to add conditions like " AND column_name 'abc' " at the end. So i tried to store this in a varchar and call EXEC on it:
    select_column_value_sql_stmt := 'SELECT column_name BULK COLLECT INTO table_column_list FROM user_tab_columns WHERE table_name = '''|| conv_tablename || '''' || inexclude_column;
    EXECUTE IMMEDIATE select_column_value_sql_stmt;
    No matter how I concatenate the conv_tablename part, i get an error. either invalid identifier or unimplemented feature.
    so is there a way to do this at all?
    >
    Yes - you can do it but the syntax is different for BULK COLLECT when using EXECUTE IMMEDIATE; the INTO goes AFTER the query, not within it.
    See the example code at this link
    http://unix-oracle-11g.blogspot.com/2011/03/dynamic-sql-execute-immediate-bulk.html
      -- example of dynamic sql with bull collect
      v_sql_stmt := 'SELECT sal FROM emp_t';
      EXECUTE IMMEDIATE v_sql_stmt BULK COLLECT INTO vc_sal;So you won't be able to use a common set of queries for normal vs execute immediate.

  • SQL statement with LIMIT and total count?

    Hello,
    I would like to know if it is possible to execute a single SQL statement that will return me a subset of data (for pagination purposes) that not only includes the subset of data for the page but the count of all available data. Can this be done so as to not take up the cpu and time it takes to essentially run two queries? One to get the subset and one to get the count? I think simply doing a subselect is not going to give me what I want in that we actually query twice.
    There may be no way to do this other than that, but I wanted to check with the gurus here first. :)
    Thanks,
    Mark

    select *
    from (
    select i.*,
    row_number() over(order by i) rn, -- used for
    pagination
    count(*) over(partition by 1) cnt  -- total count
    of rows found for this search
    from mytable
    where < PUT ALL LIMITING (i.e., "search") CONDITIONS
    HERE >
    where rn between 41 and 50 -- pagination clauseNice one
    BUT of course it adds additional row in execution plan and takes additional time and CPU :)
    I assume that it directly depends of course on returned result set and some other factors like available sort space but a simple test case on a table big which actually is 1.6 M rows like dba_source got following results:
    here is the first one returning also count(*)
    SQL> select *
      2  from (
      3    select i.*,
      4      row_number() over(order by owner, name, type) rn
      5  , -- used for pagination
      6      count(*) over(partition by 1) cnt  -- total count of rows found for this search
      7    from big i
      8    where owner like 'S%' and name like '%A%'
      9  )
    10  where rn between 41 and 45
    11  /
    OWNER                          NAME                           TYPE
          LINE
    TEXT
            RN        CNT
    SYS                            ANYDATA                        TYPE
            13
      STATIC FUNCTION ConvertVarchar(c IN VARCHAR) return AnyData,
            41     999744
    SYS                            ANYDATA                        TYPE
            11
      STATIC FUNCTION ConvertDate(dat IN DATE) return AnyData,
            42     999744
    SYS                            ANYDATA                        TYPE
             9
            43     999744
    SYS                            ANYDATA                        TYPE
             7
         They serve as explicit CAST functions from any type in the Oracle ORDBMS
            44     999744
    SYS                            ANYDATA                        TYPE
             6
         enable construction of the AnyData in its entirity with a single call.
            45     999744
    Elapsed: 00:00:41.02
    SQL> ed
    Wrote file afiedt.buf
      1  select n.name, m.value from v$statname n, v$mystat m
      2  where n.statistic# = m.statistic#
      3*   and (upper(name) like '%SORT%' or upper(name) like '%TEMP%')
    SQL> /
    NAME                                                                  VALUE
    physical reads direct temporary tablespace                            35446
    physical writes direct temporary tablespace                           17723
    RowCR attempts                                                            0
    SMON posted for dropping temp segment                                     0
    sorts (memory)                                                           36
    sorts (disk)                                                              1
    sorts (rows)                                                        1999596
    OTC commit optimization attempts                                          0
    8 rows selected.here is the second one returning only rows:
    SQL> ed
    Wrote file afiedt.buf
      1  select *
      2  from (
      3    select i.*,
      4      row_number() over(order by owner, name, type) rn
      5  --, -- used for pagination
      6  --    count(*) over(partition by 1) cnt  -- total count of rows found for this search
      7    from big i
      8    where owner like 'S%' and name like '%A%'
      9  )
    10* where rn between 41 and 45
    SQL> /
    OWNER                          NAME                           TYPE
          LINE
    TEXT
            RN
    SYS                            ANYDATA                        TYPE
            13
      STATIC FUNCTION ConvertVarchar(c IN VARCHAR) return AnyData,
            41
    SYS                            ANYDATA                        TYPE
            11
      STATIC FUNCTION ConvertDate(dat IN DATE) return AnyData,
            42
    SYS                            ANYDATA                        TYPE
             9
            43
    SYS                            ANYDATA                        TYPE
             7
         They serve as explicit CAST functions from any type in the Oracle ORDBMS
            44
    SYS                            ANYDATA                        TYPE
             6
         enable construction of the AnyData in its entirity with a single call.
            45
    Elapsed: 00:00:12.09
    SQL> select n.name, m.value from v$statname n, v$mystat m
      2  where n.statistic# = m.statistic#
      3    and (upper(name) like '%SORT%' or upper(name) like '%TEMP%')
      4  /
    NAME                                                                  VALUE
    physical reads direct temporary tablespace                                0
    physical writes direct temporary tablespace                               0
    RowCR attempts                                                            0
    SMON posted for dropping temp segment                                     0
    sorts (memory)                                                           10
    sorts (disk)                                                              0
    sorts (rows)                                                         999812
    OTC commit optimization attempts                                          0
    8 rows selected.So execution time 41 sec vs 12 sec
    sorts (rows) 1 999 596 vs 999 812
    physical reads/writes direct temporary tablespace 35446/17723 vs 0/0
    I assume that for a small overall returned row count it probably is OK, but for less restrictive search it can be quite deadly as before with two queries.
    Gints Plivna
    http://www.gplivna.eu

  • Get "Creation Script" of the existing table ( in SQL database) using C# and without using SMO dlls

    Hi All,
    I need to get the "Creation Script" of the existing table using c# and without using SMO dlls (is it possible? I don't know).
    I.e. In SQL Management Studio -> right click on any table -> Script table as -> Create To  - > open in the new query editor window. This will give you the schema of the table with the constraints of the table.
    For E.g. In Northwind database, for the table "Categories", I would like to get it as show below
    USE [Northwind]
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    CREATE TABLE [dbo].[Categories](
        [CategoryID] [int] IDENTITY(1,1) NOT NULL,
        [CategoryName] [nvarchar](15) NOT NULL,
        [Description] [ntext] NULL,
        [Picture] [image] NULL,
     CONSTRAINT [PK_Categories] PRIMARY KEY CLUSTERED
        [CategoryID] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    GO
    I would like to get the same schema using c#. Please help.
    Thanks & Regards,
    Kalai.

    SMO is the easiest way to get this. This is what Management Studio uses. If you can't use SMO, get a Profiler trace of the queries that SMO executes when generating the script and execute the same using ADO.NET.
    Regards,
    Farooq Mahmud
    Support Escalation Engineer 
    •  Microsoft Health Solutions Group

  • Execute Dynamic SQL statement using procedure builder

    i want to execute a dynamic SQL statment using procedure builder not using forms
    because my statement depending on a variable table name
    i know that i can do that from forms using
    FORMS_DDL('SQL_STAT');
    but i wanna to use the procedure builder
    which function i should use and how?
    please explain in example if you don't mind.
    thanks

    Hi,
    You can very well use DBMS_SQL Package supplied by Oracle for doing this.
    Search for DBMS_SQL in OTN. You will get all info regarding this.
    Regards.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by itslul:
    i want to execute a dynamic SQL statment using procedure builder not using forms
    because my statement depending on a variable table name
    i know that i can do that from forms using
    FORMS_DDL('SQL_STAT');
    but i wanna to use the procedure builder
    which function i should use and how?
    please explain in example if you don't mind.
    thanks<HR></BLOCKQUOTE>
    null

  • Date formats for SQL statements used by recordset object

    Hi,
    Date formatting appears to be quite problematic for Business One.  I did a forum search for date issues and I don't think I saw any of them with an "answered" status.  I have an issue with formatting a date for the creation of an SQL statement that the DI sends to SQL Server 2005.  I need to format a date so that the localization parameters don't matter for either the client machine or SQL Server's machine.  We don't have a problem as long as our machines are localized as USA.
    I have PL 22 and I have a form - ours - where I use the Today() function to fill a date field.  So this is a date that is not entered by the user.  The result of this function is consistent with the localization parameters on my machine.  We have two other date fields on the form where the user must type in the date. 
    As a test, I changed my machine to the UK parameters.  I then set up the language parameters of Business One for English(United Kingdom).  I changed the date format specifications in Business One so that its format is dd/mm/yy.  I then brought up the form and the field that is formatted by the above function arrived in the form's field as dd/mm/yy.  I then typed in the two other dates in the same format and added the record to the database.  The form's table is user-defined. 
    I dismissed the form then brought it back up loaded with the new record.  The date that was entered by the function appeared in USA format (mm/dd/yy).  The dates that were typed in appeared in the Business One format (dd/mm/yy).  This of course is not consistent.
    When I looked at what got into the database, the formats were the opposite.  Weird!  To make matters really confusing, I run an SQL statement within SQL Server Mgt Studio, and use the WHERE clause to filter on the date that was based on the function.  It didn’t matter what format I used for the WHERE clause, the record came up.  Does anyone have any idea about how I can ensure that I always use the correct date format for SQL statements passed by Business One to SQL Server regardless of where in the world the application is being run?
    Thanks,
    Mike

    Ian,
    Here's what I'm concerned about:  I’m using the date in a “WHERE” clause.
    Assume the date is Aug 3, 2007.
    "SELECT * FROM Table WHERE StartDate > ‘8/3/2007’"
    OR
    "SELECT * FROM Table WHERE StartDate > ‘3/8/2007’"
    If the client machine is set up as USA, the today function will provide the date as formatted in the first query.  If the database server is setup as let’s say the UK, I believe that SQL Server query parser will interpret the date as Mar 8, 2007.
    If the client machine is set up as UK, the today function will provide the date as formatted in the second query.  If the database server is setup as let’s say USA, I believe that SQL Server query parser will also interpret the date as Mar 8, 2007.
    In both cases it would be wrong.
    I know I could use the DATEPART function to get the three parts and this will make the code indifferent to the localization specs of the client machine.  I need to then be able to concatenate those date parts for the “WHERE” clause so that the localization specifications of the database server don’t matter.
    Thanks,
    Mike

  • How to write statement using LIKE statement in jsp

    hi
    I am new to jsp. I would like to retrive the data from database using like command. But my query dosen't work well. Can you help me in this topic.
    String name = request.getParameter("username");
    int i = st.executeQuery("select * from emp where empname LIKE '%name%'");
    Plase help me..
    Thanking you
    sure...

    Using LIKE :
    ==========
    The following SQL statement will return persons with first names that start with an 'O':
    SELECT * FROM Persons
    WHERE FirstName LIKE 'O%'
    The following SQL statement will return persons with first names that contain the pattern 'la':
    SELECT * FROM Persons
    WHERE FirstName LIKE '%la%'
    Hope this might have helped you
    REGARDS,
    RaHuL

  • Using LIKE and IN at the same time

    Is it possible to use both LIKE and IN at the same time such as:
    select first_name from emp where user_id LIKE IN('1%','2%')
    Thanks in advance
    --Joshua                                                                                                                                                                                                                                                                                                                                   

    Or consider the IN - parameters as a string. Then you can do the following:
    SQL> SELECT ename
      FROM emp
    WHERE EXISTS (
              SELECT NULL
                FROM (SELECT RTRIM (SUBSTR (nums,
                                            INSTR (nums, ',', 1, iter.pos) + 1,
                                              INSTR (nums, ',', 1, iter.pos + 1)
                                            - INSTR (nums, ',', 1, iter.pos)
                                   ) nums
                        FROM (SELECT ',' || 'SCO,BLA,CLA' || ',' nums
                                FROM DUAL) csv,
                             (SELECT ROWNUM pos
                                FROM all_objects
                               WHERE ROWNUM < 50) iter
                       WHERE iter.pos <=
                                  (  (  LENGTH (csv.nums)
                                      - LENGTH (REPLACE (csv.nums, ','))
                                   / LENGTH (',')
                                - 1)
               WHERE ename LIKE '%' || nums || '%')
    ENAME    
    BLAKE    
    CLARK    
    SCOTT    
    3 rows selected.

  • Issue while importing table from oracle to sql server using import and export wizard

    Hi All,
    I am trying to populate oracle table to sql server using import export wizard  and i am getting the below error.the table is allready present in the database but still it throwing error like table doesn't exists.
    Could not connect source component.
    Error 0xc0202009: Source - JOB_ACTION_HISTORY [1]: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80004005.
    Error 0xc02020e8: Source - JOB_ACTION_HISTORY [1]: Opening a rowset for ""FLXUSER"."JOB_ACTION_HISTORY"" failed. Check that the object exists in the database.
     (SQL Server Import and Export Wizard)
    Kindly help me out
    Thanks in advance

    Hi Snehasis,
    Please check whether the table name in the Oracle database has lower case letters. The table name should be exactly correct. 
    In addition, the issue might be related to the Oracle driver. What provider/driver do you use? If you use Microsoft OLE DB Provider for Oracle, you can try the
    Oracle OLE DB Provider. If you use Enterprise or Developer edition of SSIS 2008 or higher, you can also try the
    Microsoft Connectors for Oracle by Attunity. The  Oracle OLE DB Provider and Microsoft Connectors for Oracle are proved to have better performance.
    Regards,
    Mike Yin
    TechNet Community Support

  • How to execute the *.sql when using occi  and vc

    help me!
    i must to initialize the remote database using the file of sql,
    for example:
    the file is ss.sql;
    and it is
    "DECLARE
    row integer := 0;
    user varchar2(256);
    BEGIN
    user := '&1';
    dbms_java.grant_policy_permission('PUBLIC', 'SYS',
    'java.lang.RuntimePermission', 'loadLibrary.*', row);
    dbms_java.grant_permission(user, 'SYS:java.lang.RuntimePermission',
    'loadLibrary.orawcom10', null);
    dbms_java.disable_permission(row);
    dbms_java.delete_permission(row);
    EXCEPTION
    WHEN OTHERS THEN
    IF row > 0 THEN
    dbms_java.disable_permission(row);
    dbms_java.delete_permission(row);
    END IF;
    RAISE;
    END;"
    i use the occi statement
    Environment * env;
    Connection * conn;
    Statement * stmt;
    env=Environment::createEnvironment(Environment::DefaultEnvironment);
    conn=env->createConnect(user_name,pwd,db_name);
    string sqlstmt=''BEGIN ss.sql;END";
    stmt=conn->createStatement(sqlstmt);
    it is wrong
    how do i change the sql statement???

    Hi,
    Instead of having the PL/SQL code as an anonymous block, you can create
    a procedure and then execute it through OCCI.
    For example:
    create or replace procedure my_proc
    is
    row integer := 0;
    user varchar2(256);
    begin
    --code here...
    end;
    I assume this code will be in ss.sql. Compile this procedure in
    your schema and then form the sqlstmt in OCCI this way:
    Statement *stmt = con->createStatement("BEGIN my_proc; END;") ;
    Rgds.
    Amogh

  • High-load sql statement using v$sql

    Hi,
    Can any one please tell me, how do we find high load sql statement and it's user from v$SQL view.
    what is the query to find it.
    Thank you!

    Hello,
    You can run ADDM report and check its findings it will tell you tome stuff like the following:
         Finding
    67      SQL statements consuming significant database time were found.
    40.7      Time spent on the CPU by the instance was responsible for a substantial part of database time.
    20.7      Individual SQL statements responsible for significant user I/O wait were found.
    13.7      Individual database segments responsible for significant user I/O wait were found.Kind regards
    Mohamed Elazab

  • How to monitor perticuler sql statement using the INDEX or not?

    I am running on a long running quary, and the output is comming very late. So i want to know the sql quary is using the index or not? How to know that?

    If you want to check the real execution plan of a running query without waiting for query completion, you can try following steps that you should adapt to your query and your environment:
    1. start the query
    select
    count(*)
    from all_objects, all_objects;2. Retrieve in another session the SQL_ID and the CHILD_NUMBER of the running query:
    select sql_id, child_number, sql_text
    from v$sql
    where sql_text like '%all_objects%';3. use DBMS_XPLAN.DISPLAY_CURSOR to get the real execution plan from shared pool using SQL_ID and CHILD_NUMBER from step 2:
    select * from table(dbms_xplan.display_cursor(<sql_id>,<child_number>));Actually you don't need to restart the query if it is already running because the hint GATHER_PLAN_STATISTICS is only needed if you want to have current execution statistics.
    Edited by: P. Forstmann on 2 mars 2011 10:23

Maybe you are looking for

  • How can I make my iPhone "forget" some email addresses

    When I draft a message, a suggestion list appears of email addresses I've recently sent emails to. How do I make my phone forget them? I don't want them to appear! I've tried deleting my mail account and starting over, and yet they still are there. I

  • How do I change the advertised RD Gateway server?

    I have a 2012 R2 server that I setup RD Gateway services and setup RemoteApp.  Internally it all works fine.  The problem is the company was a branch of another company then bought out.  So the internal domain name is a .com that matches a different

  • How to install joomla on IIS (windows 2012)

    When one starts IIS, it immidiatly starts the webinstaller to choose a product and configure it. I've been working now several days trying to install Joomla  , tried it dozens of times. At first it wouldn't install at all, kept hanging in the first p

  • Plz increase performance of this report

    hi all i want to know how can i improve the performance of my report. the code is given below and it takes so much time on production even for single record plz help HERE COMES THE CODE *& Report  ZGRSTATUS REPORT  ZGRSTATUS. TYPE-POOLS slis. TABLES:

  • Image scaling problem

    Hello, I have been trying to scale an image to create a thumbnail. The thumbnail image size is around 200*200. The thumbnail is to be rendered on a web browser. My code is: public static byte[] getScaledImage(InputStream imageData) throws IOException