Simple SQL query..need help

Hi All,
I have a requirement not to show the row, if all columns value is zero. Could someone help me how to do it?
For example:
A     B     C   D    E
1 1 5 1 2
1 0 5 0 2
0 9 7 1 0
0 0 0 0 0
From the above example the only last row should not be shown, because all columns value is zero.
Thanks in advance.

Another way:
with abc as (select 1 a, 1 b, 5 c, 1 d, 2 e from dual union all
             select 1 a, 0 b, 5 c, 0 d, 2 e from dual union all
             select 0 a, 9 b, 7 c, 1 d, 0 e from dual union all
             select 0 a, 0 b, 0 c, 0 d, 0 e from dual union all
             select null a, 0 b, 0 c, 0 d, 0 e from dual)
select a, b, c, d, e
from   abc
where  (nvl(a, 0), nvl(b, 0), nvl(c, 0), nvl(d, 0), nvl(e, 0)) not in (select 0,0,0,0,0 from dual);
         A          B          C          D          E
         1          1          5          1          2
         1          0          5          0          2
         0          9          7          1          0

Similar Messages

  • 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

  • Simple SQL query needed

    hi,
    I have two tables.
    tbl1
    col1 col2
    a 2
    a 3
    b 4
    tbl1
    col1 col2
    a 3
    b 5
    i need to update table1 records with the value present in table. means after updation table1 record should be
    tbl1
    col1 col2
    a 3
    a 3
    b 5
    its pretty simple but i am not getting the answer. Thnks in advance for help.
    Ashish

    A quick, yet dirty solution:
    Update
            tbl1 t1
    Set
            t1.col2 =
                        case 
                            when (select t2.col2 from tbl2 t2 where t1.col1=t2.col1) is null
                            then (select max(t3.col2) from tbl1 t3 where t1.col1=t3.col1)
                            else (select t2.col2 from tbl2 t2 where t1.col1=t2.col1)
                        end;

  • Simple SQL query statement is needed

    I need a simple SQL query to fetch records which is existed in all the departments.
    for example: i want to list the employees which are existed in each and every department.. not sure how should i get those.. will anyone help me please.. thanks in advance

    I think it would be wise to go to the following training:
    Oracle Database <version> : Introduction to SQL
    You will get the information you are looking for in five days. You can go find a tutorial on ANSI SQL, as advised by this board for free, to fix your immediate problem with a simple query. But, I personally recommend a more formal class specific to Oracle, as you will also get information about PL/SQL, and you get the benefit with working with other DBA/programmers when you are learning. This will solve your immediate issue, and any future issues with the language.
    You can find it in the Education section of the Oracle website.

  • 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

  • Simple SQL Query and Parameters and LOV

    Newbie and trying to work thru building a simple sql query with a single table query and use a parameter and lov.
    Can anyone point me to an example.
    simple query:
    select cust_id, name_desc, name_add1, name_add2, name_city
    from customer_table
    where cust_id = :cust_parm
    This works in straight sql and in the query builder by prompting for the customer ID. When building a parameter using LOV or search, it doesn't seem to detect the variable.
    Thanks..
    DD

    If you are using version 11g, then as soon as you save the query in the data model, it should notice the parameter and ask if you want to add the parameter to the data model. What version of BIP are you using?
    What happens if you exclude the parameter from the query and simply hard-code the criteria? Can you generate XML data?
    From your wording, it sounds like you're trying to create a parameter from the LOV dialog. LOVs and parameters are totally distinct. After each are created separately, then you configure the parameter to use the LOV.

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

  • 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

  • Simple SQL query SQL developer takes it, The wizzard of XE does not

    Hello everybody
    I wrote this simple query which SQL developer runs fine, but when I try to launch a Report based on this sql query it tells me invalid sql statement. That is true, it may be invalid because this IF clause in there..but SQL developer seems to be very tolerant or understands more...
    the reason I wrote that is because obviously if there are no bosses, ie = 0 then i would get an error when dividing it by 0, so I put that 0 just to select the good ones
    if count (bosses) >0
    select company, postcode,
    sum( bosses/staff)
    from evaluation
    group by company, postcode
    Thank you very much
    Alvaro

    oh yes (blushed in shame as how dumb i looked like) i knew about the denominator 0 and infinite as as result i just didnt notice my zero was on the numerator :(
    however, i run the query and i got this message in sql developer
    Error starting at line 1 in command:
    select company, postcode,
    case when staff != 0 then sum( bosses/staff) end
    from evaluation
    group by company, postcode
    Error at Command Line:2 Column:10
    Error report:
    SQL Error: ORA-00979: not a GROUP BY expression
    00979. 00000 - "not a GROUP BY expression"
    *Cause:   
    *Action:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • 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

  • List the count of each schema objects.. schema wise sql query needed

    Hi Friends,
    i need a sql query which has to list the schema name along with the count of schema objects like tables,views,triggers.... order by schemaname
    Regards,
    DB

    Hi
    You can try this option if you use 11g .
    Get all the object types in your db.
    SELECT DISTINCT object_type
                 FROM dba_objects;Then include all the object types in to the below query.
    select *
      from (select owner, object_type, 1 CNT
              from dba_objects ) e
            pivot( sum(CNT) for object_type in
              ( 'INDEX','TYPE','VIEW','LIBRARY','TRIGGER','DIRECTORY','PACKAGE','QUEUE','PACKAGE BODY','TABLE PARTITION','PROCEDURE',
                'WINDOW','CLUSTER','LOB','FUNCTION','CONSUMER GROUP','CONTEXT','RULE','XML SCHEMA','SEQUENCE','INDEX PARTITION','OPERATOR',
                'EVALUATION CONTEXT','SCHEDULE','JOB','SCHEDULER GROUP','LOB PARTITION','JOB CLASS','INDEXTYPE','TABLE','TYPE BODY','RESOURCE PLAN',
                'TABLE SUBPARTITION','UNDEFINED','DESTINATION','SYNONYM','EDITION','PROGRAM','RULE SET' ) )       
    order by owner;Cheers
    Kanchana

Maybe you are looking for