Native SQL query - Need help

Hi All,
We have a native SQL query accessing Oracle database(given below).
Can anyone please let me know what this query is about and how can we fine tune the query?
SELECT O.OBJECT_NAME ,
               H.SID,
               HS.MACHINE,
               HS.PROCESS,
               W.SID,
               WS.MACHINE,
               WS.PROCESS,
               H.CTIME,
               W.CTIME,
               WS.ROW_WAIT_OBJ#,
               WS.ROW_WAIT_FILE#,
               WS.ROW_WAIT_BLOCK#,
               WS.ROW_WAIT_ROW#,
               HP.SPID,
               WP.SPID
        FROM V$LOCK H, V$LOCK W, V$LOCK I, V$LOCK I2, ALL_OBJECTS O,
             V$SESSION HS, V$SESSION WS, V$PROCESS HP, V$PROCESS WP
        WHERE   H.ID1 = W.ID1
        AND     H.SID <> W.SID
        AND     H.TYPE IN ('TX','DL')
        AND     H.REQUEST = 0
        AND     H.SID = I.SID
        AND     I.TYPE = 'TM'
        AND     I.ID1 = O.OBJECT_ID
        AND     I.ID1 = I2.ID1
        AND     W.SID = I2.SID
        AND     I2.TYPE = 'TM'
        AND     H.SID = HS.SID
        AND     W.SID = WS.SID
        AND     HS.PADDR = HP.ADDR
        AND     WS.PADDR = WP.ADDR
        INTO :EXCL_LOCK_WAITERS-OBJ_NAME   ,
             :EXCL_LOCK_WAITERS-HOLDER_SID ,
             :EXCL_LOCK_WAITERS-H_HOSTNAME ,
            :EXCL_LOCK_WAITERS-HOLDER_PID ,
             :HOLDER_PID ,
             :EXCL_LOCK_WAITERS-WAITER_SID ,
             :EXCL_LOCK_WAITERS-W_HOSTNAME ,
            :EXCL_LOCK_WAITERS-WAITER_PID ,
             :WAITER_PID ,
             :EXCL_LOCK_WAITERS-HELD_SINCE ,
             :EXCL_LOCK_WAITERS-WAITSSINCE,
             :ROW_WAIT_OBJ,
             :ROW_WAIT_FILE,
             :ROW_WAIT_BLOCK,
             :ROW_WAIT_ROW,
             :H_PROCESS,
             :W_PROCESS
      ENDEXEC
Thanks in advance.
Neethu Mohan

