Executing a merge query for a collection

Hello All,
I am trying to use a merge query to find common and uncommon ids between a table and a list I pass to my pl-sql proc. I am not sure if I am doing the right thing, please guide me...
Here is my code...
Procedure process_content(i_eidlist IN ocs_eid_list_t, i_id IN number, o_new_email_list OUT ocs_eid_list_t) AS
lv_last_processed_row_id number;
lv_common_email_list ocs_eid_list_t;
lv_internet_id varchar2;
Begin
lv_last_processed_row_id := 0;
MERGE INTO table c
USING TABLE(i_eidlist)a
ON (c.eid in a)
--WHEN MATCHED THEN UPDATE SET c.row_id = job_no_seq.NEXTVAL,c.copy_count=1 returning row_id bulk collect into lv_row_id_list;
WHEN MATCHED THEN SELECT c.eid bulk collect into lv_common_email_list returning row_id bulk collect into lv_row_id_list
WHEN NOT MATCHED THEN SELECT c.eid bulk collect into o_new_email_list;
I am assuming that the merge query is going to iterate over the i_eidlist, and find me the common and uncommon elements. However, I get an error saying the sql block is ignored.
Thanks
Abhishek
글 수정: A.J.

I do not think it is possible in one pass. The best I could come up with:
DECLARE
    COMMON_LIST NAME_LIST;
    UNCOMMON_LIST NAME_LIST;
    EMPLOYEE_LIST NAME_LIST;
    CHECK_LIST NAME_LIST := NAME_LIST('KING','QUEEN');
BEGIN
    SELECT  ENAME
      BULK COLLECT INTO EMPLOYEE_LIST
      FROM  EMP;
    COMMON_LIST := EMPLOYEE_LIST MULTISET INTERSECT CHECK_LIST;
    UNCOMMON_LIST := EMPLOYEE_LIST MULTISET EXCEPT CHECK_LIST;
DBMS_OUTPUT.PUT_LINE('-- COMMON_LIST --');
FOR i IN 1..COMMON_LIST.COUNT LOOP
  DBMS_OUTPUT.PUT_LINE(COMMON_LIST(i));
END LOOP;
DBMS_OUTPUT.PUT_LINE('-- UNCOMMON_LIST --');
FOR i IN 1..UNCOMMON_LIST.COUNT LOOP
  DBMS_OUTPUT.PUT_LINE(UNCOMMON_LIST(i));
END LOOP;
END;
/Run results showing contents:
SQL> DECLARE
  2      COMMON_LIST NAME_LIST;
  3      UNCOMMON_LIST NAME_LIST;
  4      EMPLOYEE_LIST NAME_LIST;
  5      CHECK_LIST NAME_LIST := NAME_LIST('KING','QUEEN');
  6  BEGIN
  7      SELECT  ENAME
  8        BULK COLLECT INTO EMPLOYEE_LIST
  9        FROM  EMP;
10      COMMON_LIST := EMPLOYEE_LIST MULTISET INTERSECT CHECK_LIST;
11      UNCOMMON_LIST := EMPLOYEE_LIST MULTISET EXCEPT CHECK_LIST;
12  DBMS_OUTPUT.PUT_LINE('-- COMMON_LIST --');
13  FOR i IN 1..COMMON_LIST.COUNT LOOP
14    DBMS_OUTPUT.PUT_LINE(COMMON_LIST(i));
15  END LOOP;
16  DBMS_OUTPUT.PUT_LINE('-- UNCOMMON_LIST --');
17  FOR i IN 1..UNCOMMON_LIST.COUNT LOOP
18    DBMS_OUTPUT.PUT_LINE(UNCOMMON_LIST(i));
19  END LOOP;
20  END;
21  /
-- COMMON_LIST --
KING
-- UNCOMMON_LIST --
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
TURNER
ADAMS
JAMES
FORD
MILLER
PL/SQL procedure successfully completed.
SQL> SY.

