Using multiple 'and' conditions in a SQL query

Is it possible to reduce the SQL required to query using multiple 'and' conditions, e.g. I have a query like the following:
select stat.personal_id, appt.username, appt.password, apps.rgn_apt_id, apps.apy_apn_id
from apy_ast_application_status stat, rgn_usr_user appt, rgn_aps_applications apps
where stat.apy_apn_id = apps.rgn_apt_id
and apps.rgn_apt_id = appt.rgn_apt_id
and stat.application_completed is null
and stat.application_started_date > '01-MAY-11'
and stat.amount_paid is null
and stat.personal_details = 'C'
and stat.further_details = 'C'
and stat.education = 'C'
and stat.employment = 'C'
and stat.personal_statement = 'C'
and stat.choices = 'C'
and stat.reference = 'C'
and stat.student_finance = 'C'
Is there a way, to reduce all the multiple 'and' queries, to be read from say one line? If you know what I mean.......

Ah, Ok this looks nice, thanks very much. It doesn't quite run as is because the stat.amount_paid query value is 'is null', while the others are 'C'. I tried amending the relevant line to various versions of the following:-
in (select 'is null' 'C','C','C','C','C','C','C','C' from dual)
which doesn't work.
I can get the following to work so I am assuming that the it is not possible to use different query values within the brackets of the 'in (select....' statement?
select stat.personal_id, appt.username, appt.password, apps.rgn_apt_id, apps.apy_apn_id
from apy_ast_application_status stat, rgn_usr_user appt, rgn_aps_applications apps
where stat.apy_apn_id = apps.rgn_apt_id
and apps.rgn_apt_id = appt.rgn_apt_id
and stat.application_completed is null
and stat.application_started_date > '01-MAY-11'
and stat.amount_paid is null
and (stat.personal_details, stat.further_details, stat.education,
stat.employment, stat.personal_statement, stat.choices, stat.reference, stat.student_finance)
in (select 'C','C','C','C','C','C','C','C' from dual)
Thanks for everybodys help - the suggested alternatives seem so much more elegant