Hi Neethu,
It gives you an overwiew of blocking Oracle sessions.
1. In general, the SQL checks Oracle sessions (SID's) that were requirering a DML lock ('TM') and now holding row locks (TX)  to prevent destructive interference of simultaneous conflicting DML or DDL operations. DML statements automatically acquire both table-level locks and row-level locks ('TX')  => holders
It joins these with the sessions that are waiting of releasing the lock by the holders  => waiters.
2. it retrieves the detail information wich  Oracle process , the object (table) , it's row , block  and file
are affected by the locks.
3. Normally, the locks are only hold for a short period of time. If you have blocking sessions it may be of a log running task (i.e. mass data update of a table) ; but it could also be a application bug due to improper handling of concurrent updates of the same object.
4. Tuning
V$tables are expensive to query: Why?
v$ tables are generally Oracle memory structures.
v$ tables are not read consistent.
v$ tables require latches to access -- cannot modify and read memory at the same
time.
heavy access to v$ tables like this may cause some serious heavy duty contention.
Especially if you self join V$lock several times.
So the best would be to save the contents of V$LOCK in some table:
Create table mylocks as select * from v$lock;
Use that table for self-joining and joins to the other tables.
You can also CTAS the other v$ tables to bypass the performance bottleneck while retrieving
v$ directly.
You can empty or drop the created tables any time for new data.
Because you want to investigate only lock hold for a longert time  to copy the v$ memory structures into
physical tables is not a disadvantage. You certainly will wait longer on finishing your query
instead of copy them into the tables.
Hope this helped
yk

Similar Messages

  • Mapping Problem with Native SQL query

    My application uses a native SQL query to locate certain entities. It looks like this:
    SELECT UPLOADATTEMPTREF, STUDENTNUMBER, USERID, WORKITEMCODE, WORKITEMINSTURN, WORKITEMTITLE, MODULERUNCODE, STUDENTNAME, SUBMISSIONDEADLINE, UPLOADATTEMPTSERVERDATE, FILENAME, UPLOADCOMPLETESERVERDATE, NEWFILENAME, FILESIZE, FILEPATH, DOWNLOADSERVERDATE, MODULECODE, MODULETITLE
    FROM Submission_Attempt WHERE UPLOADATTEMPTREF IN (
    SELECT uploadAttemptRef FROM (" +<br /><br />                         "SELECT MAX(uploadAttemptRef) AS uploadAttemptRef, UserID, workItemInstUrn, " +<br /><br />                         "workItemCode FROM Submission_Attempt where workiteminsturn = ?1 " +<br /><br />                         "GROUP BY UserID, workItemInstUrn, workItemCode) Table1 ) " +<br /><br />                         "and uploadCompleteServerDate is not null;"<br />
    My expectation was that EclipseLink would be able to handle the mapping of the results to the entity quite happily. However, I get a NonSynchronizedVector of Objects - each Object representing one field of data.
    I need help with either:
    Converting the above SQL into JPQL so that I (hopefully) don't have to worry about the SQL or
    Understanding why this isn't working properly...
    Anyone able to help?
    Edited by: phunnimonkey on Nov 6, 2008 3:33 AM

    Never mind - the problem was to do with not specifying a class when creating the native query.

  • Sql Query need to extract the Work Flow information from Hyperion Planning

    Can Any one give me the sql query to extract the Work flow from Hyperion Planning in 11.1.2.1.
    I can extract from the Hyperion Planning but it is not in required format again I need to do lot of formating. I need the information as per the flow structure is showing linke in one perticular planning unit in all coloumn format. Hence only sql query will help me to extract this kind of information. could any one provide the sql query to extract this kind of request.
    Thanks in Advance.
    Edited by: 987185 on Feb 9, 2013 10:57 PM

    If you have a look at the data models in - http://www.oracle.com/technetwork/middleware/bi-foundation/epm-data-models-11121-354684.zip
    There is the structure of the planning application tables, have a look at the HSP_PM_* tables
    Alternatively you can look at extracting the information using LCM.
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • SQL query needed to identify cancelled invoice where distribution lines

    SQL query needed to identify cancelled invoice where distribution lines Debit is not equal Credit line item in particular
    Is there a way from back end FROM ap_invoice_distributions_all where we can find for the cancelled invoice where distribution lines Debit is not equal Credit line item
    Regards,
    Prakash Ranjan

    Hello Prakash
    Can you please see if this query helps you?
    SELECT i.invoice_id, i.invoice_amount, nvl(sum(d.amount),0)
    FROM ap_invoice_distributions_all d, ap_invoices_all i
    WHERE i.org_id = <you org_id>
    AND i.invoice_id = d.invoice_id
    AND d.line_type_lookup_code not in ('PREPAY')
    AND i.cancelled_date IS NOT NULL
    GROUP BY i.invoice_id, i.invoice_amount
    HAVING (i.invoice_amount <> nvl(sum(d.amount),0))
    ORDER BY i.invoice_id asc
    Octavio

  • 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

  • Performance of native sql query detoriates

    Dear Experts,
    The performance of my native SQL query is bad. On the database the query takes less than 5 seconds to process. From my abap program I get a session timeout dump after 10 minutes. What might be the possible reason.
    Warm Regards,
    Abdullah

    I am not a DBA, but this is a wild guess.
    I have a native SQL query. It was running fine all morning(transported it to production today). By afternoon the report was not giving any output.
    I went to the MS SQL query analyzer and executed the query, it returned the results in less than 5 seconds. The same query when I was executing from SAP using native SQL took more than 10 minutes and gave a dump(time exceeded).
    My database guy asked me to execute the following on the database. Dbcc dbreindex('tablename')
    The report is running fine since then. I am still not satisfied if this is the reason the performance is back on track, but yeah the report is running fine again. There seems to be some problem with the indexes.
    I am using standard classes provided by SAP to execute my query and after execution the resultset reference object is being closed, I am closing the connection.
    the code is as below.
          PERFORM:
            connect               USING con_name con_ref,
            select_into_table     USING con_ref,
            disconnect            USING con_ref.
    *  FORM connect
    *  Connects to the database specified by the logical connection name
    *  P_CON_NAME which is expected to be specified in table DBCON. In case
    *  of success the form returns in P_CON_REF a reference to a connection
    *  object of class CL_SQL_CONNECTION.
    *  --> P_CON_NAME  logical connection name
    *  <-- P_CON_REF   reference to a CL_SQL_CONNECTION object
    FORM connect  USING    p_con_name TYPE dbcon-con_name
                           p_con_ref  TYPE REF TO cl_sql_connection
                           RAISING cx_sql_exception.
    * if CON_NAME is not initial then try to open the connection, otherwise
    * create a connection object representing the default connection.
      IF p_con_name IS INITIAL.
        CREATE OBJECT p_con_ref.
      ELSE.
        p_con_ref = cl_sql_connection=>get_connection( p_con_name ).
      ENDIF.
    ENDFORM.                    " connect
    *  FORM select_into_table
    *  Selects some rows from the test table and fetches the result rows
    *  into an internal table whose row structure corresponds to the
    *  queries select list columns.
    FORM select_into_table
      USING   p_con_ref TYPE REF TO cl_sql_connection
      RAISING cx_sql_exception.
      DATA:
        l_stmt         TYPE string,
        l_stmt_ref     TYPE REF TO cl_sql_statement,
        l_dref         TYPE REF TO data,
        l_res_ref      TYPE REF TO cl_sql_result_set,
    *Data related query
        l_itab         TYPE TABLE OF t_pricing_report,
        l_row_cnt      TYPE i.
    * create the query string
    CONCATENATE
        'select A.SEQ,A.CONDTABLE,A.CONDNAME,A.VKORG,A.VTWEG,A.MATKL,A.MATNR,B.MTEXT,A.VKGRP,A.SGRPNAME,'
        'A.VKBUR,A.SOFFNAME,A.ZSALES,A.SCNTNAME,A.KUNNR,A.SCSTNAME,A.PRBATCH,A.INCO1,'
        'A.INCO2,A.DATAB,A.DATBI,A.KBETR,A.KONWA,A.KOSRT,B.MTART,B.GROES,B.VOLUM,B.EXTWG,B.WRKST,'
        'A.MXWRT,A.GKWRT,'
        'B.PATTERN,B.RIM,B.SERIES,B.SPDINDEX,B.LDINDX,B.MGROUP,B.APPLN,B.SDWALL,B.MGRPTXT'
        'FROM Z_PRICELIST A,Z_MATERIALVIEW B'
        'WHERE A.MANDT = ? AND'
              'B.MANDT = A.MANDT AND'
              'A.MATNR = B.MATNR AND'
              'A.KSCHL = ? AND'
              'A.CONDTABLE LIKE ? AND'
              'A.VKORG LIKE ? AND'
              'A.VTWEG LIKE ? AND'
              'A.MATKL >= ? AND A.MATKL <= ? AND'
              'A.MATNR >= ? AND A.MATNR <= ? AND'
              'A.INCO1 LIKE ? AND'
              'A.INCO2 LIKE ? AND'
              'A.ZSALES >= ? AND A.ZSALES <= ? AND'
              'A.KUNNR  >= ? AND A.KUNNR <= ? AND'
              'A.PRBATCH  >= ? AND A.PRBATCH <= ? AND'
              'A.VKBUR  >= ? AND A.VKBUR <= ? AND'
              'A.VKGRP  >= ? AND A.VKGRP <= ? AND'
              'B.WRKST  >= ? AND B.WRKST <= ? AND'
              'B.MTART  >= ? AND B.MTART <= ? AND'
              '? BETWEEN A.DATAB AND A.DATBI AND'
              'B.GROES LIKE ? AND'
              'B.LDINDX LIKE ? AND'
              'B.SPDINDEX LIKE ? AND'
              'B.RIM LIKE ? AND'
              'B.SERIES LIKE ? AND'
              'B.PATTERN LIKE ? AND'
              'B.MGROUP LIKE ?'
              'order by A.MATNR'
        INTO l_stmt SEPARATED BY space.                         "#EC NOTEXT
    * create a statement object
      l_stmt_ref = p_con_ref->create_statement( ).
    * bind input variables
      GET REFERENCE OF l_col1 INTO l_dref.
      l_stmt_ref->set_param( l_dref ).
    *binding other references here
      GET REFERENCE OF l_col33 INTO l_dref.
      l_stmt_ref->set_param( l_dref ).
    * set the input values and execute the query
      l_col1  = sy-mandt.
    *..Assigning values here
      l_col33 = p_mgroup.
    *  PERFORM trace_2 USING 'EXECUTE_QUERY' l_stmt l_col1 l_col2.
      l_res_ref = l_stmt_ref->execute_query( l_stmt ).
    * set output table
      GET REFERENCE OF l_itab INTO l_dref.
      l_res_ref->set_param_table( l_dref ).
    * get the complete result set
      l_row_cnt = l_res_ref->next_package( ).
    * display the contents of the output table
    *  PERFORM trace_next_package USING l_itab.
    *  PERFORM trace_result USING l_row_cnt 'rows fetched'.
      pricing_report[] = l_itab[].
      free l_itab.
    * don't forget to close the result set object in order to free
    * resources on the database
      l_res_ref->close( ).
    ENDFORM.                    "select_into_table
    *  FORM disconnect
    *  Disconnect from the given connection. In case of the default
    *  connection this can be omitted.
    FORM disconnect
      USING   p_con_ref TYPE REF TO cl_sql_connection
      RAISING cx_sql_exception.
      DATA: l_con_name TYPE dbcon-con_name.
      l_con_name = p_con_ref->get_con_name( ).
      CHECK l_con_name <> cl_sql_connection=>c_default_connection.
    *  PERFORM trace_0 USING 'CLOSE CONNECTION' l_con_name.
      p_con_ref->close( ).
    *  PERFORM trace_result USING l_con_name 'closed'.
    ENDFORM.                    "disconnect
    *  FORM handle_sql_exception
    *  Write appropriate error messages when a SQL exception has occured
    *  -->  P_SQLERR_REF  reference to a CX_SQL_EXCEPTION object
    FORM handle_sql_exception
      USING p_sqlerr_ref TYPE REF TO cx_sql_exception.
      FORMAT COLOR COL_NEGATIVE.
      IF p_sqlerr_ref->db_error = 'X'.
        WRITE: / 'SQL error occured:', p_sqlerr_ref->sql_code,
               / p_sqlerr_ref->sql_message.                     "#EC NOTEXT
      ELSE.
        WRITE:
          / 'Error from DBI (details in dev-trace):',
            p_sqlerr_ref->internal_error.                       "#EC NOTEXT
      ENDIF.
    ENDFORM.                    "handle_sql_exception

  • Fetch join with Native SQL Query?

    Hello all,
    I am using the J2EE 5.0 persistence api with the SUN appserver v9. As the java persistence api does not yet support spatial queries ("... where contains(polygon, point)") I have to use native SQL queries for that purpose.
    Now my question is how can I "join fetch" my ManyToOne-related entities when using a native SQL query? Is this somehow possible using the SqlResultSetMapping annotation?

    Never mind - the problem was to do with not specifying a class when creating the native query.

  • Cluster bar chart- sql query please help-

    Hi,
    I am trying to create cluster bar chart and am stumped with this sql query.Any help is appreciated.
    Here is my table
    city     region      issue     value
    c1     north     i1     y
    c1     north     i2     y
    c2     north     i1     n
    c2     north     i2     y
    c3     south     i1     y
    c3     south     i2     n
    c4     east     i1     n
    c4     east     i2     n
    The bar chart will have 3 series, north south and east.
    And labels will be i1 and i2. value will be number of times this issue was encountered(y) in this region.
    How can I get something like this from the above table-
    region     issue     count(yes)
    north     i1     1
    north     i2     2
    south     i1     1
    south     i2     0
    east     i1     0
    east     i2     0
    thanks

    WITH table1 AS
    (SELECT 1435177 qte_id, 2 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 5 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 7 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 8 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 12 seq_no
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 14 seq_no
    FROM dual
    table2 AS
    SELECT 1435177 qte_id, 1 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 2 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 3 seq_no, 0 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 4 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 5 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 7 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 8 seq_no, 98500 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 11 seq_no, 59300 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 12 seq_no, 59300 cmmt_curr_amt
    FROM dual
    UNION ALL
    SELECT 1435177 qte_id, 14 seq_no, 59300 cmmt_curr_amt
    FROM dual
    SELECT qte_id, t2_seq_no, cmmt_curr_amt - cmmt_curr_lag diff
    FROM
    (SELECT t2.qte_id, t2.seq_no t2_seq_no, t1.seq_no t1_seq_no, cmmt_curr_amt, LAG(cmmt_curr_amt,1,0) OVER (PARTITION BY t2.qte_id ORDER BY t2.seq_no) cmmt_curr_lag
    FROM table1 t1, table2 t2
    WHERE t2.qte_id = t1.qte_id (+)
    AND t2.seq_no = t1.seq_no(+)
    ORDER BY 1,2
    WHERE t1_seq_no IS NOT NULL
    ORDER BY 1,2
    QTE_ID T2_SEQ_NO DIFF
    1435177 2 0
    1435177 5 0
    1435177 7 0
    1435177 8 0
    1435177 12 0
    1435177 14 0

  • SQL Gurus : Need Help in building SQL query

    SQL Gurus,
    Need your expertise to solve my below problem:
    - I have a column that had comma separated data, basically there are the levels in a hierarchy. eg The same column could have the following data:
    Row 1: R1L1, R1L2, R1L3
    Row 2: R2L1, R2L2
    Row 3: R3L1, R3L2, R3L3, R3L4
    For assumption purpose lets assume that there are maximum 5 Levels
    I want to put this data from this column into another table which holds the levels. I am expecting the output in another table as follows:
    Col1____Col2 ____Col3____Col4____Col5
    Row 1: R1L1___R1L2____R1L3____null_____null
    Row 2: R2L1___R2L2____null_____null_____null
    Row 3: R3L1___R3L2____R3L3____R3L4___null
    How do i achieve this ? ie coverting the comma separated values in a column to separate columns. The # of values in each columns could be different as I have showb above
    Regards,
    pk

    with t as (
               select 'R1L1, R1L2, R1L3' c1 from dual union all
               select 'R2L1, R2L2' c1 from dual union all
               select 'R3L1, R3L2, R3L3, R3L4' c1 from dual
    select  substr(c1,instr(', ' || c1 || ', ',', ',1,mod(l,5) + 1),instr(', ' || c1 || ', ',', ',1,mod(l + 1,5) + 1) - instr(', ' || c1 || ', ',', ',1,mod(l,5) + 1) - 2) col1,
            substr(c1,instr(', ' || c1 || ', ',', ',1,mod(l - 1,5) + 1),instr(', ' || c1 || ', ',', ',1,mod(l,5) + 1) - instr(', ' || c1 || ', ',', ',1,mod(l - 1,5) + 1) - 2) col2,
            substr(c1,instr(', ' || c1 || ', ',', ',1,mod(l - 2,5) + 1),instr(', ' || c1 || ', ',', ',1,mod(l - 1,5) + 1) - instr(', ' || c1 || ', ',', ',1,mod(l - 2,5) + 1) - 2) col3,
            substr(c1,instr(', ' || c1 || ', ',', ',1,mod(l - 3,5) + 1),instr(', ' || c1 || ', ',', ',1,mod(l - 2,5) + 1) - instr(', ' || c1 || ', ',', ',1,mod(l - 3,5) + 1) - 2) col4,
            substr(c1,instr(', ' || c1 || ', ',', ',1,mod(l - 4,5) + 1),instr(', ' || c1 || ', ',', ',1,mod(l - 3,5) + 1) - instr(', ' || c1 || ', ',', ',1,mod(l - 4,5) + 1) - 2) col5
      from  (
             select  c1,
                     length(c1) - length(replace(c1,',')) + 5 l
               from  t
    COL1                   COL2                   COL3                   COL4                   COL5
    R1L3                   R1L2                   R1L1
    R2L2                   R2L1
    R3L4                   R3L3                   R3L2                   R3L1
    SQL> SY.

  • A sql query needed

    Hi All,
    I have belwo two record values.
    select 1 as seq_no,'test1' as data_set from dual
    union
    select 1,'12test' from dual
    union
    select 2,'abcd' from dual
    union
    select 2,'ilm' from dual
    union
    select 2,'12test444' from dual
    here i need to extract the below o/p from from the above dataset
    1,12test
    1,test1
    2,12test444
    select 1 as seq_no,'test1' as data_set from dual
    union
    select 1,'12test' from dual
    union
    select 2,'abcd' from dual
    union
    select 2,'ilm' from dual
    here i need to extract the below o/p from from the above dataset
    1,12test
    1,test1
    2,abcd
    2,ilm
    The logic behind the above two types of o/p is
    if the search string 'test' is present in any data set (data set is defined by same seq_no values) then print the whole row containing the search string. As in the first record value data set with seq_val 1 and 2 both have test string 'test' , o/p is all the rows contating the search string 'test'
    If the search string 'test' is not present in any data set (data set is defined by same seq_no values) then print all other rows not containing the search string. As in the second record value data set with seq_val 2 both doesn't have test string 'test' , o/p is all the rows not contating the search string 'test' in data test with seq_val 1as well as all the rows contating the search string 'test' in data set with seq_val 2
    Hope i could explain my o/p logic and i need to perform this in a sql query.
    Waiting for your responses.
    Thanks in advance.

    Hi,
    Here's one way:
    WITH     got_rnk          AS
         SELECT     seq_no, data_set
         ,     DENSE_RANK () OVER ( PARTITION BY  seq_no
                                   ORDER BY          CASE
                                       WHEN  INSTR (data_set, 'test') > 0
                                       THEN  1
                                       ELSE  2
                                     END
                           )     AS rnk
         FROM    table_x
    SELECT     seq_no, data_set
    FROM     got_rnk
    WHERE     rnk     = 1
    ;The CASE expression returns 1 if data_set contains 'test', and it returns 2 if it does not. Let's call this number x.
    You're not really interested in x itself. Rather, you want all the rows that have the lowest value of x among rows with the same seq_no. That is, if any row with a given_seq_num has x=1, then you want all rows with that seq_no and x=1, but it the lowest x for the a seq_no is 2, then you want the rows with x=2 instead.
    DENSE_RANK returns the the number 1 if the given riow is the lowest (or tied for the lowest) in its partition, so if the are any rows with x=1 in the group, rnk=1 will correspond to x=1. But if all the rows with the same seq_no have x=2, then rnk=1 will correspond to x=2.

  • Native sql query in sap

    Hi all,
    my open SQL query is like
    select matnr  matkl from mara into corresponding fields of table i_mara for all entries in i_marc
         where matnr = marc-matnr.
    can u plz tell me the native sql for the same query?
    Thanks.
    pabi

    hi,
    EXEC SQL PERFORMING form.
    Native SQL Anweisung
    ENDEXEC.
    EXEC SQL
    select matnr matkl from mara into corresponding fields of table i_mara for all entries in i_marc
    where matnr = marc-matnr.
    ENDEXEC.
    For further ref pls refer to link...
    Re: Normal SQL Query othern than Native
    Native SQL

  • SQL query tunning help

    Hi All,
    Could you please help me out the below SQL query tuning .
    Temp table is having 1 Million records
    Master table is having 60 Million records
    Query :
    SELECT B.*,U.ID, SD, LE, LAE
    FROM client.Temp B, client.Master
    U WHERE U.policyno = B.policyno
    AND B.UPFLAG = 0
    1.     Indexes are created on both email columns and Upflag for both tables.
    2.     Gathered DBMS Stats for MASTER Table
    Data is loading 100k/hour on production .

    When your query takes too long ...
    When your query takes too long ...
    HOW TO: Post a SQL statement tuning request - template posting
    HOW TO: Post a SQL statement tuning request - template posting

  • Sql query need for date format''Mon 23 Apr 16:45 pm'

    i need SQL query to print date like 'Mon 23 Apr 16:45 pm' format

    SQL> select to_char(sysdate,'Dy fmddfm Mon hh24:mi pm','nls_date_language=american') from dual
      2  /
    TO_CHAR(SYSDATE,'DY
    Fri 27 Apr 13:04 pm
    1 rij is geselecteerd.Regards,
    Rob.

  • Simplify SQL query - need suggestions

    Hi,
    I have a table "Product" in my Database , which i am using to create reports in OBIEE. The table has five cols : ID, Version, Date, ItemName, ItemRate . It is partitioned on Date col . The table has many rows and I want to hit Date partition to improve performance.I take Date as input from user by Date Prompt.
    The primary key is ID+Version+ItemName
    I want to get a table which contains Date, ItemName,ItemRate, ID for each ID with max(Version). This table I will join with another table in Oracle BI Answers to generate reports. If an ID has many versions, I get max version value and then return ID,ItemName,ItemRate,Date corresponding to that Verion value.
    What is the best way to achieve this, should I define view in my physical layer which contains sql query for simplified table so that it will make my task of generating reports easier by having asimplified table in Oracle BI Answers ? ?
    Please ask if any clarification is needed ....
    Thanks

    There are couple of ways to handle your requirements. Try this:
    When table is partitioned we have to use fragmentation option using LTS->Proparties->Content tab specify the condition at
    Fragmentation content:
    and
    Check 'This source should...'
    For Max(version): Use repository variable for getting max(version) and filter using Where clause option in Content tab.
    Let me know updates

  • Passing parameter to a SQL query - Please help

    Hi All,
    I am new to JDBC. I have been trying to pass an external variable to an SQL Query.
    The query is
    String username1="le";
    PreparedStatement pstmt = null;
    pstmt = c.prepareStatement("select * from users where USER_NAME like '%?%'");
         pstmt.setString(1, username1);
         pstmt.executeQuery();
         ResultSet rs = pstmt.getResultSet();
    I am trying to retrieve values from the users table where the USER_NAME column value that is a String contains the supplied value username1.
    I am using the question mark (?) character to pass the value from the variable username1. I am also using the '%' substitution character which matches for any number of characters. So, the above query should retrieve rows where the USER_NAME is something like "charles","leander","Elena" etc.( that contains "le")
    I am getting the error:
    SQLException: java.sql.SQLException: ORA-01006: bind variable does not exist
    I changed the query to
    PreparedStatement pstmt = null;
    pstmt = c.prepareStatement("select * from users where USER_NAME like '% " + username1 + "%'");
         //pstmt.setString(1, username1);
         pstmt.executeQuery();
    This time , it is not giving the error and retrieving properly.
    But I want to use the original query and use the "pstmt.setString(1, username1); " . Is there any way of achieving this?
    Please help.
    Cheers,
    charles_am

    hi,
    try this...
    String username1="%le%";
    pstmt = c.prepareStatement("select * from users where USER_NAME like ?")
    pstmt.setString(1,username1);
    cheers,
    rpk

Maybe you are looking for