Similar Messages

  • Error while executing a sql query for select

    HI All,
    ORA-01652: unable to extend temp segment by 128 in tablespace PSTEMP i'm getting this error while i'm executing the sql query for selecting the data.

    I am having 44GB of temp space, while executing the below query my temp space is getting full, Expert please let us know how the issue can be resolved..
    1. I dont want to increase the temp space
    2. I need to tune the query, please provide your recomendations.
    insert /*+APPEND*/ into CST_DSA.HIERARCHY_MISMATCHES
    (REPORT_NUM,REPORT_TYPE,REPORT_DESC,GAP,CARRIED_ITEMS,CARRIED_ITEM_TYPE,NO_OF_ROUTE_OF_CARRIED_ITEM,CARRIED_ITEM_ROUTE_NO,CARRIER_ITEMS,CARRIER_ITEM_TYPE,CARRIED_ITEM_PROTECTION_TYPE,SOURCE_SYSTEM)
    select
    REPORTNUMBER,REPORTTYPE,REPORTDESCRIPTION ,NULL,
    carried_items,carried_item_type,no_of_route_of_carried_item,carried_item_route_no,carrier_items,
    carrier_item_type,carried_item_protection_type,'PACS'
    from
    (select distinct
    c.REPORTNUMBER,c.REPORTTYPE,c.REPORTDESCRIPTION ,NULL,
    a.carried_items,a.carried_item_type,a.no_of_route_of_carried_item,a.carried_item_route_no,a.carrier_items,
    a.carrier_item_type,a.carried_item_protection_type,'PACS'
    from CST_ASIR.HIERARCHY_asir a,CST_DSA.M_PB_CIRCUIT_ROUTING b ,CST_DSA.REPORT_METADATA c
    where a.carrier_item_type in('Connection') and a.carried_item_type in('Service')
    AND a.carrier_items=b.mux
    and c.REPORTNUMBER=(case
    when a.carrier_item_type in ('ServicePackage','Service','Connection') then 10
    else 20
    end)
    and a.carrier_items not in (select carried_items from CST_ASIR.HIERARCHY_asir where carried_item_type in('Connection') ))A
    where not exists
    (select *
    from CST_DSA.HIERARCHY_MISMATCHES B where
    A.REPORTNUMBER=B.REPORT_NUM and
    A.REPORTTYPE=B.REPORT_TYPE and
    A.REPORTDESCRIPTION=B.REPORT_DESC and
    A.CARRIED_ITEMS=B.CARRIED_ITEMS and
    A.CARRIED_ITEM_TYPE=B.CARRIED_ITEM_TYPE and
    A.NO_OF_ROUTE_OF_CARRIED_ITEM=B.NO_OF_ROUTE_OF_CARRIED_ITEM and
    A.CARRIED_ITEM_ROUTE_NO=B.CARRIED_ITEM_ROUTE_NO and
    A.CARRIER_ITEMS=B.CARRIER_ITEMS and
    A.CARRIER_ITEM_TYPE=B.CARRIER_ITEM_TYPE and
    A.CARRIED_ITEM_PROTECTION_TYPE=B.CARRIED_ITEM_PROTECTION_TYPE
    AND B.SOURCE_SYSTEM='PACS'
    Explain Plan
    ==========
    Plan
    INSERT STATEMENT ALL_ROWSCost: 129 Bytes: 1,103 Cardinality: 1                                                        
         20 LOAD AS SELECT CST_DSA.HIERARCHY_MISMATCHES                                                   
              19 PX COORDINATOR                                              
                   18 PX SEND QC (RANDOM) PARALLEL_TO_SERIAL SYS.:TQ10002 :Q1002Cost: 129 Bytes: 1,103 Cardinality: 1                                         
                        17 NESTED LOOPS PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 129 Bytes: 1,103 Cardinality: 1                                    
                             15 HASH JOIN RIGHT ANTI NA PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 129 Bytes: 1,098 Cardinality: 1                               
                                  4 PX RECEIVE PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 63 Bytes: 359,283 Cardinality: 15,621                          
                                       3 PX SEND BROADCAST PARALLEL_TO_PARALLEL SYS.:TQ10001 :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621                     
                                            2 PX BLOCK ITERATOR PARALLEL_COMBINED_WITH_CHILD :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621                
                                                 1 MAT_VIEW ACCESS FULL MAT_VIEW PARALLEL_COMBINED_WITH_PARENT CST_ASIR.HIERARCHY :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621           
                                  14 NESTED LOOPS ANTI PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 65 Bytes: 40,256,600 Cardinality: 37,448                          
                                       11 HASH JOIN PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 65 Bytes: 6,366,160 Cardinality: 37,448                     
                                            8 BUFFER SORT PARALLEL_COMBINED_WITH_CHILD :Q1002               
                                                 7 PX RECEIVE PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 1 Bytes: 214 Cardinality: 2           
                                                      6 PX SEND BROADCAST PARALLEL_FROM_SERIAL SYS.:TQ10000 Cost: 1 Bytes: 214 Cardinality: 2      
                                                           5 INDEX FULL SCAN INDEX CST_DSA.IDX$$_06EF0005 Cost: 1 Bytes: 214 Cardinality: 2
                                            10 PX BLOCK ITERATOR PARALLEL_COMBINED_WITH_CHILD :Q1002Cost: 63 Bytes: 2,359,224 Cardinality: 37,448                
                                                 9 MAT_VIEW ACCESS FULL MAT_VIEW PARALLEL_COMBINED_WITH_PARENT CST_ASIR.HIERARCHY :Q1002Cost: 63 Bytes: 2,359,224 Cardinality: 37,448           
                                       13 TABLE ACCESS BY INDEX ROWID TABLE PARALLEL_COMBINED_WITH_PARENT CST_DSA.HIERARCHY_MISMATCHES :Q1002Cost: 0 Bytes: 905 Cardinality: 1                     
                                            12 INDEX RANGE SCAN INDEX PARALLEL_COMBINED_WITH_PARENT SYS.HIERARCHY_MISMATCHES_IDX3 :Q1002Cost: 0 Cardinality: 1                
                             16 INDEX RANGE SCAN INDEX PARALLEL_COMBINED_WITH_PARENT CST_DSA.IDX$$_06EF0001 :Q1002Cost: 1 Bytes: 5 Cardinality: 1

  • Executing the saved query for views -Need Help

    How can i run get the query for the saved search in views and execute it to view the results ?Can some one help on this pl
    Thanks!

    Hi,
    I am not able to get your requirement. Share in little details.
    As of my understanding, you want to get the query which is being executed.
    Regards,
    Gyan

  • Error executing filter in query using a Collection as a parameter

    Hi,
    I am getting a null pointer exception when executing my query. When it
    gets to Kodo it looks like the following:
    Filter -
    ((emailView._email._text.ext:stringContains(keyword)
    || emailView._email._subject.ext:stringContains(keyword))
    && (folders.contains(emailFolder) &&
    emailFolder._views.contains(emailView)))
    variables - com.mail.data.EmailView emailView;com.mail.data.EmailFolder
    emailFolder;
    ordering - (there is no ordering)
    imports - import java.util.Collection;import
    com.mail.data.EmailFolder;import com.mail.data.EmailMessage;
    parameters - java.lang.String keyword,java.util.Collection folders
    class/extent - com.mail.data.EmailView
    Basically I am trying to get all the EmailViews that contains an
    EmailMessage whose text or subject contains a keyword. The views
    returned should only be contained in certain folders which are passed as
    a parameter.
    So my object model is like this:
    EmailFolder -- 1 to many --> EmailView -- 1 to 1 --> EmailMessage
    I tried the following filter first which works:
    (_email._text.ext:stringContains(keyword)
    || email.subject.ext:stringContains(keyword))
    But when I try filtering with the folders it throws a
    NullPointerException. The folders passed to the filter are valid, and
    contain valid EmailViews, and those EmailViews contain valid
    EmailMessages that have non-null text and subject fields.
    The following is the relevant part of the stack trace:
    javax.jdo.JDOUserException: The given filter/ordering String
    "((emailView._email._text.ext:stringContains(keyword) ||
    emailView._email._subject.ext:stringContains(keyword)) &&
    (folders.contains(emailFolder) &&
    emailFolder._views.contains(emailView)))" is not valid. Make sure all
    parentheses are properly matched and that the filter uses proper Java
    syntax.
    NestedThrowables:
    java.lang.NullPointerException
    at com.solarmetric.kodo.query.FilterParser.evaluate(UnknownSource)
    at
    com.solarmetric.kodo.query.QueryImpl.getExpression(UnknownSource)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.JDBCQuery.getExpression(UnknownSource)
    at
    com.solarmetric.kodo.query.QueryImpl.executeWithMap(UnknownSource)
    at
    com.solarmetric.kodo.query.QueryImpl$SynchronizedQuery.executeWithMap(Unknown
    Source)
    NestedThrowablesStackTrace:
    java.lang.NullPointerException
    at
    com.solarmetric.kodo.impl.jdbc.runtime.JDBCExpressionFactory$PathImpl.<init>(Unknown
    Source)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.JDBCExpressionFactory.getPath(Unknown
    Source)
    at com.solarmetric.kodo.query.FilterParser.eval(Unknown Source)
    at com.solarmetric.kodo.query.FilterParser.getValue(UnknownSource)
    at com.solarmetric.kodo.query.FilterParser.eval(Unknown Source)
    at com.solarmetric.kodo.query.FilterParser.getValue(UnknownSource)
    at com.solarmetric.kodo.query.FilterParser.eval(Unknown Source)
    at
    com.solarmetric.kodo.query.FilterParser.getExpression(UnknownSource)
    at com.solarmetric.kodo.query.FilterParser.eval(Unknown Source)
    at
    com.solarmetric.kodo.query.FilterParser.getExpression(UnknownSource)
    at com.solarmetric.kodo.query.FilterParser.eval(Unknown Source)
    at
    com.solarmetric.kodo.query.FilterParser.getExpression(UnknownSource)
    at com.solarmetric.kodo.query.FilterParser.evaluate(UnknownSource)
    at
    com.solarmetric.kodo.query.QueryImpl.getExpression(UnknownSource)
    at
    com.solarmetric.kodo.impl.jdbc.runtime.JDBCQuery.getExpression(UnknownSource)
    at
    com.solarmetric.kodo.query.QueryImpl.executeWithMap(UnknownSource)
    at
    com.solarmetric.kodo.query.QueryImpl$SynchronizedQuery.executeWithMap(UnknownSource)
    Thanks in advance,
    Khamsouk

    As the exception said, this is not a valid query string.
    What happens if you do:
    folders.contains(emailFolder) &&
    emailFolder._views.contains(emailView) &&
    (emailView._email._text.ext:stringContains(keyword) ||
    emailView._email._subject.ext:stringContains(keyword))
    The point here is that a 'relation.contains(var)' statement must be
    followed by '&& something that uses the var'.
    -Fred
    Khamsouk Souvanlasy <[email protected]> wrote:
    Filter -
    ((emailView._email._text.ext:stringContains(keyword)
    || emailView._email._subject.ext:stringContains(keyword))
    && (folders.contains(emailFolder) &&
    emailFolder._views.contains(emailView)))
    variables - com.mail.data.EmailView emailView;com.mail.data.EmailFolder
    emailFolder;--
    Fred Lucas
    SolarMetric Inc.
    202-595-2064 x1122
    http://www.solarmetric.com

  • Executing Native SQL query for oracle

    Hi,
    I want to run following native sql query but it is giving me error ora:933,
    DATA: BEGIN OF WA,
          TSP_NAME(255) TYPE C,
          PER_USAGE(10) TYPE C,
          END OF WA.
    EXEC SQL PERFORMING loop_output.
    select t.tablespace_name,'(' || TO_CHAR(ROUND(100*(NVL(b.bytes,0)/NVL(a
    .bytes,0)))) || '%)' "TSUsed%" from dba_tablespaces t,
    ( select tablespace_name, sum(bytes)/1024/1024 bytes
    from dba_data_files group by tablespace_name) a,
    ( select e.tablespace_name, sum(e.bytes)/1024/1024 bytes
    from dba_extents e group by e.tablespace_name ) b,
    ( select f.tablespace_name, sum(f.bytes)/1024/1024 bytes
    from dba_free_space f group by f.tablespace_name ) c
    where t.tablespace_name = a.tablespace_name(+) and
    t.tablespace_name = b.tablespace_name(+) and
    t.tablespace_name = c.tablespace_name(+) into :wa.
    ENDEXEC.
    Please provide me the soln
    Regards,
    Bharat Mistry

    ORA-00933: SQL command not properly ended.
    Try:
    EXEC SQL PERFORMING loop_output.
    select
    into :wa
    ENDEXEC.
    (No "." at the end). If that doesn't work, try ending it with a ";"
    Rob

  • Merge query error in Where clause

    Following error is coming when i execute the merge query. Anything wrong with this? I am using Oracle 9.2.0.1.
    Query:
    MERGE
         INTO incompletekalls ic
         USING live_small ls
         ON ((ls.callid = ic.callid) AND
         (ls.sdate = ic.sdate) AND
         (ls.stime = ic.stime))
    WHEN MATCHED THEN
         UPDATE
         SET     ic.adate = ls.adate,
              ic.atime = ls.atime,
              ic.edate = ls.edate,
              ic.etime = ls.etime
         WHERE
              ls.sdate = '16-Apr-09' AND ls.stime >= '09:00:00' AND ls.stime <= '11:00:00' AND ((ls.adate IS NULL) OR
              (ls.edate IS NULL))
    WHEN NOT MATCHED THEN
         INSERT (ic.callid,ic.cg,ic.cd,ic.re,ic.opc,ic.dpc,ic.sdate,ic.stime,ic.adate,ic.atime,ic.edate,ic.etime)
         VALUES (ls.callid,ls.cg,ls.cd,ls.re,ls.opc,ls.dpc,ls.sdate,ls.stime,ls.adate,ls.atime,ls.edate,ls.etime)
         WHERE ls.sdate >= '16-Apr-09' AND ls.stime >= '09:00:00' AND ls.stime <= '11:00:00'
    Error:
    SQL> /
    WHERE
    ERROR at line 13:
    ORA-00905: missing keyword

    Hi,
    From looking at the documented examples
    http://www.oracle.com/pls/db92/db92.drilldown?levelnum=2&toplevel=a96540&method=FULL&chapters=0&book=&wildcards=1&preference=&expand_all=&verb=&word=MERGE#a96540
    and on http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:5318183934935
    I think that you cannot use the WHERE in your MERGE like that on 9i...
    Something else I want to warn you for:
    It's a bad idea to store your date and time separated as strings! You'll run into troubles sooner or later, for 100%...
    Use a single DATE column instead, in which you store both the date and time components..

  • Oracle Merge query

    Hi ,
    I am writing a merge query for a Java application. I have a screen and I am going to take the values in the screen and check if those values exist in the database. If they exist, then I will have to update the data, else I will have to insert the data.
    The query is like
    MERGE INTO XYZ USING
    (SELECT BONUS_ID,CUST_NBR FROM XYZ)B ON
    (B.BONUS_ID = 2027 and B.CUST_NBR='181258225')
    WHEN MATCHED THEN UPDATE SET
    CUST_TYPE= 'S', REV_AMT= 123, POUND_TOTAL= 123, PKG_TOTAL= 123 WHERE
    CUST_NBR = '181258225'
    WHEN NOT MATCHED THEN INSERT
    But this query is not working. I get the "Missing Keyword"

    I meant nothing else
    update xyz set ... where ...;
    and
    insert into xyz select ... from xyz where ...;
    I wrote "When I check B.Bonus_ID it refers to the BonusID from XYZ table".
    Let me give you one example with SCOTT schema.
    I hope it illustrates well my concern of your
    statement:
    SQL> select ename, empno, sal from emp;
    &nbsp
    ENAME                     EMPNO        SAL
    SMITH                      7369        800
    ALLEN                      7499       1600
    WARD                       7521       1250
    JONES                      7566       2975
    MARTIN                     7654       1250
    BLAKE                      7698       2850
    CLARK                      7782       2450
    SCOTT                      7788       3000
    KING                       7839       5000
    TURNER                     7844       1500
    ADAMS                      7876       1100
    JAMES                      7900        950
    FORD                       7902       3000
    MILLER                     7934       1300
    &nbsp
    14 rows selected.
    &nbsp
    SQL> merge into emp using (select * from emp) b
      2  on (b.ename = 'KING')
      3  when matched then update set sal = 1000
      4  when not matched then insert (emp.empno, emp.ename, emp.deptno, emp.sal
      5  values(-b.empno, b.ename, b.deptno, 0)
      6  /
    &nbsp
    27 rows merged.
    &nbsp
    SQL> select ename, empno, sal from emp;
    &nbsp
    ENAME                     EMPNO        SAL
    SMITH                     -7369          0
    ALLEN                     -7499          0
    WARD                      -7521          0
    JONES                     -7566          0
    MARTIN                    -7654          0
    BLAKE                     -7698          0
    CLARK                     -7782          0
    SCOTT                     -7788          0
    TURNER                    -7844          0
    ADAMS                     -7876          0
    JAMES                     -7900          0
    FORD                      -7902          0
    MILLER                    -7934          0
    SMITH                      7369       1000
    ALLEN                      7499       1000
    WARD                       7521       1000
    JONES                      7566       1000
    MARTIN                     7654       1000
    BLAKE                      7698       1000
    CLARK                      7782       1000
    SCOTT                      7788       1000
    KING                       7839       1000
    TURNER                     7844       1000
    ADAMS                      7876       1000
    JAMES                      7900       1000
    FORD                       7902       1000
    MILLER                     7934       1000
    &nbsp
    27 rows selected.Rgds.

  • SCCM query for Windows 8 machines without software installed

    Would anyone be able to point me in the direction of an SCCM query for a collection that would list all Windows 8 machines without certain software installed?
    Thanks

    I have this query to for systems without software installed:
    select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,
    SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.
    ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System  
    inner join SMS_G_System_COMPUTER_SYSTEM on  
    SMS_G_System_COMPUTER_SYSTEM.ResourceID = SMS_R_System.ResourceId 
    where SMS_G_System_COMPUTER_SYSTEM.Name not in  
    (select SMS_G_System_COMPUTER_SYSTEM.Name from  SMS_R_System  
    inner join SMS_G_System_COMPUTER_SYSTEM on  
    SMS_G_System_COMPUTER_SYSTEM.ResourceID = SMS_R_System.ResourceId
    inner join SMS_G_System_ADD_REMOVE_PROGRAMS on  
    SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID =  
    SMS_R_System.ResourceId where SMS_G_System_ADD_REMOVE_PROGRAMS. 
    DisplayName like "%SOFTWARE%")
    The query works, but I would like to modify it so the query only includes certain versions of Windows. Any suggestions would be appreciated
    Thanks 

  • Collection query for computers with windows management framework 3.0

    Hi,
    collection query for computers with windows management framework 3.0, but I cant found a way. I cant see that it is in the inventory data for SMS_G_System_ADD_REMOVE_PROGRAMS_64.DisplayName.
    So any way to get computers with windows management framework 3.0?
    /SaiTech

    select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System inner join SMS_G_System_SoftwareProduct on SMS_G_System_SoftwareProduct.ResourceId
    = SMS_R_System.ResourceId where SMS_G_System_SoftwareProduct.ProductName like "Windows Management Framework 3.0%"
    That won't work because as mentioned, it doesn't appear in ARP.
    Torsten's suggestion will work or you can resort to software/hardware inventory using the info at
    http://serverfault.com/questions/555100/methods-to-detect-version-of-windows-management-framework
    Jason | http://blog.configmgrftw.com

  • Issue While executing the Query for Pagination using ROWNUM with like

    Issue While executing the Query for Pagination using ROWNUM with like.
    Database is Oracle11G.
    Oracle Database Table contains 8-9 lakh records
    1) SQL equal (=)
    SELECT /*+ FIRST_ROWS(n) */ ROWNUM RNUM, A.* FROM LINE A
    WHERE A.REFERENCE = 'KMF22600920'
    Execution Time:- 0.00869245 seconds
    Returns 2 resultsets
    2) SQL like (one %)
    SELECT /*+ FIRST_ROWS(n) */ ROWNUM RNUM, A.* FROM LINE A
    WHERE A.REFERENCE = 'KMF22600920%'
    Execution Time:- 0.01094301 seconds
    Returns 2 resultsets
    3) SQL like (two%)
    SELECT /*+ FIRST_ROWS(n) */ ROWNUM RNUM, A.* FROM LINE A
    WHERE A.REFERENCE like '%KMF22600920%'
    Execution Time:- 6.43989658 seconds
    Returns 2 resultsets
    In Pagination, we are using Modified version of SQL Query 3) with ROWNUM as mentioned below :-
    4) SELECT * FROM (
    SELECT /*+ FIRST_ROWS(n) */ ROWNUM RNUM, A.* FROM LINE A
    WHERE REFERENCE like '%KMF22600920%' AND ROWNUM <= 20 ) WHERE RNUM > 0
    Execution Time:- Infinite
    ResultSets:- No as execution time is infinite
    a) Instead of like if we use = in the above query it is returning the 2 resultsets (execution time 0.02699282 seconds)
    b) Instead of two % in the above query, if use one example REFERENCE like 'KMF22600920%' it is returning the 2 resultsets (execution time 0.03313019 seconds)
    Issue:- When using two % in like in the above query i.e. REFERENCE like '%KMF22600920%' AND ROWNUM <= 20 ) , it is going to infinite.
    Could you please let us know what is the issue with two % used in like and rownum
    5) Modified version of Option1 query (move out the RNUM condition AND RNUM <= 20)
    SELECT * FROM (
    SELECT /*+ FIRST_ROWS(n) */ ROWNUM RNUM, A.* FROM LINE A
    WHERE REFERENCE like '%KMF22600920%' ) WHERE RNUM > 0 AND RNUM <= 20
    Execution Time:- 7.41368914 seconds
    Returns 2 resultsets
    Is the above query is best optimized query which should be used for the Pagination or still can improve on this ?

    This would be easier to diagnose if there was an explain plan posted for the 'good' and 'bad' queries. Generally speaking using '%' on both sides precludes the use of any indexes.

  • Query for log Parser to get number of hits in a day or week for particular web applications or site collection

    Hi All,
    Want to get the number of hits in a day for a web application with IIS logs. so need to know Query for log Parser to get number hits in a day or week for particular web applications or site collection. Kindly help
    Regards,
    Naveen

    I'm trying to get this from WSS 3.0, Hence using the Log Parser

  • Query for collection "Quick Fix Engineering"

    Hi!
    I try to create query for collection,to find all workstation with install specific KB, from "Quick Fix Engineering".
    Added by this sample:
    http://myitforum.com/myitforumwp/2011/10/04/non-security-hotfix-detection-for-windows-7-2008/
    Maybe you can help? Can not find an example :(
    cenubit

    That's made a lot simpler in ConfigMgr 2012, as it can now simply be selected as an extra class in the
    Hardware Inventory of your client settings.
    Simply go in to your client settings, go to Hardware Inventory
    and click Set Classes. Here you can select the Quick Fix Engineering class to be part of your inventory.
    After an inventory you will be able to create your collection. Do keep in mind that this will also capture a lot of information that you will probably never use.
    My Blog: http://www.petervanderwoude.nl/
    Follow me on twitter: pvanderwoude

  • Query For Series wise Collection

    Hi
    Please anyone provide  query for series-wise collection

    Satish Doke,
    Im using this query as "Series Wise Outstanding" I want to create another  query for "series wise collection".How can  i do this.Im not into SAP accounting.Please help.
    DECLARE @Date AS DATETIME
    DECLARE @Series AS varchar(30)
    DECLARE @Branch AS varchar(30)
    DECLARE @Exec AS varchar(30)
    /* SELECT FROM [dbo].[OINV] S0 WHERE */ SET  @Date = /* S0.DocDate*/ '[%0]'
    /* SELECT FROM [dbo].[NNM1] S2 WHERE */ SET  @Series = /* S2.SeriesName*/ '[%2]'
    /* SELECT FROM [dbo].[OLCT] S3 WHERE */ SET  @Branch = /* S3.Location*/ '[%3]'
    /* SELECT FROM [dbo].[OSLP] S4 WHERE */ SET  @Exec = /* S4.SlpName*/ '[%4]'
    if( @Exec ='') set @Exec ='%'
    if( @Series ='') set @Series ='%'
    if( @Branch ='') set @Branch ='%'
    if( @Date ='') set @Date =GETDATE()
    Select distinct OINV.CardName [Customer Name], ISNULL(NNM1.SeriesName ,'-')+'/'+ CAST(OINV.DocNum as varchar) [Bill No.],
    OINV.DocDate [Bill Date],INV1.Dscription,INV1.Quantity,
    OINV.DocTotal - OINV.PaidToDate [Out Standing Amount],
    DATEDIFF(dd,OINV.DocDate,@Date)[No of Days]  from OINV
    inner join INV1 on OINV.DocEntry = INV1.DocEntry
    inner join OLCT on INV1.LocCode = OLCT.Code
    inner join NNM1 on OINV.Series = NNM1.Series
    inner join OSLP on OINV.SlpCode = OSLP.SlpCode 
    where OINV.DocType ='I' and (OINV.DocTotal - OINV.PaidToDate)>0
    and NNM1.SeriesName like @Series and OINV.DocDate<= @Date
    and OLCT.Location like @Branch and OSLP.SlpName like @Exec

  • Query for create manual tabular form using apex collection add row button functionality

    Hello everyone
    My requirement is i created a tabular form manually using apex collection but if i click on add row button then previously selected data refreshed and added new row in this form it is fine.but i don't want to refreshed previously selected data and click on add row button then add new row .how it is possible? plz help
    Thanks & Regards,
    Ujwala

    Ujwala
    Instead of starting a new thread with the same question as Query for create manual tabular form using apex collection add row button functionality.
    Could you answer the question about what you see while debug the javascript code.
    If you don't understand the question or have trouble debug javascript let us know.
    Nicolette

  • Issue with "read by other session" and a parallel MERGE query

    Hi everyone,
    we have run into an issue with a batch process updating a large table (12 million rows / a few GB, so it's not that large). The process is quite simple - load the 'increment' from a file into a working table (INCREMENT_TABLE) and apply it to the main table using a MERGE. The increment is rather small (usually less than 10k rows), but the MERGE runs for hours (literally) although the execution plan seems quite reasonable (can post it tomorrow, if needed).
    The first thing we've checked is AWR report, and we've noticed this:
    Top 5 Timed Foreground Events
    Event     Waits     Time(s)     Avg wait (ms)     % DB time     Wait Class
    DB CPU           10,086           43.82     
    read by other session     3,968,673     9,179     2     39.88     User I/O
    db file scattered read     1,058,889     2,307     2     10.02     User I/O
    db file sequential read     408,499     600     1     2.61     User I/O
    direct path read     132,430     459     3     1.99     User I/OSo obviously most of the time was consumed by "read by other session" wait event. There were no other queries running at the server, so in this case "other session" actually means "parallel processes" used to execute the same query. The main table (the one that's updated by the batch process) has "PARALLEL DEGREE 4" so Oracle spawns 4 processes.
    I'm not sure how to fix this. I've read a lot of details about "read by other session" but I'm not sure it's the root cause - in the end, when two processes read the same block, it's quite natural that only one does the physical I/O while the other waits. What really seems suspicious is the number of waits - 4 million waits means 4 million blocks, 8kB each. That's about 32GB - the table has about 4GB, and there are less than 10k rows updated. So 32 GB is a bit overkill (OK, there are indexes etc. but still, that's 8x the size of the table).
    So I'm thinking that the buffer cache is too small - one process reads the data into cache, then it's removed and read again. And again ...
    One of the recommendations I've read was to increase the PCTFREE, to eliminate 'hot blocks' - but wouldn't that make the problem even worse (more blocks to read and keep in the cache)? Or am I completely wrong?
    The database is 11gR2, the buffer cache is about 4GB. The storage is a SAN (but I don't think this is the bottleneck - according to the iostat results it performs much better in case of other batch jobs).

    OK, so a bit more details - we've managed to significantly decrease the estimated cost and runtime. All we had to do was a small change in the SQL - instead of
    MERGE /*+ parallel(D DEFAULT)*/ INTO T_NOTUNIFIED_CLIENT D /*+ append */
      USING (SELECT
          FROM TMP_SODW_BB) S
      ON (D.NCLIENT_KEY = S.NCLIENT_KEY AND D.CURRENT_RECORD = 'Y' AND S.DIFF_FLAG IN ('U', 'D'))
      ...(which is the query listed above) we have done this
    MERGE /*+ parallel(D DEFAULT)*/ INTO T_NOTUNIFIED_CLIENT D /*+ append */
      USING (SELECT
          FROM TMP_SODW_BB AND DIFF_FLAG IN ('U', 'D')) S
      ON (D.NCLIENT_KEY = S.NCLIENT_KEY AND D.CURRENT_RECORD = 'Y')
      ...i.e. we have moved the condition from the MERGE ON clause to the SELECT. And suddenly, the execution plan is this
    OPERATION                           OBJECT_NAME             OPTIONS             COST
    MERGE STATEMENT                                                                 239
      MERGE                             T_NOTUNIFIED_CLIENT
        PX COORDINATOR
          PX SEND                       :TQ10000                QC (RANDOM)         239
            VIEW
              NESTED LOOPS                                      OUTER               239
                PX BLOCK                                        ITERATOR
                  TABLE ACCESS          TMP_SODW_BB             FULL                2
                    Filter Predicates
                      OR
                        DIFF_FLAG='D'
                        DIFF_FLAG='U'
                  TABLE ACCESS          T_NOTUNIFIED_CLIENT       BY INDEX ROWID    3
                    INDEX               AK_UQ_NOTUNIF_T_NOTUNI    RANGE SCAN        2
                      Access Predicates
                        AND
                          D.NCLIENT_KEY(+)=NCLIENT_KEY
                          D.CURRENT_RECORD(+)='Y'
                      Filter Predicates
                        D.CURRENT_RECORD(+)='Y' Yes, I know the queries are not exactly the same - but we can fix that. The point is that the TMP_SODW_BB table contains 1639 rows in total, and 284 of them match the moved 'IN' condition. Even if we remove the condition altogether (i.e. 1639 rows have to be merged), the execution plan does not change (the cost increases to about 1300, which is proportional to the number of rows).
    But with the original IN condition (that turns into an OR combination of predicates) in the MERGE ON clausule, the cost suddenly skyrockets to 990.000 and it's damn slow. It seems like a problem with cost estimation, because once we remove one of the values (so there's only one value in the IN clausule), it works fine again. So I guess it's a planner/estimator issue ...

Maybe you are looking for

  • Movies in my iMac's iTunes do not show up Apple TV(1st Gen)

    So frustrated. Movies in my iMac's iTunes do not show up on my Apple TV(1st Gen) in the Shared Movie area. I've done the Media Type fix to "movie." I've re-started and re-booted and changed the Apple TV from ethernet to wireless and re-connected iTun

  • T440s with Windows 8.1 (and BitLocker) - 1 ot of 3 times gets black screen when booting

    We have a case on a machine with original "Lenovo Windows 8" installed. Windows updated to 8.1 and the latest patches. System update is up to date. Aprox 1 out of 3 times, when booting, after entering the BitLocker PIN, the Windows loading screen is

  • Using Apple TV Without Internet?

    I have successfully set up my Apple TV2 by logging into my iTunes account. Now I would like to take it with me on vacation, and use with AirPlay to run videos off my iPad on the HD TV where we're staying. Is it possible to run AirPlay without having

  • Does the Weblogic Admin server need to be running after initial Connection?

    Initially, I require a login to the Weblogic Admin Server.via my code I am using JMX to monitor weblogic and all works great..I am trying to close the Admin Server and code blows up. Do I need the Admin Server running all the time? Do you know of a w

  • Cannot print to wireless HP 7280 with Time Capsule

    I just put up Time Capsule. My windows and mac machines are able to hook into the wireless router portion with no problem. My main problem is that I cannot print to my HP7280 wireless printer. I had a belkin wireless router that I replaced with the T