Similar Messages

  • Using extract and existnodes in a SQL query

    I have created a table having one column of datatype xmltype in oracle 9i and inserted 2 rows. When I try to execute the select query having extract and existsnode it is giving me ORA-00904: invalid column name.
    CREATE TABLE xml_tab ( xmlval sys.xmltype);
    INSERT INTO xml_tab VALUES (
    sys.xmltype.createxml('<?xml version="1.0"?>
    <EMP>
    <EMPNO>221</EMPNO>
    <ENAME>John</ENAME>
    </EMP>'));
    INSERT INTO xml_tab VALUES (
    sys.xmltype.createxml('<?xml version="1.0"?>
    <PO>
    <PONO>331</PONO>
    <PONAME>PO_1</PONAME>
    </PO>'));
    SELECT e.xmlval.extract('//EMPNO/text()').getNumVal() AS empno
    FROM xml_tab
    WHERE e.xmlval.existsnode('/EMP/EMPNO') = 1;

    Correct forum for extract() and existsnode() SQL functions is /Products/Database/XML DB.. Please post there

  • How to use outer join condition in my below query.

    Hi All,
    How to use outer join condition in my below query.
    In the table  APPS_JP.GEDIS_OFFER_HEADER goh I have more records
    in the table APPS_JP.GEDIS_ORDER_BUILDS gob I have less number of records.
    I want all the records from APPS_JP.GEDIS_OFFER_HEADER goh
    including other conditions.
    I have tried goh.OFFER_NO=gob.OFFER_NO(+) but same result.
    [code]SELECT   GOH.ORIG_SYSTEM,
               gsp.USER_NAME,
               goh.ORDER_NO,
               goh.OMEGA_ORDER_NUMBER,
               goh.ORDER_TYPE,
               gc.CUSTOMER_ID,
               gc.OMEGA_CUSTOMER_NUMBER,
               CASE WHEN gc.PRIVATE = 'N' THEN gc.CUSTOMER_NAME ELSE '' END
                  AS COMPANY_NAME,
               goh.ORDER_STATUS,
               goh.TOTAL_SELLING_PRICE,
               goh.TOTAL_MARGIN,
                  ga1.ADDRESS1
               || ','
               || ga1.ADDRESS2
               || ','
               || ga1.ADDRESS3
               || ','
               || ga1.POSTAL_CODE
               || ','
               || ga1.CITY
                  AS SHIPPING_ADDRESS,
                  ga2.ADDRESS1
               || ','
               || ga2.ADDRESS2
               || ','
               || ga2.ADDRESS3
               || ','
               || ga2.POSTAL_CODE
               || ','
               || ga2.CITY
                  AS BILLING_ADDRESS,
               ga.ADDRESS_ID,
               gol.DESCRIPTION,
               APPS_JP.TZ.to_local_date (goh.OFFER_DATE, goh.OFFER_DATE_UTC)
                  AS OFFER_DATE,
               gc.LEVEL_8,
               goh.NO_OF_BUILDS,
               gob.SFDC_ID,
               goh.PURCHASE_ORDER_NO AS PO,
               gc1.CUSTOMER_NAME AS END_USAGE,
               gol.LOB,
               goh.TOTAL_MARGIN_PCT,
               goh.TOTAL_DISCOUNT,
               goh.TOTAL_DISCOUNT_PCT
        FROM   APPS_JP.GEDIS_OFFER_HEADER goh,
               APPS_JP.GEDIS_ORDER_BUILDS gob,
               APPS_JP.GEDIS_ORDER_LINES gol,
               APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER gorc,
               APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER ship,
               APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER bill,
               APPS_JP.GEDIS_CUSTOMER gc,
               APPS_JP.GEDIS_CUSTOMER gc1,
               APPS_JP.GEDIS_CONTACT gct,
               APPS_JP.GEDIS_ADDRESS ga,
               APPS_JP.GEDIS_ADDRESS_NORM ga1,
               APPS_JP.GEDIS_ADDRESS_NORM ga2,
               (SELECT   DISTINCT SALESPERSON_ID, USER_NAME
                  FROM   APPS_JP.GEDIS_SALESPERSON
                 WHERE   SALESPERSON_ID IN
                               (SELECT   TO_NUMBER (COLUMN_VALUE) AS SALESPERSON_ID
                                  FROM   TABLE (APPS_GLOBAL.SplitString ('337309'))))
               gsp
       WHERE       goh.ORDER_NO <> 0
               AND goh.OFFER_NO <> 0
               AND goh.OFFER_NO=gol.OFFER_NO
               AND gol.BUILD_NO = 1
               AND gol.LINE_NO = 1
               AND goh.OFFER_NO=gob.OFFER_NO
               AND gob.BUILD_NO = 1
               AND goh.OFFER_NO = gorc.OFFER_NO
               AND gct.CONTACT_ID = gorc.CONTACT_ID
               AND ga.CUSTOMER_ID = gc.CUSTOMER_ID
               AND ga.PRIMARY = 'Y'
               AND goh.LEAD_SALESPERSON=gsp.SALESPERSON_ID
               AND goh.OFFER_NO = ship.OFFER_NO
               AND ship.RELATION_TYPE = 'SHIP'
               AND ga1.ADDRESS_ID = ship.ADDRESS_ID
               AND ga1.CUSTOMER_ID = gc1.CUSTOMER_ID
               AND goh.OFFER_NO = bill.OFFER_NO
               AND bill.RELATION_TYPE = 'BILL'
               AND ga2.ADDRESS_ID = bill.ADDRESS_ID
               AND goh.OFFER_DATE BETWEEN APPS_JP.TZ.LOCAL_TO_DB_DATE (
                                             SYSDATE - 30
                                      AND  APPS_JP.TZ.LOCAL_TO_DB_DATE (SYSDATE)
               AND gorc.RELATION_TYPE = 'BASE'
               AND gorc.CUSTOMER_ID = gc.CUSTOMER_ID
               AND goh.SALES_CHANNEL = gc.SALES_CHANNEL
               AND gc.SALES_CHANNEL = 'SMB'
               AND goh.LEAD_SALESPERSON IN (goh.CREATED_BY, goh.LEAD_SALESPERSON)
    ORDER BY   goh.OFFER_NO;[/code]
    Please help me how to use this outer join condition.
    Thanks in advance.

    Hi,
    If you want all the rows from goh, then you don't want any conditions like  goh.OFFER_NO <> 0.
    Make all the joins to goh outer joins, and make all conditions that apply to any tables joined to goh (or to tables joined to them) part of the join condition, like this:
    FROM             APPS_JP.GEDIS_OFFER_HEADER     goh
    LEFT OUTER JOIN  APPS_JP.GEDIS_ORDER_BUILDS     gob  ON   gob.OFFER_NO = goh.OFFER_NO
                                                         AND  gob.BUILD_NO = 1
    LEFT OUTER JOIN  APPS_JP.GEDIS_ORDER_LINES      gol  ON   gol.OFFER_NO = goh.OFFER_NO
                                                         AND  gol.BUILD_NO = 1
                                                         AND  gol.LINE_NO  = 1
    LEFT OUTER JOIN  APPS_JP.GEDIS_OFFER_RELATED_CUSTOMER
                                                    gorc ...
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Simplify the problem as much as possible.  For example, do you really need all those tables to show what the problem is?  Of course, you need them in tyour real query, but if you understand a solution that only involves 4 or 5 tables, you'll know how to apply it to any number of tables.
    Explain, using specific examples, how you get those results from that data.Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ https://forums.oracle.com/message/9362002#9362002

  • How does Index fragmentation and statistics affect the sql query performance

    Hi,
    How does Index fragmentation and statistics affect the sql query performance
    Thanks
    Shashikala
    Shashikala

    How does Index fragmentation and statistics affect the sql query performance
    Very simple answer, outdated statistics will lead optimizer to create bad plans which in turn will require more resources and this will impact performance. If index is fragmented ( mainly clustered index,holds true for Non clustred as well) time spent in finding
    the value will be more as query would have to search fragmented index to look for data, additional spaces will increase search time.
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers
    My TechNet Wiki Articles

  • Can we use exceptions and conditions at the same time?

    can we use exceptions and conditions at the same time? Are there any dependencies between exceptions an conditions?

    Exceptions are used when there are some mistakes , or exceeds the supposed values, we can highligt that in different colours for enabling the validator to notice easily. In this we are giving conditions for considering the value as exceptions. suppose, if the values is out of the range -1 to +1 then exception.
    But conditions can be considered as the restrictions given in measure level also. So please elaborate what you meant by conditions

  • When to use SELECT and END SELECT in the query.

    hi all,
    When to use SELECT and END SELECT in the query.
    regads,
    Venkata Suresh Penke.

    Hi Suresh..
    When do we need to use SELECT .. ENDSELECT
    Usually we will never use SELECT .. ENDSELECT as it gives very poor performance.
    But whenever we read a single Record we will use it as an alternative for SELECT SINGLE in some scenarios.
    Eg: When the Full primary key is not specified in the WHERE clause.
    SELECT * FROM MARC INTO WA_MARC UP TO 1 ROWS WHERE MATNR = P_MATNR.
    ENDSELECT.
    And other scenario is when we perform AGGREGATE OPERATIONS.when the Result is only one row.
    SELECT SUM( LABST ) FROM MARD INTO V_LABST UP TO 1 ROWS
    WHERE MATNR = P_MATNR.
    ENDSELECT.
    Note: In The Above scenario we cannot use SELECT SINGLE..
    <b>REWARD IF HELPFUL.</b>

  • Problem using alias field names in a sql query

    Hello,
    I have a question regarding a simple Oracle database SQL query writeup:
    In the following (badly written but properly working) SQL query:
    Query 1:
    select
    soe.field1,
    (soe.field2 + soe.field3) as field4,
    (soe.field5 - (soe.field2 + soe.field3)) as field6,
    (select comp.parValue*soe.field7
    from
    CompTable comp) as parValue,
    (select soe.field8 - (comp.parValue*soe.field7+ soe.field9)
    from
    CompTable comp) as field10
    from
    SomeTable soe
    PROBLEM 1:
    I am re writing the code (soe.field2 + soe.field3) to get the alias field4 or column name field4 that I have created on the fly in the previously for use with the following fields. Can't I rewrite the query as follows. There is something simple missing!
    Query 2:
    select
    soe.field1,
    (soe.field2 + soe.field3) as field4,
    soe.field5 - field4 as field6, <<< field4 does not work here
    (select
    comp.parValue*soe.field7
    from
    CompTable comp) as parValue,
    (select
    soe.field8 - (comp.parValue*soe.field7+ soe.field9)
    from
    CompTable comp) as field10
    from
    SomeTable soe
    PROBLEM 2:
    Similar to the above problem, I was thinking to get a field parValue out of the CompTable table and re-use many times rather than the code shown in Query 1:
    Query 3:
    select
    soe.field1,
    (soe.field2 + soe.field3) as field4,
    soe.field5 - field4 as field6,
    soe.field7* (select comp.parValue from CompTable comp) as parValue1,
    soe.field8 - (parValue1*soe.field7+ soe.field9) as field10      <<<< parvalue1 does not work here
    parValue1*soe.field9 as TaxCondition               <<<< parvalue1 does not work here
    from
    SomeTable soe
    See that the query becomes so simple, but the above query does not work. There is something fundamentally wrong in my usage of the alias field names in creating other fields. The Query1 seems to be the only working option but its very slow as I am redoing and re-writing the whole code again and again to get the parValue field out of the CompTable table for use to create many other fields.
    I will appreciate if you can guide me in the right direction on this issue.
    Thanks and Regards
    Rama

    SELECT tmp.contract_no, tmp.Actual, tmp.Actual - tmp.NbHours
    FROM ( SELECT t.contract_no, sum(l.hrs) AS Actual, (c.labour_hours * c.labour_progress_per) / 100 AS NbHours
    FROM TASK_DELEGATION t
    INNER JOIN COST_CODE c
    ON t.cost_code = c.cost_code AND t.contract_no = c.contract_no AND t.is_inactive=0
    INNER JOIN Labour.dbo.LABOURALLOT l
    ON l.contractNo = c.contract_no AND l.costcode = c.cost_code AND l.pm = 'N'
    GROUP BY t.contract_no, c.labour_hours, c.labour_progress_per
    ) tmp

  • Using/calling  a parameter in the SQL Query!

    Hi
    How do I use or call a parameter from the parameterform in my SQL query in Reports ??
    Thanks in advange *S
    /Stig :-)

    If you have user parameters of P_BEGINDATE and P_ENDDATE, in your query you would reference them by the following:
    FROM auditlog
    WHERE (eventtimestamp between :P_BEGINDATE and :P_ENDDATE
    or :P_BEGINDATE IS NULL)
    If you are using the report through Oracle Applications Concurrent Manager make sure the Token (when setting up parameters for the concurrent program)matches the user parameter exactly.
    - Rob

  • Chart Query and Failed to parse SQL query

    Hi,
    first of all, this is not a question. It is a reminder for me and maybe for someone with the same problem.
    I just fell over this for the 123124 time.
    I have a 3D Chart Query
    select sum(order_ok) value,
          count(*) maximum_value
    from      v_dialer_campaign
    where campaign_uuid = :P300_CAMPAIGN_IDSaving fails with
    "1 error has occurred Failed to parse SQL query!" ...
    Saving the query without validation works, but does not show any result in the chart.
    v_dialer_campaign is a view selecting from a view in a mssql db over database link and HS.
    running the select in sqlplus or toad works.
    Without any trace on freetds/unixodb/hs side, i would have not found the following line:
    [FreeTDS][SQL Server]The data types nvarchar and text are incompatible in the equal to operator.[FreeTDS][SQL Server]Statement(s) could not be prepared.
    Solution:
    with q as (select :P300_CAMPAIGN_ID val from dual)
    select     sum(order_ok) value,
         count(*) maximum_value
    from     v_dialer_campaign
    where     campaign_uuid in ( select val from q)Maybe the error output when validating the query should be included in the APEX error message.
    Same solution applies for dynamic LOV's reading from HS using a where clause.

    I tried your first query on Apex 3.2 and it created a nice dial chart.
    Is there any ORA-xxxxx error along with the "failed to parse SQL query" message? Did you double check column & table name spelling?
    P.S. The second query is invalid (a superfluous comma after the second column).

  • Returning operation, table and column from a sql query

    Hi,
    I am working on Oracle 10g and i have to do achieve something like this.
    i have to create procedure or functions which will accept a SQL query and will return following :
    1).  Operation like 'SELECT', 'INSERT', 'UPDATE', 'DELETE' etc.
    2).  Column names
    3).  Table involved.
    One way to achieve this would be through hard parsing of string which might be time consuming. So do we have any in-built oracle package or function for the same job ?
    Regards,
    Vikas Kumar

    Check for DBMS_SQL package and DESCRIBE_COLUMNS procedure in that package.
    You might need a combination of this package and Hard parsing of the input string.
    For operation you can trim any space and brackets using TRIM function and then you can extrcat first 6 characters using SUBSTR for Operation.
    I have not worked or used DBMS_SQL so wont be able to help you much on this.
    Here is the link for DBMS_SQL
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_sql.htm#i1026120
    Regards
    Arun

  • Use multiple partitions on a table in query

    Hi All,
    Overview:-
    I have a table - TRACK which is partitioned on weekly basis. Im using this table in one of my SQL queries in which I require to find a monthly count of some column data. The query looks like:-
    Select  count(*)
    from Barcode B
    inner join Track partition P(99) T
        on B.item_barcode = T.item_barcode
    where B.create_date between 20120202 and 20120209;In the above query I am fetching the count for one week using the Partitions created on that table during that week.
    Desired output:-
    I want to fetch data between 01-Feb and 01-Mar and use the rest of the partitions for that table during the duration in the above query. The weekly partitions currently present for Track table are -
    P(99) - 20120202
    P(100) - 20120209
    P(101) - 20120216
    P(102) - 20120223
    P(103) - 20120301
    My question is that above Ive used one partition successfully, now how can I use the other 4 partitions in the same query if I am finding the count for one month (i.e. from 201201 to 20120301) ?
    Environment:-
    Oracle version - Oracle 10g R2 (10.2.0.4)
    Operating System - AIX version 5
    Thanks.
    Edited by: Sandyboy036 on Mar 12, 2012 10:47 AM

    I'm with damorgan on this one, though I was lazy and only read it twice.
    You've got a mix of everything in this one and none of it is correct.
    1. If B.create_date is VARCHAR2 this is the wrong way to store dates.
    2. All Track partitions are needed for one month if you only have the 5 partitions you listed so there is no point in mentioning any of them by name. So the answer to 'how can I use the other 4 partitions' is - don't; Oracle will use them anyway.
    3. BETWEEN 01_Feb and 01-Mar - be aware that the BETWEEN operator includes both endpoints so if you actually used it in your query the data would include March 1.

  • Using lag and rank in the same query

    Hi
    I am trying to find out the difference in time between peoples memberships and also the order that these memberships are taken out in. So far I have added in a rank statement to work out the order the memberships were created in, but now want to look at the difference between the dates returned. The SQL I used is:
    SELECT owner_party_id,
    mem_number,
    support_id,
    mem_start_date,
    RANK() OVER (PARTITION BY owner_party_id ORDER BY mem_start_date ASC) MEMBERSHIP_SEQUENCE
    FROM membership_all
    WHERE version_type = 'CUR'
    AND owner_party_id IN ('65051', '65051', '65348', '65348', '65607', '65607', '65607')
    to get:
    "OWNER_PARTY_ID"|"MEM_NUMBER"|"SUPPORT_ID"|"MEM_START_DATE"|"MEMBERSHIP_SEQUENCE"
    65051|318874751|8014747|01-MAR-10|1
    65051|412311060|21502883|15-AUG-12|2
    65348|308672459|3526913|01-MAY-10|1
    65348|409951130|20950524|18-JUN-12|2
    65607|315830192|7510133|17-MAY-10|1
    65607|406448110|20024246|16-MAR-12|2
    65607|409738130|20903556|14-JUN-12|3
    Now I would like to calculate the difference between the start dates of each of the owner_party_id groups, so to get something like this:
    OWNER_PARTY_ID|MEM_NUMBER     |SUPPORT_ID|MEM_START_DATE     |MEMBERSHIP_SEQUENCE|Diff
    65051|318874751|8014747|01-Mar-10|1|     
    65051|412311060|21502883|15-Aug-12|2|898
    65348|308672459|3526913|01-May-10|1     
    65348|409951130|20950524|18-Jun-12|2|779
    65607|315830192|7510133|17-May-10|1     
    65607|406448110|20024246|16-Mar-12|2|669
    65607|409738130|20903556|14-Jun-12|3|90
    I think that I need to use the Lag function in, but I am not too sure if it can be linkited to look at the data within a grouping of owner party id, as it would make no sense to calculate the difference in dates for two different owner party ids.
    Any advice much appreciated.
    Thanks
    Edited by: 992871 on 09-Mar-2013 23:34

    Couple notes:
    1. You wrote you want to get order that these memberships are taken out in, however, both your and Etbin's queries calculate order within each owner_party_id and not across all members. If you want to get rank and difference in time regardless of member's owner_party_id remove PARTITION BY caluse.
    2. You might want to use DENSE_RANK and not RANK depending how you want to display rank. If two people joined at the same time and were second in rank, analytic RANK will be:
    RANK
    1
    2
    2
    4
    5
    .while DENSE_RANK:
    DENSE_RANK
    1
    2
    2
    3
    4
    .SY.

  • Using WHERE command in property loader SQL query

    Hello All,
    Hopefully this will be a fairly straight forward question.
    I am attempting to use Property Loader to read in test limits from a SQL database. There are many types of models that need to be tested, each having a unique set of limits. I want to be able to retrieve the appropriate limits for the model of product under test.
    To do this I have the product model number available in a FileGlobal. The database contains a table with the test limit information with an identifying 'ModelNumber_Number' column.
    I have written the following SQL query achieve this:
    "SELECT *  FROM TESTLIMITS WHERE ModelNumber_Number=+ FileGlobals.ModelNumber"
    However, this is where I am confused. I'm not sure on the syntax for accessing a variable in the SQL command. I receive the following error:
    The multi-part identifier "FileGlobals.ModelNumber" could not be bound.
    Can someone please provide guidence on how to do this?
    Many thanks,
    Cam.
    Solved!
    Go to Solution.

    Thank you very much for your reply.
    Upon changing the query to as you suggest, I am presented with the following:
    Error In SQL Statement Expression. "SELECT *  FROM TESTLIMITS WHERE ModelNumber_Number = " + FileGlobals.ModelNumber
    Specified value does not have the expected type.
    The type of FileGlobals.ModelNumber is a numeric represented as a double precision 64 bit signed integer.
    The database column is also of type int 64.
    Can you suggest a solution?
    Many thanks.

  • Can give me examples and explantions on Using COPY and NOCOPY in pl-sql

    Can give me examples and explantions on Using COPY and NOCOPY in pl-sql

    If you use COPY then parameter is copied into procedure/function internal
    spae, so You can't modify parameter.
    If you use NOCOPY then parameter is not copied into procedure/function
    internal spae, so You can modify parameter.NOCOPY modifier serves the same purpose as "copy by value" and "copy by reference" concept (like in C++).
    Then you NOCOPY parameter you pass it's pointer in memory but not pass it's value into the stack.
    You can modify the value of this parameter in both cases. The essential difference is for NOCOPY not only the pointer copies much faster then the object itself but the semantic of exception processing is voilated because when the exception raises Oracle can't restore the initial state of parameter (because all changes where made using the memory pointer but not usual stack copie of parameter):
    SQL> create or replace package my_pkg
      2  is
      3   type t is table of number index by binary_integer;
      4   t1 t;
      5   procedure no_copy (a in out nocopy t);
      6   procedure with_copy(a in out t);
      7  end;
      8  /
    Package created.
    SQL> create or replace package body my_pkg
      2  is
      3 
      4   my_exc exception;
      5 
      6   procedure no_copy (a in out nocopy t)
      7   is
      8   begin
      9    for j in 1..10 loop
    10     a(j) := 1;
    11    end loop;
    12    raise my_exc;
    13   end;
    14 
    15   procedure with_copy (a in out t)
    16   is
    17   begin
    18    for j in 1..10 loop
    19     a(j) := 1;
    20    end loop;
    21    raise my_exc;
    22   end;
    23  
    24  end;
    25  /
    Package body created.
    SQL> declare
      2    t1 my_pkg.t;
      3  begin
      4    dbms_output.put_line('Count before ' || t1.count);
      5    begin
      6      my_pkg.no_copy(t1);
      7    exception
      8      when others then
      9        null;
    10    end;
    11    dbms_output.put_line('Count after ' || t1.count);
    12  end;
    13  /
    Count before 0
    Count after 10
    PL/SQL procedure successfully completed.
    SQL> declare
      2    t1 my_pkg.t;
      3  begin
      4    dbms_output.put_line('Count before ' || t1.count);
      5    begin
      6      my_pkg.with_copy(t1);
      7    exception
      8      when others then
      9        null;
    10    end;
    11    dbms_output.put_line('Count after ' || t1.count);
    12  end;
    13  /
    Count before 0
    Count after 0
    PL/SQL procedure successfully completed.Rgds.

  • Multiple and conditions in the same table

    Ok I am going to kick myself for this, but I can't figure it out. I am trying to figure out how to find employees which match multiple criteria in the same table.
    create table emp
    (empno number,
    name  varchar2(10))
    create table skills
    (skill_id   number,
    skill_code varchar2(20))
    create table emp_skills
    (empno    number,
    skill_id number,
    rating   number)
    insert into emp values(1, 'SMITH');
    insert into emp values(2, 'JONES');
    insert into skills values (1, 'SQL');
    insert into skills values (2, 'PLSQL');
    insert into skills values (3, 'JAVA');
    insert into emp_skills values(1,1, 8);
    insert into emp_skills values(1,2, 9);
    insert into emp_skills values(1,3, 10);
    insert into emp_skills values(2,1,9);
    insert into emp_skills values(2,2,2);
    insert into emp_skills values(2,3,7);Now I need to come up with a query finding all employees who match all 3 of the following criteria:
    1) Have at least a 5 rating in SQL
    2) Have at least a 6 rating in PLSQL
    3) Have at least a 7 rating in JAVA
    So using this I would expect to return only SMITH since his/her skills meet all 3 criteria. I dont want to use OR in my query since I want all 3 to match not just one of them.
    I have a feeling I will need to self join the table - but this is going to be part of a dynamic query for APEX where the users can choose the skills and ratings they want employees to adhere to, so I dont know the number of criteria or the exact criteria in advance. But I figure if I can get a proof of concept SQL I can make it work dynamically.
    Any ideas are appreciated - sorry for the long post but I figure more detail is better

    with es1 as(
    select s.skill_code, es.empno, es.rating
    from skills s, emp_skills es
    where s.skill_id = es.skill_id
    /* main */
    select e.*
    from emp e
    where
    exists
    (select 'x' from es1
    where es1.rating >= 5
    and es1.skill_code = 'SQL'
    and es1.empno = e.empno)
    and
    exists
    (select 'x' from es1
    where es1.rating >= 6
    and es1.skill_code = 'PLSQL'
    and es1.empno = e.empno)
    and
    exists
    (select 'x' from es1
    where es1.rating >= 7
    and es1.skill_code = 'JAVA'
    and es1.empno = e.empno)
    -- Addition (Another example)
    with es1 as(
    select s.skill_code, es.empno, es.rating
    from skills s, emp_skills es
    where s.skill_id = es.skill_id
    /* main */
    select e.*
    from emp e
    where
    (select count(distinct es1.skill_code) from es1
    where
    ((es1.rating >= 5 and es1.skill_code = 'SQL')
    or
    (es1.rating >= 6 and es1.skill_code = 'PLSQL')
    or
    (es1.rating >= 7 and es1.skill_code = 'JAVA')
    and es1.empno = e.empno)
    =3;

Maybe you are looking for

  • One button of the keyboard doesn't work correctly

    Hi there, I have a problem with my keyboard: One button of the keyboard doesn??t work correctly: I want to write down a vowel with an accent (like in French and Spanish?), but if I press the button ´ and then the vowel, TWO dashes (´´) and the vowel

  • Change source path in batch Job

    Hi Experts, my organization has created job in data services 3.2 to cleanse the data reading from excel flat files. the folder path was store in the global variable(I think) and now they have changed the directories hence is it throwing me below erro

  • Table maintenance in ECC6

    HI All, I have created a table in ECC 6, now after creating table maintenance generator when i try to maintain data this error comes when 'View/table ZHRPMT_REQPRO can only be displayed and maintained with restrictions'  I don't know why this error i

  • Can I set 2 iphones with the same Apple acount

    Can I set 2 different iPhones with the same Apple account?

  • Iphone 4S to full website

    I don't like the mobile website, how can I set the Safari to go to the full site my default?