High-load sql statement using v$sql

Hi,
Can any one please tell me, how do we find high load sql statement and it's user from v$SQL view.
what is the query to find it.
Thank you!

Hello,
You can run ADDM report and check its findings it will tell you tome stuff like the following:
     Finding
67      SQL statements consuming significant database time were found.
40.7      Time spent on the CPU by the instance was responsible for a substantial part of database time.
20.7      Individual SQL statements responsible for significant user I/O wait were found.
13.7      Individual database segments responsible for significant user I/O wait were found.Kind regards
Mohamed Elazab

Similar Messages

  • Performance between SQL Statement and Dynamic SQL

    Select emp_id
    into id_val
    from emp
    where emp_id = 100
    EXECUTE IMMEDIATE
    'Select '|| t_emp_id ||
    'from emp '
    'where emp_id = 100'
    into id_valWill there be more impact in performance while using Dynamic SQL?

    CP wrote:
    Will there be more impact in performance while using Dynamic SQL?All SQLs are parsed and executed as SQL cursors.
    The 2 SQLs (dynamic and static) results in the exact same SQL cursor. So both methods will use an identical cursor. There are therefore no performance differences ito of how fast that SQL cursor will be.
    If an identical SQL cursor is not found (a soft parse), the SQL engine needs to compile the SQL source code supplied, into a SQL cursor (a hard parse).
    Hard parsing burns a lot of CPU cycles. Soft parsing burns less CPU cycles and is therefore better. However, no parsing at all is the best.
    To explain: if the code creates a cursor (e.g. INSERT INTO tab VALUES( :1, :2, :3 ) for inserting data), it can do it as follows:
    while More Data Found loop
      parse INSERT cursor
      bind variables to INSERT cursor
      execute INSERT cursor
      close INSERT cursor
    end loopIf that INSERT cursor does not yet exists, it will be hard parsed and a cursor created. Each subsequent loop iteration will result in a soft parse.
    However, the code will be far more optimal as follows:
    parse INSERT cursor
    while More Data Found loop
      bind variables to INSERT cursor
      execute INSERT cursor
    end loop
    close INSERT cursorWith this approach the cursor is parsed (hard or soft), once only. The cursor handle is then used again and again. And when the application is done inserting data, the cursor handle is released.
    With dynamic SQL in PL/SQL, you cannot really follow the optimal approach - unless you use DBMS_SQL (a complex cursor interface). With static SQL, the PL/SQL's optimiser can kick in and it can optimise its access to the cursors your code create and minimise parsing all together.
    This is however not the only consideration when using dynamic SQL. Dynamic SQL makes coding a lot more complex. The SQL code can now only be checked at execution time and not at development time. There is the issue of creating shareable SQL cursors using bind variables. There is the risk of SQL injection. Etc.
    So dynamic SQL is seldom a good idea. And IMO, the vast majority of people that post problems here relating to dynamic SQL, are using dynamic SQL unnecessary. For no justified and logical reasons. Creating unstable code, insecure code and non-performing code.

  • Run sql statements in PL/Sql Developer without installing Oracle database?

    Hi all,
    I wish to ask is there any possibility to run Run sql statements in PL/Sql Developer without installing Oracle database?
    Regards.

    Hello Jimmy,
    this is the forum for the tool SQL Developer and, as the title says, *(Not for general SQL/PLSQL questions)*.
    PL/Sql Developer is not an Oracle tool, but from allound allroundautomations.
    And you need access to a database to run SQL statements. This does not need to be one installed by yourself.
    Regards
    Marcus

  • Multiple SQL statements in Init SQL in WLS 8.1

    How to seperate multiple SQL statements in Init SQL text box ?
    For example, I want to enter following two SQL statements. How do I seperate them.
    I tested with / and ; as seperator, but did not worked..
    alter session set nls_date_format = 'MM/DD/YYYY'
    set role xxx_role identified by xxxx

    Mahendra wrote:
    Thanks Joe.
    Following worked for Oracle 8.1.7Good news.
    but did not for 8.0.6
    SQL BEGIN EXECUTE IMMEDIATE 'ALTER SESSION SET nls_date_format = ''MM/DD/YYYY''';
    EXECUTE IMMEDIATE 'SET ROLE xxx identified xxx'; end;
    Do you know 8.0.6 syntax ?You might try asking oracle, but note that no one is supporting that old version
    of Oracle any longer...
    Joe
    >
    Mahendra
    Joe Weinstein <[email protected]> wrote:
    Hi.
    I found the syntax, I think. Try this:
    BEGIN EXECUTE IMMEDIATE 'ALTER SESSION SET nls_date_format = 'MM/DD/YYYY'';
    EXECUTE IMMEDIATE 'SET ROLE <<role name>> identified
    by <<pwd>>';END;
    Joe
    Mahendra wrote:
    Still getting following exception.
    <Feb 19, 2004 1:47:58 PM EST>
    <Warning>
    <JDBC> <BEA-001164>
    <Unable to initialize connection in pool "XXXX".
    Initialization
    SQL = "BEGIN alter session set nls_date_format = 'MM/DD/YYYY'; setrole xxxx_role
    identified by
    xxxx; END;".
    Received exception: "java.sql.SQLException: ORA-06550: line 1,column7:
    PLS-00103: Encountered the symbol "ALTER" when expecting one of thefollowing:
    begin declare exit for goto if loop mod null pragma raise
    return select update while <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> <<
    close current delete fetch lock insert open rollback
    savepoint set sql commit <a single-quoted SQL string>
    The symbol "update was inserted before "ALTER" to continue.
    ORA-06550: line 1, column 61:
    PLS-00103: Encountered the symbol "ROLE" when expecting one of thefollowing:
    transaction
    ".>
    <Feb 19, 2004 1:47:59 PM EST> <Notice> <WebLogicServer> <BEA-000355><Thread "Li
    Joe Weinstein <[email protected]> wrote:
    Mahendra wrote:
    Thanks for reply, but that did not worked.
    Get following exception
    Unable to initialize connection pool "POOL_NAME".
    Initialization SQL = "Select count(*) from ""SQL BEGIN alter sessionset nls_date_format
    = 'MM/DD/YYYY'; set role xxx_role identified by xxxx; END;"". Receivedexception:
    "java.sql.SQLException: ORA-00972: identifier is too long
    Since we have not given SQL before that statement, BEA is treating
    statment "SQL Begin ....." as a table name.
    Then I tried by putting SQL out side quotes, like SQL "Begin .....end;" but the
    same error.
    Is there any way around it ?
    MahendraHi. The full string you should enter into the console when you define
    the
    initSQL parameter is:
    SQL BEGIN alter session set nls_date_format = 'MM/DD/YYYY'; set role
    xxx_role identified by xxxx; END;
    Let me know...
    Joe
    Joe Weinstein <[email protected]> wrote:
    Mahendra wrote:
    How to seperate multiple SQL statements in Init SQL text box ?
    For example, I want to enter following two SQL statements. How do
    I
    seperate them.
    I tested with / and ; as seperator, but did not worked..
    alter session set nls_date_format = 'MM/DD/YYYY'
    set role xxx_role identified by xxxxThis will always be DBMS-specific. If this is for oracle, you can
    try:
    "SQL BEGIN alter session set nls_date_format = 'MM/DD/YYYY'; setrole
    xxx_role identified by xxxx; END;"
    Joe

  • Date formats for SQL statements used by recordset object

    Hi,
    Date formatting appears to be quite problematic for Business One.  I did a forum search for date issues and I don't think I saw any of them with an "answered" status.  I have an issue with formatting a date for the creation of an SQL statement that the DI sends to SQL Server 2005.  I need to format a date so that the localization parameters don't matter for either the client machine or SQL Server's machine.  We don't have a problem as long as our machines are localized as USA.
    I have PL 22 and I have a form - ours - where I use the Today() function to fill a date field.  So this is a date that is not entered by the user.  The result of this function is consistent with the localization parameters on my machine.  We have two other date fields on the form where the user must type in the date. 
    As a test, I changed my machine to the UK parameters.  I then set up the language parameters of Business One for English(United Kingdom).  I changed the date format specifications in Business One so that its format is dd/mm/yy.  I then brought up the form and the field that is formatted by the above function arrived in the form's field as dd/mm/yy.  I then typed in the two other dates in the same format and added the record to the database.  The form's table is user-defined. 
    I dismissed the form then brought it back up loaded with the new record.  The date that was entered by the function appeared in USA format (mm/dd/yy).  The dates that were typed in appeared in the Business One format (dd/mm/yy).  This of course is not consistent.
    When I looked at what got into the database, the formats were the opposite.  Weird!  To make matters really confusing, I run an SQL statement within SQL Server Mgt Studio, and use the WHERE clause to filter on the date that was based on the function.  It didn’t matter what format I used for the WHERE clause, the record came up.  Does anyone have any idea about how I can ensure that I always use the correct date format for SQL statements passed by Business One to SQL Server regardless of where in the world the application is being run?
    Thanks,
    Mike

    Ian,
    Here's what I'm concerned about:  I’m using the date in a “WHERE” clause.
    Assume the date is Aug 3, 2007.
    "SELECT * FROM Table WHERE StartDate > ‘8/3/2007’"
    OR
    "SELECT * FROM Table WHERE StartDate > ‘3/8/2007’"
    If the client machine is set up as USA, the today function will provide the date as formatted in the first query.  If the database server is setup as let’s say the UK, I believe that SQL Server query parser will interpret the date as Mar 8, 2007.
    If the client machine is set up as UK, the today function will provide the date as formatted in the second query.  If the database server is setup as let’s say USA, I believe that SQL Server query parser will also interpret the date as Mar 8, 2007.
    In both cases it would be wrong.
    I know I could use the DATEPART function to get the three parts and this will make the code indifferent to the localization specs of the client machine.  I need to then be able to concatenate those date parts for the “WHERE” clause so that the localization specifications of the database server don’t matter.
    Thanks,
    Mike

  • Execute Dynamic SQL statement using procedure builder

    i want to execute a dynamic SQL statment using procedure builder not using forms
    because my statement depending on a variable table name
    i know that i can do that from forms using
    FORMS_DDL('SQL_STAT');
    but i wanna to use the procedure builder
    which function i should use and how?
    please explain in example if you don't mind.
    thanks

    Hi,
    You can very well use DBMS_SQL Package supplied by Oracle for doing this.
    Search for DBMS_SQL in OTN. You will get all info regarding this.
    Regards.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by itslul:
    i want to execute a dynamic SQL statment using procedure builder not using forms
    because my statement depending on a variable table name
    i know that i can do that from forms using
    FORMS_DDL('SQL_STAT');
    but i wanna to use the procedure builder
    which function i should use and how?
    please explain in example if you don't mind.
    thanks<HR></BLOCKQUOTE>
    null

  • SQL Statement using Undo Tablespace

    Hi
    Is there a way to find out which SQL Statement is using the highest amount of Undo Tablespace ?

    Query v$undostat.
    Use column "MAXQUERYID" for identgifying long running queries.
    Refer Metalink Note 262066.1 for undo information.
    Regards
    Sethu

  • Buffer size for SQL statement using JDBC calls

    I need to find out the buffer size for SQL statements in jave/JDBC because I need to insert or update a field that could be up to 4KB in size.

    I'm not sure that I follow the question; I'm not sure which buffer size you're referring to.
    If you have a field that can store up to 4k worth of data, you would create a VARCHAR2(4000) column in the Oracle database (assuming it is character data) or a BLOB column (if the data is binary). Either of those two fields can be populated from JDBC.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Possible to do "grant" sql statement in Native SQL?

    We have a need to do a grant of access from one of our systems out for various applications.  In order for this to work we need to run a grant access command on the table and are trying to put a wrapper around this so we can use an abap.  Below is the code I am unit testing.  Two questions.  First, can a grant be done via native SQL in abap?  Second, if it can be done, what is the error with the logic where I am trying to put in the table name via a parameter.
    REPORT  ZLJTEST2.
    tables dd02l.
    DATA scarr_carrid TYPE dd02l-tabname.
    SELECT-OPTIONS s_carrid for dd02l-tabname no intervals.
    DATA s_carrid_wa LIKE LINE OF s_carrid.
    DATA name TYPE c LENGTH 20.
    TRY.
        EXEC SQL.
          CREATE FUNCTION selfunc( input CHAR(20) )
            RETURNING char(20);
            DEFINE output char(20);
            set schema sapr3;
            grant select on table input to group infouser;
            RETURN output;
            END FUNCTION;
        ENDEXEC.
        LOOP AT s_carrid INTO s_carrid_wa
                         WHERE sign = 'I' AND option = 'EQ'.
          TRY.
             EXEC SQL.
                EXECUTE PROCEDURE selfunc( IN  :s_carrid_wa-low,
                                           OUT :name )
              ENDEXEC.
              WRITE: / s_carrid_wa-low, name.
            CATCH cx_sy_native_sql_error.
              MESSAGE `Error in procedure execution` TYPE 'I'.
          ENDTRY.
        ENDLOOP.
        EXEC SQL.
          DROP FUNCTION selfunc;
        ENDEXEC.
      CATCH cx_sy_native_sql_error.
        MESSAGE `Error in procedure handling` TYPE 'I'.
    ENDTRY.

    Hi,
    Yes it is posible.
    I made one program like you want. But it need very long code.
    Here I explain the idea:
    1. Create Screen with input TEXT EDIT CONTROL.
        This is for input SQL Statement.
    2. Get SQL Statement from Text Edit Control using method <b>get_text_as_r3table</b>.
    3. Now we need to separate SQL Statement into different table.
        We Separate SELECT, FROM, WHERE, GROUP, HAVING, ORDER, etc.
    4. We need dynamic internal table to store the data.
    5. Select the data according SQL statement.
          SELECT (IT_SELECT)
            into corresponding fields of table  <dyn_table>
          FROM (IT_FROM)
          WHERE (IT_WHERE)
          GROUP BY (IT_GROUP)
          HAVING (IT_HAVING)
          ORDER BY (IT_ORDER).
    6. Display our data using ALV GRID
    Hopefully it will help you.
    Regards,

  • SQL statement works with SQL/Plus - but not with ODBC

    Hi all,
    I have a rather copmplex SQL statement:
    BEGIN
    UPDATE ContentDataTable
    SET SYMBOLIC_PATH_PARENT = N'/Test',
    SYMBOLIC_NAME = N'HAWK01.GIF',
    VERSION_NUMBER = 1 +
    SELECT MAX(VERSION)
    FROM
    (SELECT MAX(VERSION_NUMBER) AS VERSION
    FROM ContentDataTable WHERE
    SYMBOLIC_PATH_PARENT = N'/Test' AND
    SYMBOLIC_NAME = N'HAWK01.GIF'
    UNION
    SELECT MAX(VERSION_NUMBER) AS VERSION
    FROM RevisedContentDataTable WHERE
    SYMBOLIC_PATH_PARENT = N'/Test' AND
    SYMBOLIC_NAME = N'HAWK01.GIF'))
    WHERE SYMBOLIC_PATH_PARENT = N'/Test' AND SYMBOLIC_NAME = N'HAWK02.GIF' AND VERSION_NUMBER = 1;
    END;
    It works fine in SQL/Plus or SQL Worksheet and does what it should do ;-)
    But when using it via ADO (ODBC Driver) I get the following error:
    PLS-00103 found 'string' but expected one of the following: 'string'"}
    Any idaes?
    Thanx,
    Christian
    null

    Pardon my ignorance, but what's the significance of the N'<string>' construction? That's not one I'm familar with.
    Justin

  • SQL statement inside a SQL statement

    Hello,
    I'm trying to write a SQL statement to a field in a table ( so that i can store some sql statements in a table) For the most part this code works fine (where string1 is the statement):
    updatestring1 = "update [@SQLSTATEMENTS] set [U_statement] = '" & qstring1.ToString & "' where [Code] = " & row
    oRecordSet.DoQuery(updatestring1)
    but when the statement that i want to save contains a WHERE clause that refernces a string (enclosed by single quotes), the update query fails - because of the quotes i think.
    I'm thinking i might be able to use different symbols in the statement to signify that it is a string but i'm not sure...
    Is there a better way to write the query to a field in a table ? maybe one that doesn't require an update query ? I'm pretty new to SDK (and SQL), so any advice will help - even if it's something really obvious...
    Thanks!

    I am not sure why you need to save SQL queries in the table but, you need to follow up a single quote with another single quote. for example look at the following sql string
    update customer set custname  = 'Customer'' A'  where custid = 'CustA'
    'IS correct
    However the following will fail
    update customer set custname  = 'Customer' A'  where custid = 'CustA'
    Message was edited by: Indika Dekumpitiya

  • Optimizing an SQL Query using Oracle SQL Developer

    Hi ,
    Currently i am using Oracle SQL Developer as my Database IDE .
    Is it possible to use Orqcles SQLDeveloper for the purpose of Optimizing an SQL Query ??
    For example assume i am having a query as :
    Select from Tranac_Master where CUST_STATAUS='Y' and JCC_REPORT='N'*
    Could anybody please tell me how can i use Oracle SQL Developer to optimize this query or any other SQL queries ??
    Please share your ideas , thanks in advance .

    1. Your query looks very simplistic as it is, so I fail to see how you can better optimise it (unless 'Tranac_Master' is a view, in which case I'd need to see the view details).
    2. No tool can automagically optimise your SQL to any degree of practical use. Very minor adjustments may be possible automatically, but really it is a question of you knowing your data & database design accurately, and then you applying your expert knowledge to tune it.

  • FD leaks on high load in JBOSS using Selector

    We observed FD leaks when our application is moved from Geronimo to  JBOSS. Ours is a multi-threaded application getting a response from UDP server.
    We were using Selector and DatagramChannel. we saw FD leak on high load. But when I removed Selector usage, the same does not leak any FDs.
    Is there any known issue in JDK?
    Thanks

    JBoss and Geronimo both run on top of Java.
    Obviously if you are using the same Java version for both then it is unlikely to be a JDK problem.
    If you are using a different version then there are too many variables to determine the cause.  So reduce the number of variables by using the same Java version.

  • SQL statement using result of aggregate min function to fetch a row - how?

    Need help trying to get to something seemingly simple. I'll provide a simple example to illustrate the problem.
    I'll be using a simple addresses table with 4 fields.
    Create the table:
      CREATE TABLE "ADDRESSES"
       (     "OWNER_NAME" VARCHAR2(20 BYTE),
         "STREET_NAME" VARCHAR2(20 BYTE),
         "STREET_NUMBER" NUMBER
       ) ;populate with 6 rows
    Insert into ADDRESSES (OWNER_NAME,STREET_NAME,STREET_NUMBER) values ('FRED','MAIN',1);
    Insert into ADDRESSES (OWNER_NAME,STREET_NAME,STREET_NUMBER) values ('JOAN','MAIN',2);
    Insert into ADDRESSES (OWNER_NAME,STREET_NAME,STREET_NUMBER) values ('JEAN','MAIN',3);
    Insert into ADDRESSES (OWNER_NAME,STREET_NAME,STREET_NUMBER) values ('JACK','ELM',1);
    Insert into ADDRESSES (OWNER_NAME,STREET_NAME,STREET_NUMBER) values ('JANE','ELM',2);
    Insert into ADDRESSES (OWNER_NAME,STREET_NAME,STREET_NUMBER) values ('JEFF','ELM',3);We now have this:
    Select * from addresses
    OWNER_NAME           STREET_NAME          STREET_NUMBER         
    FRED                 MAIN                 1                     
    JOAN                 MAIN                 2                     
    JEAN                 MAIN                 3                     
    JACK                 ELM                  1                     
    JANE                 ELM                  2                     
    JEFF                 ELM                  3                     
    6 rows selectedNow i wish to group by StreetName, and get a count of houses. At the same time, i'd like to know the first and last house number
        select
        street_name,
        count(*) "NBR HOUSES",
        min(street_number) "First Number",
        max(street_number) "Last Number"
         from addresses
        group by street_name
    produces
    STREET_NAME          NBR HOUSES             First Number           Last Number           
    ELM                  3                      1                      3                     
    MAIN                 3                      1                      3                     
    2 rows selectedExcellent. Now for the problem. I wish to also list on each line, the owner that lives at the first and/or last house number. Note again, assume that house number and street name is unique
    It would seem i have all that i need. Not sure how to get at it.
    I tried:
    select
        street_name,
        count(*) "NBR HOUSES",
        min(street_number) "First Number",
        max(street_number) "Last Number",
        (Select b.owner_name from addresses b where b.street_number = min(street_number) and b.owner_name = owner_name) "First Owner"
         from addresses
        group by street_nameBut get a sql syntax error, group function not allowed when i add the subselect.
    any ideas?
    thanks for any help.
    Edited by: user6876601 on Nov 19, 2009 7:08 PM
    Edited by: user6876601 on Nov 19, 2009 7:30 PM

    Hi,
    Welcome to the forum!
    Getting the highest and lowest number for each street is a fairly simple concept; simpler to describe, and simple to code.
    Now you want the owner_name associated with the highest and lowest number, which is a more complicated concept; a little harder to describe, and, unfortunately, much less simple to code, and much, much harder to explain:
    select
        street_name,
        count (*)                "NBR HOUSES",
        min (street_number)      "First Number",
        min (owner_name) KEEP (DENSE_RANK FIRST ORDER BY street_number)
                        "First Owner",
        max (street_number)      "Last Number",
        min (owner_name) KEEP (DENSE_RANK LAST ORDER BY street_number)
                        "Last Owner"
         from addresses
        group by street_name
    ;Notice that I used min for both "First Owner" and "Last Owner". Why is that?
    The important keyword in these funtions is the word FIRST or LAST that comes after DENSE_RANK and before ORDER BY. The function at the beginning is merely a tie-breaker.
    That is, MIN in this context only refers to what should happen when there is a tie for the first or last in the group. Even if such a thing is impossibe in your data, the generic functions have to have some mechanism for returning a single owner_name when two or more rows have an equal claim to having the highest street_number. For example, if we change Joan's address to 1 Main, then MIN (street_number) is still 1, obviously, but who is the person associated with the minimum street_number: is it Fred or Joan? Both have an equal claim to being the owner with the lowest address on Main Street, but aggregate functions must return a single value, so we have to have some mechanism for tell the system whether to return 'JOAN' or 'FRED'. In this example, I arbitrarily said that in the een of a tie, the lowest name, in alphabetic order, should be returned. In this case, 'FRED' would be returned, since 'FRED' is earlier than 'JOAN' .
    Thanks for including the CREATE TABLE and INSERT statements!

  • Using a string as sql statement in PL/SQL

    Hi there,
    I have a function which returns a part of a query depending on some conditions.
    FUNCTION GET_REPORT_TYPE(in_report_type IN NUMBER)
    RETURN VARCHAR2
    AS
    reporttype varchar2(50);
    BEGIN
    CASE in_report_type
    WHEN 0 THEN
    reporttype := 'C1.DATE_CLOSED != NULL';
    WHEN 1 THEN
    reporttype := 'C1.DATE_CLOSED := NULL';
    WHEN 2 THEN
    reporttype := '';
    END CASE;
    RETURN reporttype;
    END GET_REPORT_TYPE;
    Now in my procedure I would like to put this returned value in an AND clause of my query:
    procedure get_cpl(p_cursor OUT rst_cur, searchcode IN VARCHAR2, reporttype IN VARCHAR2)
    is
    begin
    open p_cursor for
    SELECT C1.CIPIDI_NR,
    C1.CIPIDI_NAME,
    C2.TEAM_MEMBER
    FROM TBL_CIPIDI C1, TBL_TEAM_MEMBERS C2
    WHERE C1.CIPIDI_NR LIKE searchcode
    AND C1.CIPIDI_NR = C2.CIPIDI_NR (+);
    AND reporttype; -- HERE I WOULD LIKE TO USE WHAT THE FUNCTIONS RETURNED
    end get_cpl;
    How can I can I use reporttype to function as a part of the query? Thanks a lot
    Chris

    scott@ORA92> -- test data:
    scott@ORA92> SELECT * FROM tbl_cipidi
      2  /
    CIPIDI_NR CIPIDI_NAME DATE_CLOS
             1 name1       30-MAY-05
             1 name2
    scott@ORA92> SELECT * FROM tbl_team_members
      2  /
    CIPIDI_NR TEAM_MEMBER
             1 team1
    scott@ORA92> -- function:
    scott@ORA92> CREATE OR REPLACE FUNCTION GET_REPORT_TYPE
      2    (in_report_type IN NUMBER)
      3    RETURN            VARCHAR2
      4  AS
      5    reporttype       varchar2(50);
      6  BEGIN
      7    CASE in_report_type
      8        WHEN 0 THEN reporttype := 'C1.DATE_CLOSED IS NOT NULL';
      9        WHEN 1 THEN reporttype := 'C1.DATE_CLOSED IS NULL';
    10        ELSE reporttype := '1 = 1';
    11    END CASE;
    12    RETURN reporttype;
    13  END GET_REPORT_TYPE;
    14  /
    Function created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> -- packaged with procedure:
    scott@ORA92> CREATE OR REPLACE PACKAGE your_pkg
      2  AS
      3    TYPE rst_cur IS REF CURSOR;
      4    procedure get_cpl
      5        (p_cursor   OUT rst_cur,
      6         searchcode IN  VARCHAR2,
      7         reporttype IN  VARCHAR2);
      8  END your_pkg;
      9  /
    Package created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> CREATE OR REPLACE PACKAGE BODY your_pkg
      2  AS
      3    procedure get_cpl
      4        (p_cursor   OUT rst_cur,
      5         searchcode IN  VARCHAR2,
      6         reporttype IN  VARCHAR2)
      7    is
      8    begin
      9        OPEN p_cursor FOR
    10        'SELECT C1.CIPIDI_NR,
    11             C1.CIPIDI_NAME,
    12             C2.TEAM_MEMBER
    13         FROM      TBL_CIPIDI C1, TBL_TEAM_MEMBERS C2
    14         WHERE  C1.CIPIDI_NR = :b_searchcode
    15         AND      C1.CIPIDI_NR = C2.CIPIDI_NR (+)
    16         AND ' || get_report_type (reporttype)
    17        USING searchcode;
    18    end get_cpl;
    19  END your_pkg;
    20  /
    Package body created.
    scott@ORA92> SHOW ERRORS
    No errors.
    scott@ORA92> -- tests:
    scott@ORA92> VARIABLE g_ref REFCURSOR
    scott@ORA92> SET AUTOPRINT ON
    scott@ORA92> EXECUTE your_pkg.get_cpl (:g_ref, 1, 0)
    PL/SQL procedure successfully completed.
    CIPIDI_NR CIPIDI_NAME TEAM_MEMBER
             1 name1       team1
    scott@ORA92> EXECUTE your_pkg.get_cpl (:g_ref, 1, 1)
    PL/SQL procedure successfully completed.
    CIPIDI_NR CIPIDI_NAME TEAM_MEMBER
             1 name2       team1
    scott@ORA92> EXECUTE your_pkg.get_cpl (:g_ref, 1, 2)
    PL/SQL procedure successfully completed.
    CIPIDI_NR CIPIDI_NAME TEAM_MEMBER
             1 name1       team1
             1 name2       team1
    scott@ORA92>

Maybe you are looking for