Regarding SQL ...

Hello ABAP gurus,
Please help me out in solving following doubt.
Fieldname: Tax-code1 (STCD1), Tax-code2( STCD2), Vendor number(LIFNR)
Table name: LFA1.
I am working on uniqueness for tax code verification for vendors.
Lets say that tax code1 (STCD1) value for a particular vendor is in v_tax1 and tax-code2 (STCD2) value for vendor is in v_tax2.
I want to check tax-code1 value for this vendor number (LIFNR) against tax-code1 values for all the other vendors numbers in table LFA1.
Hence in simple terms I want to see if value of v_tax1 exists for any other vendor's Tax-code1  scanning the whole LFA1 for all the other vendors and comparing with their respective taxcode1s (STCD1).
If an entry exists then raise error.
Same thing I want to do for tax-code2, tax-code3..
Please let me know how do I perform this using SQL ?
Relevant points will be awarded..

Hi
You can perhaps do this using a subquery in the  select stmt.
select lifnr stcd1 from lfa1 as a
into table itab
where lifnr in s_lifnr
and exists ( select stcd1 from lfa1 as b
             where blifnr <> alifnr
             and bstcd1 = astcd1 ).
Regards
Kalpana
Message was edited by: Kalpana Tyagi

Similar Messages

  • Doubt regarding SQL execution

    Hi Friends,
    Am using Oracle 10g DB - 10.2.0.3.0
    I have some basic doubts regarding sql query execution by Oracle.
    Say, Am executing a query from a toad/sqlplus session for the first time, it takes 10 secs then 1 sec and so on.
    Same thing happens for every 15 minutes.(Any specific reason for this ??).
    It takes more time when it executes first because of parsing and all those stuff but from then on it picks from the
    shared pool right??.. How long will it be there in Shared Pool does Oracle maintain any specific time period to clear that query from shared pool memory. How does Oracle handle this.
    Another thing is, say, I have a report query, I run this query monthly. What will be the execution time when I run this query each and every month. Will Oracle parse this query everytime I run. How do I improve the performance in this situation (May sound odd :)).
    Regards,
    Marlon

    Say, Am executing a query from a toad/sqlplus session for the first time, it takes 10 secs then 1 sec and so on.
    Same thing happens for every 15 minutes.(Any specific reason for this ??).
    It takes more time when it executes first because of parsing and all those stuff but from then on it picks from the
    shared pool right??.. How long will it be there in Shared Pool does Oracle maintain any specific time period to clear that query from shared pool memory. How does Oracle handle this. Share Pool caches the SQL statement. So when you execute the same SQL for the second time it goes for a soft parse. But this is not the only reason for the query to execute faster the second time. The time difference between a soft parse and hard parse is very minimal. So it really does not matter unless you are executing the same query several number of times.
    The thing that really matters is the Data Buffer Cache. That is the rows that are selected by your query are cached into the Data buffer that is available in the SGA. So for the next time when you run the same query the IO is reduced as the data is available in the memory and you don't have to go to your disk to get the data.
    But the data in Data Buffer is not persistent, meaning it follows the FIFO rule. That is first in first out. When the Data Buffer is full the content of the buffer is removed in the FIFO order.
    Another thing is, say, I have a report query, I run this query monthly. What will be the execution time when I run this query each and every month. Will Oracle parse this query every time I run. How do I improve the performance in this situation (May sound odd :)). Like the Data Buffer the Shared Pool is also maintained in the FIFO order. So if the query is still in the Shared Pool the query will be soft parsed else it will be hard parsed. But its very rare that you will have a query in your Shared Pool for a month.

  • Question Regarding SQL logic error!

    Hello everyone,
    I get the following error when executing an Informatica mapping with teh following SQL in the Source Qualifier.
    error - OR- 00936: missing expression.
    Can anyone help please!
    SELECT
    PS_CUSTOMER.SETID
    , PS_CUSTOMER.CUST_ID
    , PS_CUSTOMER.CUST_STATUS
    , PS_CUSTOMER.ADD_DT
    , PS_CUSTOMER.NAME1
    , PS_CUSTOMER.TAXPAYER_ID
    , PS_CUSTOMER.WEB_URL
    , PS_CUSTOMER.LAST_MAINT_OPRID
    , PS_CUSTOMER.DATE_LAST_MAINT
    , PS_CUST_SIC_CODES.SIC_CD_QUAL
    , PS_CUST_SIC_CODES.SIC_CODE
    , PS_CUST_CGRP_LNK.CUST_GRP_TYPE
    , PS_CUST_CGRP_LNK.CUSTOMER_GROUP
    , PS_CUST_CGRP_LNK.LASTUPDDTTM
    , PS_CUST_ID_NBRS.STD_ID_NUM
    , PS_CUSTOMER.SUBCUST_QUAL1
    FROM PS_CUSTOMER
    select SIC1.SETID, SIC1.CUST_ID, MAX(SIC1.SIC_CODE) SIC_CODE, SIC1.SIC_CD_QUAL
    from PS_CUST_SIC_CODES SIC1
    where SIC1.SIC_CD_QUAL =
    ( select MAX(SIC_CD_QUAL)
    from PS_CUST_SIC_CODES SIC2
    where SIC2.CUST_ID = SIC1.CUST_ID
    and SIC2.SETID = SIC1.SETID
    group by SETID, CUST_ID, SIC1.SIC_CD_QUAL
    ) PS_CUST_SIC_CODES
    select A.CUST_ID, A.SETID, A.CUST_GRP_TYPE
    , MAX(A.CUSTOMER_GROUP) CUSTOMER_GROUP, A.LASTUPDDTTM
    from PS_CUST_CGRP_LNK A
    where A.CUST_GRP_TYPE =
    SELECT MAX(CUST_GRP_TYPE)
    FROM PS_CUST_CGRP_LNK B
    WHERE A.CUST_ID = B.CUST_ID
    AND A.SETID = B.SETID
    AND A.LASTUPDDTTM = B.LASTUPDDTTM
    AND B.LASTUPDDTTM =
    SELECT MAX(LASTUPDDTTM)
    FROM PS_CUST_CGRP_LNK C
    WHERE C.CUST_ID = B.CUST_ID
    AND C.SETID = B.SETID
    GROUP BY CUST_ID, SETID, CUST_GRP_TYPE, LASTUPDDTTM
    ) PS_CUST_CGRP_LNK
    select SETID, CUST_ID, STD_ID_NUM
    from PS_CUST_ID_NBRS
    where STD_ID_NUM_QUAL = 'DNS'
    ) PS_CUST_ID_NBRS
    WHERE
    { PS_CUSTOMER
    LEFT OUTER JOIN
    PS_CUST_SIC_CODES ON
    PS_CUSTOMER.SETID = PS_CUST_SIC_CODES.SETID
    AND PS_CUSTOMER.CUST_ID = PS_CUST_SIC_CODES.CUST_ID
    LEFT OUTER JOIN
    PS_CUST_CGRP_LNK ON
    PS_CUSTOMER.SETID = PS_CUST_CGRP_LNK.SETID
    AND PS_CUSTOMER.CUST_ID = PS_CUST_CGRP_LNK.CUST_ID
    LEFT OUTER JOIN
    PS_CUST_ID_NBRS ON
    PS_CUSTOMER.SETID = PS_CUST_ID_NBRS.SETID
    AND PS_CUSTOMER.CUST_ID = PS_CUST_ID_NBRS.CUST_ID
    ORDER BY PS_CUSTOMER.CUST_ID , PS_CUSTOMER.SETID
    Thanks,
    Ajay.

    Kramer wrote:
    Hi
    So.. do we have to pay for the feature regarding sql tuning advisor?
    Can we use the dbms_sqltune package for free in oracle?
    No, you need the license. Please read below,
    http://download.oracle.com/docs/cd/E11882_01/license.112/e10594/options.htm#CIHFIHFG
    I `m doing below test on my Linux. I installed an oracle on it and only for study purpose so didn`t pay.
    As you can see. I got no output.
    SQL> exec dbms_sqltune.execute_tuning_task('TASK_1634');
    PL/SQL procedure successfully completed.
    SQL> select dbms_sqltune.report_tuning_task('TASK_1634') from dual;
    DBMS_SQLTUNE.REPORT_TUNING_TASK('TASK_1634')
    GENERAL INFORMATION SECTION
    Please read the below link to learn how to use the STA.
    http://download.oracle.com/docs/cd/E11882_01/server.112/e16638/sql_tune.htm
    HTH
    Aman....

  • Regarding sql loader ---  can we have  control file  to do a check on csv?

    Hi,
    I normally get a csv having data as
    column1 ;columnb;columnc;
    13 ; 12 ; 13 ;
    11 ;13 ;33;
    as the table where it needs to go is say table
    xys( a number, b number , c number).
    so the control file is fairly simple ...
    But from now I need to restrict data entry if the change in format happens in the csv
    say if it is like
    column2;column1;column3,
    12,13;12;
    11;13;14;
    or say the csv like
    column1;column2;column3;column4;
    11;13;14;15;
    111;134;14;12;
    in both cases sql loader should not run and throw the error saying the reason in the log.
    how do i manage it in the control file `???
    any ideas???
    it is urgent pls help !!!
    regards
    SHUBH
    Message was edited by:
    SHUBH

    Try changing the following properties:
    autosubmit = true;
    immediate = true;
    Here is a link where the user uses a transient attribute for the rows in his table:
    Technology on my way...:): ADF 11g : CheckBox Demo (Select one checkbox in table, Select all/Deselect all)
    Hope that helps.
    Regards,
    Frederico.

  • ? Regarding 'SQL user-defined function' execution performance ?

    Hi All,
    I have an user-defined function in SQL which am using in a SQL select statement and i found that the execution time taken by the user-defined function is 9-10 minutes as a result of which my whole query execution time is affected.
    How to i improvise the execution time. Should i do some sort of scheduling for executing the user-defined functions only. Am new to the database world. Your early response with a good suggestion would really be appreciated.
    Thanks in Advance.

    Try to read SQL tuning documents along with TkProf. Then only you will be able to detect the problem.
    There is no instant method by which you can solve this problem.
    But, you can get idea from this samples.
    Tuning:
    http://www.dba-oracle.com/art_sql_tune.htm
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::NO::P11_QUESTION_ID:8764517459743
    Reading TkProf:
    http://www.dbspecialists.com/presentations/use_explain.html
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:920429344869
    Regards.
    Satyaki De.

  • ADDM recommendation regarding SQL Tuning

    Hi all.
    Several times, I've seen this recommendation when I run ADDM:
    Recommendation 1: SQL Tuning
    Estimated benefit is 1.78 active sessions, 4.93% of total activity.
    Action
    Tune the PL/SQL block with SQL_ID "9f9y14fzgg9a9". Refer to the "Tuning
    PL/SQL Applications" chapter of Oracle's "PL/SQL User's Guide and
    Reference".
    Related Object
    SQL statement with SQL_ID 9f9y14fzgg9a9.
    declare
    rc__ number;
    simple_list__ owa_util.vc_arr;
    complex_list__ owa_util.vc_arr;
    begin
    owa.init_cgi_env(:n__,:nm__,:v__);
    htp.HTBUF_LEN := 255;
    null;
    null;
    simple_list__(1) := 'sys.%';
    simple_list__(2) := 'dbms\_%';
    simple_list__(3) := 'utl\_%';
    simple_list__(4) := 'owa\_%';
    simple_list__(5) := 'owa.%';
    simple_list__(6) := 'htp.%';
    simple_list__(7) := 'htf.%';
    simple_list__(8) := 'wpg_docload.%';
    if ((owa_match.match_pattern('adhoc_run.submit_rep', simple_list__,
    complex_list__, true))) then
    rc__ := 2;
    else
    null;
    null;
    adhoc_run.submit_rep(NAME_ARRAY=>:NAME_ARRAY,VALUE_ARRAY=>:VALUE_ARRA
    Y);
    if (wpg_docload.is_file_download) then
    rc__ := 1;
    wpg_docload.get_download_file(:doc_info);
    null;
    null;
    null;
    commit;
    else
    rc__ := 0;
    null;
    null;
    null;
    commit;
    owa.get_page(:data__,:ndata__);
    end if;
    end if;
    :rc__ := rc__;
    end;
    Rationale
    SQL statement with SQL_ID "9f9y14fzgg9a9" was executed 206 times and had
    an average elapsed time of 46 seconds.
    My understanding is that this is an embedded APEX routine I can't control.
    Question for the gurus out there:
    - Have you seen this before?
    - Is there any way to tune this (any parameter, etc.)? Any recommendation?
    Thanks a lot,
    Ignacio.

    Hi,
    How about SQL Profiles? Have thought in this direction?
    Some info is here http://www.oracle-base.com/articles/10g/AutomaticSQLTuning10g.php
    Regards,

  • Need help regarding sql loader

    Hi ,
    I am executing following command
    sqlldr admin_user@ces CONTROL=D:\sample_control.ctl log=D:\sample_log.log bad=D:\Sample_bad.bad
    In case of valid data it is inserting the data properly into the table. While invalid records added into the bad file.
    Now I want rollback valid data whenever count of bad file greater than equal to 10.
    In short whenever file has more than 10 invalid records , I don't want to insert any record from that file.
    Please provide me the solution.Thanks in advance.

    SQL*Loader Command-Line Reference
    DISCARDMAX(integer)
    Regards
    Etbin

  • Regarding sql function error  for Hijri date to Gregorian date

    Hi ,
    I want to convert Hijri date format into Gregorian date format . i write the script with  sql function  like this
    $Hijri_Date = '16/04/1428';
    $Gregorian_Date = sql('DS_REPO','SELECT CONVERT(DATE,[$Hijri_Date],131)');
    print($Gregorian_Date);
    here $Hijri_Date data type is varchar and $Gregorian_Date data type is date.
    but  I am getting error like
    7868     5812     DBS-070401     10/26/2010 10:37:18 PM     |Session Job_Hijradata_Conversion
    7868     5812     DBS-070401     10/26/2010 10:37:18 PM     ODBC data source <UIPL-LAP-0013\SQLEXPRESS> error message for operation <SQLExecute>: <[Microsoft][SQL Server Native Client
    7868     5812     DBS-070401     10/26/2010 10:37:18 PM     10.0][SQL Server]Explicit conversion from data type int to date is not allowed.>.
    7868     5812     RUN-050304     10/26/2010 10:37:18 PM     |Session Job_Hijradata_Conversion
    7868     5812     RUN-050304     10/26/2010 10:37:18 PM     Function call <sql ( DS_REPO, SELECT CONVERT(DATE,16/04/1428,131) ) > failed, due to error <70401>: <ODBC data source
    7868     5812     RUN-050304     10/26/2010 10:37:18 PM     <UIPL-LAP-0013\SQLEXPRESS> error message for operation <SQLExecute>: <[Microsoft][SQL Server Native Client 10.0][SQL
    7868     5812     RUN-050304     10/26/2010 10:37:18 PM     Server]Explicit conversion from data type int to date is not allowed.>.>.
    7868     5812     RUN-053008     10/26/2010 10:37:18 PM     |Session Job_Hijradata_Conversion
    please help me out to solve this problem .
    Please suggest any other solution to convert hijri date format to gregorian date format.
    Thanks&Regards,
    Ramana.

    Hi ,
    In Data quality there is no inbuild function for converting hijri date to gregorian date .  we have the function for converting julian date to gregorian date.
    Thanks&Regards,
    Ramana.

  • Query regarding sql server

    i downloaded Microsoft visual studio 2010 in my laptop for windows 8 and in that the sql server is not working.the services for sql server is not starting .so pls help me in starting the services for sql server.

    
    1. Make sure SQL Server Service is running
    2. If a named instance, make sure SQL Server browser service is running
    3. Make sure SQL Server is configured to allow remote connections
    4. Examine the SQL Server error log for messages confirming that SQL is listening on the expected network interfaces and ports
    5. Test server connectivity with PING from the client machine
    6. Test port connectivity using TELNET or PowerShell to the server and port (from step 4) from the client machine.  For example
    a. TELNET <server-name> 1433
    b. PowerShell: 1433 | % { echo ((new-object Net.Sockets.TcpClient).Connect("YourServerName",$_)) "server listening on TCP port $_" }
    7. Check firewall settings if step 5 or 6 connectivity test fails
    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

  • VERY VERY URGENT SOLUTION NEEDED regarding SQL

    Dear Sir,
    I have a table whose structure is
    SQL> desc fof;
    Name Null? Type
    FOFID NUMBER(12)
    PERSONID NUMBER(12)
    RELATIONSHIPID NUMBER(2)
    FPERSONID NUMBER(12)
    STRENGTH NUMBER(1)
    RELATIONSTATE VARCHAR2(15)
    CTIME DATE
    UTIME DATE
    DELETED NUMBER(1)
    EDITEDBY NUMBER(12)
    The table has duplicate entries let me explain :
    personid fpersonid
    1 2
    2 1
    3 4
    4 3
    I want to keep only rows with one entry of every duplicate
    personid fpersonid and not personid fpersonid
    1 2 1 2
    2 1
    In other words keep a -> b and remove b -> a
    Is there is any way you geeks can help i am ripping my hair out thinking about it
    Please reply
    :(

    That works .....
    Also the approach which i was thinking that to use cursor searching values in the table and deleting them
    but in those also it deleted all records :(
    something similar to this
    --create table test_person_id ( personid number, fpersonid number)
    --insert into test_person_id values ( 1,2 )
    --insert into test_person_id values ( 2,1 )
    --insert into test_person_id values ( 3,4 )
    --insert into test_person_id values ( 4,3 )
    --insert into test_person_id values ( 5,6 )
    --insert into test_person_id values ( 7,8 )
    --select * from test_person_id
    --delete from test_person_id
    --select * from test_person_id tpi where exists
    --( select * from test_person_id tpi_1 where tpi.fpersonid = tpi_1.personid)
    declare
      v_personid  number;
      v_fpersonid number;
      temp_personid  number;
      temp_fpersonid number;
      v_rowid rowid;
      cursor c1 is
        select rowid, personid, fpersonid from test_person_id;
    BEGIN
      OPEN c1;
      LOOP
      FETCH c1
        INTO v_rowid, v_personid, v_fpersonid;
      DBMS_OUTPUT.PUT_LINE('Fetched values having rowid.. ' || v_rowid);
      EXIT WHEN c1%NOTFOUND;
      delete from test_person_id tpi where
      tpi.rowid != v_rowid
      and tpi.personid = v_fpersonid
      and tpi.fpersonid = v_personid returning tpi.personid, tpi.fpersonid into temp_personid, temp_fpersonid ;
      DBMS_OUTPUT.PUT_LINE(' Deleted record ' || temp_personid || '  ' || temp_fpersonid);
      END LOOP;
      close c1;
    end;After running this only 2 records were left
    5,6
    7,8
    Can anyone help in this regard...

  • Need help regarding sql query

    hii All
    I need help for pl/sql function.
    I build a function for monthly attendance all employees.
    but now i want to show all Sundays with 'S' and others respectively 'P' and 'A'.
    Currently Sunday also shows 'A'
    So please help
    SQL queries ... like
    SELECT DISTINCT AL.USERNAME,
    CASE WHEN DAY1 =1 THEN 'P' ELSE 'A' END DAY1,
    CASE WHEN DAY2 =1 THEN 'P' ELSE 'A' END DAY2,
    CASE WHEN DAY3 =1 THEN 'P' ELSE 'A' END DAY3,
    CASE WHEN DAY31 =1 THEN 'P' ELSE 'A' END DAY31
    FROM
    SELECT DISTINCT USERNAME, SUM(CASE WHEN
    fromdt=TRUNC(L.LOGIN_DATE) THEN
    1
    ELSE
    0
    END) DAY1
    ,SUM(CASE WHEN
    fromdt +1=TRUNC(L.LOGIN_DATE) THEN
    1
    ELSE
    0
    END) DAY2,
    SUM(CASE WHEN
    fromdt+30=TRUNC(L.LOGIN_DATE) THEN
    1
    ELSE
    0
    END) DAY31
    FROM ( SELECT DISTINCT TRUNC(LOGIN_DATE)LOGIN_DATE ,USERNAME FROM FCDM_AUDIT_TRAIL_NEW WHERE
    TRUNC(LOGIN_DATE) BETWEEN fromdt AND todt
    -- to_date( login_date, 'dd-mom-yyyy') between to_date( fromdt, 'dd-mom-yyyy') and to_date( todt, 'dd-mom-yyyy')
    ) L
    GROUP BY USERNAME
    ) AL;
    how can i show matched Sundays and show with 'SUN' or 'S'
    Regards
    vij..

    Try this way:
    SELECT USERNAME,
           MAX(CASE WHEN to_char(fromdt,'d')='1' and fromdt=TRUNC(L.LOGIN_DATE) THEN 'S'
                    WHEN to_char(fromdt,'d')!='1' and fromdt=TRUNC(L.LOGIN_DATE) THEN 'P'
                    ELSE 'A') DAY1,
           MAX(CASE WHEN to_char(fromdt+1,'d')='1' and fromdt+1=TRUNC(L.LOGIN_DATE) THEN 'S'
                    WHEN to_char(fromdt+1,'d')!='1' and fromdt+1=TRUNC(L.LOGIN_DATE) THEN 'P'
                    ELSE 'A') DAY2,
           MAX(CASE WHEN to_char(fromdt+30,'d')='1' and fromdt+30=TRUNC(L.LOGIN_DATE) THEN 'S'
                    WHEN to_char(fromdt+30,'d')!='1' and fromdt+30=TRUNC(L.LOGIN_DATE) THEN 'P'
                    ELSE 'A') DAY31
    FROM
    (SELECT DISTINCT TRUNC(LOGIN_DATE) LOGIN_DATE,
            USERNAME
       FROM FCDM_AUDIT_TRAIL_NEW
      WHERE TRUNC(LOGIN_DATE) BETWEEN fromdt AND todt
    ) L
    Group by USERNAME
    ;Max
    http://oracleitalia.wordpress.com

  • Help Regarding SQL QUERY

    I have a column with values
    Sample Data
    EMPNO
    =====
    1
    2
    3
    4
    5
    6
    7
    8
    .I would like to display all the values of the column in a single row with multiple columns
    I do not want to create any other objects. i require a single query.
    Sample Output
    col1     col2   col3   col4    col5     col6  col7 col8 ............
    =======================================
    1         2      3       4        5         6      7     8   ...............FYI i am using Oracle 9.2.0
    Thanks in Advance
    Edited by: user10733211 on Oct 7, 2009 5:38 AM

    Hmm...
    satyaki>
    satyaki>select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    PL/SQL Release 10.2.0.1.0 - Production
    CORE    10.2.0.1.0      Production
    TNS for Linux: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>
    satyaki>with tab
      2  as
      3    (
      4       select 1 cola from dual
      5       union all
      6       select 2 from dual
      7       union all
      8       select 3 from dual
      9    )
    10  select *
    11  from tab;
          COLA
             1
             2
             3
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>
    satyaki>with tab
      2  as
      3    (
      4       select 1 cola from dual
      5       union all
      6       select 2 from dual
      7       union all
      8       select 3 from dual
      9    )
    10  select sum(decode(cola,1,1,0)) col1,
    11         sum(decode(cola,2,2,0)) col2,
    12         sum(decode(cola,3,3,0)) col3
    13  from tab;
          COL1       COL2       COL3
             1          2          3
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>decode can be used in much more complex case - i guess. ;)
    Regards.
    Satyaki De.

  • URgent: Help regarding SQL Query

    Hi ,
    I need help regarding an sql query.
    Sample Data:
    ITEM_TYPE  ITEM_NUM   UNIT_PRICE QUANTITY       LINE_TOTAL
    ITEM         1            5         10           50
    ITEM         2           10         5            50
    ITEM         1            5          5            25
    ITEM                       2         10           20
    TAX                                               16.5
    TAX                                              -3.5I would like to display the data as
    ITEM_TYPE ITEM_NUM  UNIT_PRICE          QUANTITY          LINE_TOTAL
    ITEM       1          5                 15               145
                  2         10                  5 
                              2                 10
    TAX                                                          13.0
    Line_total = unit_price * QuantityThanks in Advance
    G.Vamsi Krishna
    Edited by: user10733211 on Aug 5, 2009 7:42 AM
    Edited by: user10733211 on Aug 5, 2009 7:49 AM
    Edited by: user10733211 on Aug 5, 2009 8:12 AM
    Edited by: user10733211 on Aug 5, 2009 8:22 AM
    Edited by: user10733211 on Aug 5, 2009 8:24 AM

    Hi,
    Try this, use some analytics:
    SQL> with t as (
      2  select 'item' item_type, 1 item_num, 5 unit_price, 10 quantity, 50 linetotal from dual union all
      3  select 'item', 2, 10, 5, 50 from dual union all
      4  select 'item', 1, 5, 5, 25 from dual union all
      5  select 'item', null, 2, 10, 20 from dual union all
      6  select 'tax', null, null, null, 16.5 from dual union all
      7  select 'tax', null, null, null, -3.5 from dual
      8  ) -- actual query starts here:
      9  select item_type
    10  ,      item_num
    11  ,      unit_price
    12  ,      sum_qty
    13  ,      case when sum_lt = lag(sum_lt) over ( order by item_type, item_num )
    14              then null
    15              else sum_lt
    16         end  sum_lt
    17  from ( select item_type
    18         ,      item_num
    19         ,      unit_price
    20         ,      quantity
    21         ,      sum(quantity) over  ( partition by item_type, item_num ) sum_qty
    22         ,      sum(linetotal) over ( partition by item_type )           sum_lt
    23         ,      row_number() over ( partition by item_type, item_num  order by item_type, item_num ) rn
    24         from   t
    25       )
    26  where rn=1;
    ITEM   ITEM_NUM UNIT_PRICE    SUM_QTY     SUM_LT
    item          1          5         15        145
    item          2         10          5
    item                     2         10
    tax                                           13
    4 rows selected.
    edit
    And please use the code tag, instead of clunging with concats.
    Read:
    http://forums.oracle.com/forums/help.jspa
    Edited by: hoek on Aug 5, 2009 5:15 PM
    edit2
    Also nulls for item_type:
    ops$xmt%OPVN> with t as (
      2  select 'item' item_type, 1 item_num, 5 unit_price, 10 quantity, 50 linetotal from dual union all
      3  select 'item', 2, 10, 5, 50 from dual union all
      4  select 'item', 1, 5, 5, 25 from dual union all
      5  select 'item', null, 2, 10, 20 from dual union all
      6  select 'tax', null, null, null, 16.5 from dual union all
      7  select 'tax', null, null, null, -3.5 from dual
      8  ) -- actual query starts here:
      9  select case when item_type = lag(item_type) over ( order by item_type, item_num )
    10              then null
    11              else sum_lt
    12         end  item_type
    13  ,      item_num
    14  ,      unit_price
    15  ,      sum_qty
    16  ,      case when sum_lt = lag(sum_lt) over ( order by item_type, item_num )
    17              then null
    18              else sum_lt
    19         end  sum_lt
    20  from ( select item_type
    21         ,      item_num
    22         ,      unit_price
    23         ,      quantity
    24         ,      sum(quantity) over  ( partition by item_type, item_num ) sum_qty
    25         ,      sum(linetotal) over ( partition by item_type )           sum_lt
    26         ,      row_number() over ( partition by item_type, item_num  order by item_type, item_num ) rn
    27         from   t
    28       )
    29  where rn=1;
    ITEM_TYPE   ITEM_NUM UNIT_PRICE    SUM_QTY     SUM_LT
           145          1          5         15        145
                        2         10          5
                                   2         10
            13                                          13
    4 rows selected.If you really need a space instead of nulls, then simply replace the nulls by a space....
    Edited by: hoek on Aug 5, 2009 5:18 PM

  • Regarding SQL performance Analyzer

    Hi,
    I am working on oracle 11g new feature Real application testing.I want to test the performance of DB after setting DB_BLOCK_CHECKSUM and DB_BLOCK_CHECKING parameters to TRUE(currently FALSE) by using SQL performance Analyzer. I have collected the SQL Tuning Sets from production and imported in Test server(replica of PROD), and will test the same in Test server only.
    Will it be feasible to check by using SPA ? My concern is that in Test environment concurrent transaction and DML operation will not be done .
    Please help me out on this .
    Rgds,
    At

    Hi,
    Look at http://download.oracle.com/docs/cd/B28359_01/server.111/e12253/dbr_intro.htm
    Regards,

  • Query regarding SQL + save feature

    Hi All,
    On giving the following command at the SQL prompt, "save myqueries.sql" it creates a file named myqueries.sql under the bin directory of my Oracle installation folder. I want that file to be created in a path of my choice. How do I change this behaviour of SQL+?
    Thanks,
    Babu

    save c:\your_folder\myqueries.sql
    Cheers
    Sarma.

Maybe you are looking for