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

Similar Messages

  • Multiple Select statements in EXECUTE SQL TASK in SSIS

    Can we write multiple select statements in execute sql task(SSIS).
    If possible how to assign them to variables in result statement

    Hi ,
    You can use below steps to set result set to variable.
    1.In the Execute SQL Task Editor dialog box, on the General page, select the Single row, Full result set, or XML result set type(According to your result set).
    2.Click Result Set.
    3.To add a result set mapping, click Add.
    4.From the Variables Name list, select a variable or create a new variable.
    What is multiple selection ? May be below can be used in your scenario !
    http://stackoverflow.com/questions/17698908/how-to-set-multiple-ssis-variables-in-sql-task
    What you want to achieve ?
    Thanks
    Please Mark This As Answer or vote for Helpful Post if this helps you to solve your question/problem. http://techequation.com

  • 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 select statements in PL/SQL

    Hi All
    I am new to PL/SQL and my experience is in writing TSQL. There we can write a SQL statement like this to return 3 result set
    SELECT empname FROM Employee
    SELECT authname FROM Author
    SELECT athname FROM sport
    how can we write the same 3 statements in PL/SQL and attain the 3 resultsets.
    I tried to implement the same using PL/SQL anonymous blocks. But it didn't worked.
    DECLARE
    P_RECORDSET OUT SYS_REFCURSOR
    BEGIN
    OPEN P_RECORDSET FOR
    SELECT empname FROM Employee;
    SELECT authname FROM Author;
    SELECT athname FROM sport;
    END;
    can anybody show how it can be done.
    Thanks in advance
    George
    Edited by: user6290570 on Sep 16, 2009 11:23 PM

    george2009 wrote:
    No i just want to select 3 result sets from 3 select statements, so that it is helpful to compare the resultsets. Compare? How? This is done using the SQL language. Not PL/SQL. Not Java. Not VB. Not anything else.
    You would use these other language for flow control and certain forms of conditional logic - but the actual comparison of data sets is done in SQL.
    Of course, that is if you do want to do it the most optimal way, that will perform well, and scale well.
    SQL is not an I/O API layer - to be used to read() a record and write() a record as if the RDBMS is an ISAM file. That form of row-by-row and slow-by-slow processing dates back to the 80's when we used Cobol.. (or at least for those old farts like me that can actually remember coding in Cobol in the 80's ;-) ).
    You want to design and code database applications that are fast, robust, and can scale? Then learn how to use SQL correctly.

  • 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

  • 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

  • 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

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

  • Multiple SQL statements in dynamic SQL

    Hello experts,
    is there a possibility in Oracle (in sybase and ms sql there is one) to place in dynamic query several SQL (e.g. SELECT) statements and to execute them additionally?
    Example:
    v_sqlQuery :='
    SELECT column_1
    FROM table_a
    SELECT column_1
    FROM table_b'
    open cv_1 for to_char(v_sqlQuery);
    or
    v_sqlQuery='
    SELECT x, y INTO #temp_table FROM table_x
    SELECT y FROM #temp_table';
    Thank you in advance!
    anton

    Hi cth,
    not in pl block, but within dynamic query. An example what I want to do:
    What is actually need to be done is
    1)to read and count all IDs into temporary table doc_id_count.
    2)to read and count all IDs and marital_fields into table status_presel
    3) to match data using their ids
    Ouput would be like:
    v_doc_id married single widowed
    Miller 2 3 4
    I think the idea is becomming more clear - to write data in temporal table and then read them in the next SELECT statement by matching the IDs.
    Comment: I am using a wrong syntax (T-SQL syntax) for coping into temporary tables.
    v_counter := '
    SELECT
    NAMES.' || v_doc_id || '
    ,Count(*) Count
    INTO #doc_id_count
    FROM
    NAMES
    GROUP BY
    ....-- group by v_doc_id
    v_status_pre := '
    SELECT
    NAMES.' || v_doc_id || '
    ,NAMES.'|| v_marital_field || ' status_field
    ,COUNT(*) Count
    INTO #status_presel
    FROM
    NAMES
    GROUP BY
    ... -- group by v_doc_id and v_marital_field
    ORDER BY
    v_status := '
    SELECT
    #doc_id_count.' || v_doc_id || '
    ,#status_presel.Count married
    ,status_1.Count single
    ,status_pre2.Count widowed
    FROM
    #doc_id_count
    LEFT OUTER JOIN #status_presel
    ON ...
    AND #status_presel.status_field = ''married''
    LEFT OUTER JOIN #status_presel status_1
    ON ...
    AND status_1.status_field = ''single''
    LEFT OUTER JOIN #status_presel status_2
    ON ...
    AND status_2.status_field = ''widowed''
    ORDER BY
    v_sql := v_counter + v_status_pre + v_status;
    open cv_1 for to_char(v_sqlQuery);

  • Multiple case statements with aggregates- SQL

    Hi guys
    Here is my ddl
    create table TestTable
      Bill_date                    DATE,
      Phone_no                     NUMBER(10),
      Planlvl1                     VARCHAR2(20),
      Planlvl2                     VARCHAR2(20)
      Revenue                      NUMBER                     
    INSERT INTO TestTable
    Values
    ('1/01/2014' , 64221, 'Bundle', 'SpecialPack1', '$23'),
    ('1/01/2014'' , 64221, 'Bundle', 'PlanA', '$32'),
    ('1/01/2014' , 65211, 'Bundle', 'SpecialPack2', '$3'),
    ('1/01/2014' , 65211, 'Bundle', 'SpecialPack1', '$23'),
    ('1/01/2014' , 66211, 'Bundle', 'PlanB', '$34'),
    ('1/01/2014' , 66211, 'Bundle', 'SpecialPack2', '$3'),
    ('1/01/2014' , 66222, 'Bundle', 'SpecialPack1', '$23'),
    ('1/01/2014' , 66222, 'Bundle', 'SpecialPack2', '$3'),
    ('1/01/2014' , 66222, 'Bundle', 'PlanB', '$65'),
    ('1/01/2014' , 32444, 'Non_bundle', 'Casual1', '$32'),
    ('1/01/2014' , 324441, 'Non_bundle', 'Casual2', '$76'),
    ('1/01/2014' , 65444, 'Non_bundle', 'Casual1', '$12'),
    ('1/01/2014' , 65444, 'Bundle', 'PlanB', '$98'),
    ('1/01/2014' , 54322, 'Bundle', 'PlanA', '$12'),
    ('1/01/2014' , 54322, 'Non_bundle', 'Casual', '$12')
    Expected Outcome:
    Bill_date PlanLvl2 PhonenoCount
    '01/01/2014' 'SpecialPack1' 1
    '01/01/2014' 'SpecialPack2' 3
    '01/01/2014' 'Casual1' 1
    '01/01/2014' 'Casual2' 1
    '01/01/2014' 'PlanA' 1
    '01/01/2014' 'PlanB' 1
    Basically I have to count all the phone nos grouped by plans in a certain way:
    If PlanLvl1 = Bundle, then I have to look  at planLvl2 and see if that phone no has ' SpecialPack%' ,and also another plan,them 'Special pack' gets the priority and the phone no gets counted in the special pack.
    In case when PlanLvl1 = Bundle and a phone no has both 'Special Packs' as their plans, then the phone no will be counted under the 'Special Pack' with higher Revenue.
    In case where PalnLvl is 'Bundle' and a phone no has multiple 'Special Packs' and a non special, that ph no will only be counted once under 'Special Pack; of higher rev as compared to the special pack of lower rev.
    Now there are also PlanLvl1 which are 'Non_Bundles' which means they do not have any 'SpecialPacks' but if a ph no with 'NonBundle' plan has 2 different plans under planLvl2, we need to count that ph no for eack planLvl2..
    Then there is a scenario where a ph no can have bundles as well as non bundles and in that case we just have to count that ph no in bundles and not in non-bundles.
    As I mentioned , 'SpecialPack2' will get a preference over special pack 1 if a phone no has got both of these
    Hope this helps

    I;m not sure exactly what your rules are since you specify both "In case when PlanLvl1 = Bundle and a phone no has both 'Special Packs' as their plans, then the phone no will be counted under the 'Special Pack' with higher Revenue" and "As I mentioned ,
    'SpecialPack2' will get a preference over special pack 1 if a phone no has got both of these".  I went with the rule "As I mentioned , 'SpecialPack2' will get a preference over special pack 1 if a phone no has got both of these" since that seemed to match
    the result you say you want.  I also changed the datatypes to valid SQL Server datatypes.
    create table TestTable
    Bill_date DATE,
    Phone_no Decimal(10,0),
    Planlvl1 VARCHAR(20),
    Planlvl2 VARCHAR(20),
    Revenue money
    INSERT INTO TestTable
    Values
    ('1/01/2014' , 64221, 'Bundle', 'SpecialPack1', '$23'),
    ('1/01/2014' , 64221, 'Bundle', 'PlanA', '$32'),
    ('1/01/2014' , 65211, 'Bundle', 'SpecialPack2', '$3'),
    ('1/01/2014' , 65211, 'Bundle', 'SpecialPack1', '$23'),
    ('1/01/2014' , 66211, 'Bundle', 'PlanB', '$34'),
    ('1/01/2014' , 66211, 'Bundle', 'SpecialPack2', '$3'),
    ('1/01/2014' , 66222, 'Bundle', 'SpecialPack1', '$23'),
    ('1/01/2014' , 66222, 'Bundle', 'SpecialPack2', '$3'),
    ('1/01/2014' , 66222, 'Bundle', 'PlanB', '$65'),
    ('1/01/2014' , 32444, 'Non_bundle', 'Casual1', '$32'),
    ('1/01/2014' , 324441, 'Non_bundle', 'Casual2', '$76'),
    ('1/01/2014' , 65444, 'Non_bundle', 'Casual1', '$12'),
    ('1/01/2014' , 65444, 'Bundle', 'PlanB', '$98'),
    ('1/01/2014' , 54322, 'Bundle', 'PlanA', '$12'),
    ('1/01/2014' , 54322, 'Non_bundle', 'Casual', '$12')
    ;With cte As
    (Select Bill_date, Phone_no, Planlvl1, Planlvl2, Revenue,
    Row_Number() Over (Partition By Bill_Date, Phone_no Order By
    Case When Planlvl1 = 'Bundle' And Planlvl2 Like 'SpecialPack2' Then 0 Else 1 End,
    Case When Planlvl1 = 'Bundle' And Planlvl2 Like 'SpecialPack1' Then 0 Else 1 End,
    Case When Planlvl1 = 'Bundle' Then Revenue Else -1 End Desc) As rn,
    Min(Case When Planlvl1 = 'Bundle' Then 0 Else 1 End) Over(Partition By Bill_Date, Phone_no) As NumberHasOnlyNonBundle
    From TestTable)
    Select Bill_date, Planlvl2, COUNT(*) As PhoneNoCount
    From cte
    Where rn = 1 Or NumberHasOnlyNonBundle = 1
    Group By Bill_date, Planlvl2;
    Tom

  • Variables & dynamic sql statements in PL/SQL

    Hi All,
    I'm sure I am missing something really simple, but I can't figure it out...
    In a procedure, I'm trying to 'build' a sequence name from a parameter (table name), and then select the nextval into another variable to be used later. But I don't seem to be doing it correctly...
    First I created a var to hold the full sequence name (table_name_seq.nextval) like this:
    v_Sequence_Name := '"'||param_table_name||'_Seq".nextval';This seems to work correctly as I have output the value and I get what I am expecting. Next I try to use the new variable in a select statement like so:
    -- I've tried many variations here, but none have worked
    select v('v_Sequence_Name') into v_Sequence_ID from dual;I end up with a Null I think (because I insert the value into a test table).
    Any ideas what I am doing wrong?
    TIA,
    Corey

    dynamic query in pl/sql needs to be executed using exec. immediate statement or the dbms_sql package.
    here's what you can do :
    execute immediate 'select '|| v_sequence_name ||' from dual' into v_sequence_id;

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

  • Can we give multiple select statements in one function in PL/SQL

    Hi All,
    I am new to the PL/SQL. Can you please help me with the following problem.
    I am cretaing a function in which I have to extract some fields from three tables and to handle three tables I am first extracting the primary key from one table(acting as a foreign key for other table) in a variable declared in declare section, then I am selecting the required fields from the other table by giving that variable name in Where condition. My code is attached as well.
    e.g
    Create or Replace function <function name>(arguments)
    Return return type
    AS
    a1 a%TYPE;
    b_new b%TYPE;
    n fn%TYPE
    Select a into a1 from table1 where b like b_new;
    Select fn into n from table2 where id like a1;
    return a1,n; (can we pass record like this?)
    end;

    Left's first look at the approach you use.. 2 SQL statements that can be done using a single SQL statement.
    Actually it is not as bad as some other code posted here where people go and write complex PL/SQL code to do what could have been done using a single SQL statement.
    There are a couple of golden rules in Oracle development. One of these is to 'Maximise SQL and Minimise PL/SQL'.
    Why take a value from one SQL statement into PL/SQL and then use that value in a second SQL statement?
    Rather do this:
    select
    fn into n
    from table2
    where id like (Select a from table1 where b like b_new);Also keep in mind that in PL/SQL the above SQL construct is only able to fetch a single row - look at the bold above. The variable N can only hold a single value. If that SQL SELECT returns more than one value, how is variable N suppose to hold it?
    I suggest that you read [url http://www.oracle.com/pls/db102/to_toc?pathname=appdev.102%2Fb14261%2Ftoc.htm&remark=portal+%28Books%29]Oracle® Database PL/SQL User's Guide and Reference guide.

  • Can i use commit in between pl sql statements

    Hi,
    I have written program unit , in that I used insert statements and after that I used commit command.
    But in runtime it's getting oracle error unable to insert . because I used some non database items and database items
    so that it's coming error.
    But my question is , Can i use commit after executing some statements in program unit procedure.
    Thanks in advance.

    FORMS_DDL restrictions
    The statement you pass to FORMS_DDL may not contain bind variable references in the string, but the
    values of bind variables can be concatenated into the string before passing the result to FORMS_DDL.
    For example, this statement is not valid:
    Forms_DDL ('Begin Update_Employee (:emp.empno); End;');
    However, this statement is valid, and would have the desired effect:
    Forms_DDL ('Begin Update_Employee ('||TO_CHAR(:emp.empno)
    ||');End;');
    However, you could also call a stored procedure directly, using Oracle8's shared SQL area over
    multiple executions with different values for emp.empno:
    Update_Employee (:emp.empno);
    SQL statements and PL/SQL blocks executed using FORMS_DDL cannot return results to Form
    Builder directly.
    In addition, some DDL operations cannot be performed using FORMS_DDL, such as dropping a table
    or database link, if Form Builder is holding a cursor open against the object being operated upon.
    Sarah

Maybe you are looking for