Function/Proc

Hi I have to automate the update. I have 3 possible variables, VariantIdIN , QuestionIdIn and third is the column name. In the following example column name will be ACS_Sufferer. What are my options to automated the process? I tried to write a function but I don't know how to take the column name as a variable and update it. Please help.
DECLARE
CURSOR pharm_cur
IS
SELECT ms.rtvmemberid,
ms.StartTime,
MAX(CASE WHEN v.variantid = VariantIdIN THEN 'Y' ELSE 'N' END)ACS_Sufferer
FROM rsch_membersurvey_T4 ms, rsch_response r, rsch_variant v
WHERE mr.rsch_membersurveyid = ms.rsch_membersurveyid
AND ms.responseid = r.responseid
AND ms.variantid = v.variantid(+
AND r.questionid = QuestionIdIn
GROUP BY ms.rtvmemberid, ms.StartTime, ms.UpdateDate
ORDER BY ms.rtvmemberid, ms.UpdateDate;
BEGIN     
FOR pharm_rec IN pharm_cur
     LOOP
UPDATE prf_pharmasufferer ps
SET ACS_SUFFERER = decode(ps.ACS_SUFFERER,'Y','Y',pharm_rec.ACS_SUFFERER)
WHERE ps.rtvmemberid=pharm_rec.rtvmemberid
END LOOP;
END;
/

try this declaration
CURSOR pharm_cur IS
SELECT ms.rtvmemberid[b] rtvmemberid, ms.StartTime StartTime, ms.UpdateDate UpdateDate,
MAX(CASE WHEN v.variantid =Variantid_IN THEN 'Y' ELSE 'N' END) Sufferer
FROM rsch_membersurvey_pharma2 ms, rsch_memberresponse_pharma2 mr, rsch_response r,
rsch_variant v, rsch_survey s
WHERE mr.rsch_membersurveyid = ms.rsch_membersurveyid AND mr.responseid = r.responseid
AND mr.variantid = v.variantid(+) AND ms.completedind = 'Y'
AND mr.surveyid = s.surveyid
AND s.surveytype = 'Pharma2'
AND r.questionid = QUESTIONID_IN
GROUP BY ms.rtvmemberid, ms.StartTime, ms.UpdateDate;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

Similar Messages

  • Adding a db user via stored function/proc

    Does anyone have sample code for a proc/function to add a user? I want to pass in username, password and role....
    Thanks

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Mike McManus ():
    Does anyone have sample code for a proc/function to add a user? I want to pass in username, password and role....
    Thanks<HR></BLOCKQUOTE>
    Use this code given
    below this should help you.
    CREATE OR REPLACE PROCEDURE creat_user(iuser VARCHAR2, ipass VARCHAR2, irole VARCHAR2)
    AS
    BEGIN
    EXECUTE IMMEDIATE 'CREATE USER '&#0124; &#0124;iuser&#0124; &#0124;' IDENTIFIED BY '&#0124; &#0124;ipass;
    EXECUTE IMMEDIATE 'CREATE ROLE '&#0124; &#0124;irole&#0124; &#0124;' IDENTIFIED BY '&#0124; &#0124;ipass;
    END;

  • How can I create packages procedure & function in user-define Library

    hi.
    i am already created packages procedure & function in database and use so on.
    now i would like to create these in library file.
    please anyone give me example of any procedure or function to store in library.
    thanks
    Ali

    <FONT FACE="Arial" size=2 color="2D0000">> please send me one simple example for create library
    then create any function in library.
    2nd is any package can be create in library or not??
    Thanks S.K
    AliHave you checked the link?
    A simple example is provided.
    I think What I understood from your post is that, you want to put function/ Proc and want to call that as Library ..
    Which is not  possible.
    For exampel an external routine is a third-generation language procedure stored in a
    dynamic link library (DLL), registered with PL/SQL, and called by the DBA to perform
    special-purpose processing.
    In Unix a dynamic link library is known as a shared object (so).
    At run time, PL/SQL loads the library dynamically, then calls the routine as if it were a
    PL/SQL subprogram. To safeguard our database, the routine runs in a separate address
    space, but it participates fully in the current transaction. Furthermore, the routine can
    make a call back to the database to perform SQL operations.
    To identify a DLL we have to use CREATE LIBRARY command.
    The CREATE LIBRARY command is used to create a schema object, library, which
    represents an operating-system shared library, from which SQL and PL/SQL can call
    external third-generation-language (3GL) functions and procedures.
    Learn something more on External Procedures
    -SK
    </FONT>

  • VPD: Problems calling a function on another schema

    Here's the setup:
    I've create a schema called "AllYourBase".  It contains all of my tables, views, functions, procs, etc.
    These tables are protected by a DBMS_RLS policy.  The policy uses a function to define its predicate which looks like this:
    create or replace function tous_filter(schemaName varchar2, tableName varchar2)
    return varchar2 is
    begin
    return  'account = sys_context(''USERENV'', ''CLIENT_IDENTIFIER'')';
    end;
    All of the tables have an account column for this to work.  So far, this is a pretty basic VPD setup.
    I have other db users that login and view data in the "AllYourBase" schema.
    So when "ArbyLong" logs in, I set sys_context('USERENV', 'CLIENT_IDENTIFIER') to "ArbyLong", and when he runs a query, he gets back his rows.
    Now, "AllYourBase" has several functions.  Here's a very contrived, simplified example of one (but it illustrates the issue I'm running into just fine):
    create or replace function getUserID
    return integer is retval integer;
    begin
    select user_id into retval from users;
    return (retval);
    end;
    When "ArbyLong" runs the equivalent query (select user_id from users), he gets back the one row where the account column is equal to "ArbyLong", as expected.
    But this getUserID function lives in the "AllYourBase" schema.  And here's the catch: I've made "AllYourBase" exempt from the policies by running "grant exempt access policy to AllYourBase".
    When "ArbyLong" runs the function getUserID, it runs in the "AllYourBase" schema and pulls ALL of the rows from the users table.
    This particular function simply errors out (since it's only expecting one row), but other functions are returning data that the logged in user shouldn't see.
    So even though there are policies in place, by calling a function on another schema who is exempt from the policies, a user is able to see all returned data and not just the rows they are normally limited to.
    Ultimately my question is this: Is there a way to enforce VPD policies when a user calls a function that lives in another schema?
    Doing my own research, the answers I've come up with are:
    * Don't use "grant exempt policy"!
    * Put the function directly into the users' schemas.  So "ArbyLong" would have his own getUserID function that would look at the "AllYourBase" users table.
    I'd rather not do either of these, so does anyone have any other ideas?  If it turns out these are the only solutions, then I'll go with one of them.
    Thanks!

    Need more info. Are you using a ViewStack or other navigator container, and trying to access a view that has not been displayed yet, due to deferred instantiation?
    If this post answers your question or helps, please mark it as such.
    Greg Lafrance - Flex 2 and 3 ACE certified
    www.ChikaraDev.com
    Flex Training and Support Services

  • Grant authorization to stored procs

    I have users that I want to give them the ability to view functions, procs, packages (spec and body). If I give them execute any proc authority they can then see functions, procs and packages(spec only), however, they also need to see the package body. Any ideas on how to get this to work?

    Package bodies will not be seen unless the users has 'create any procedure' privilege.
    Alternatively you could create your own view based on all_source's definition and grant this view to your users.
    The catprc.sql file contains the view for all_source, all you need to do is change
    /* package body */
    o.type = 11 and
    privilege# = -141 /* CREATE ANY PROCEDURE */ to
    /* package body */
    o.type = 11 or
    privilege# = -141 /* CREATE ANY PROCEDURE */

  • PL/SQL 101 : Exception Handling

    Frequently I see questions and issues around the use of Exception/Error Handling in PL/SQL.  More often than not the issue comes from the questioners misunderstanding about how PL/SQL is constructed and executed, so I thought I'd write a small article covering the key concepts to give a clear picture of how it all hangs together. (Note: the examples are just showing examples of the exception handling structure, and should not be taken as truly valid code for ways of handling things)
    Exception Handling
    Contents
    1. Understanding Execution Blocks (part 1)
    2. Execution of the Execution Block
    3. Exceptions
    4. Understanding Execution Blocks (part 2)
    5. How to continue exection of statements after an exception
    6. User defined exceptions
    7. Line number of exception
    8. Exceptions within code within the exception block
    1. Understanding Execution Blocks (part 1)
    The first thing that one needs to understand is almost taking us back to the basics of PL/SQL... how a PL/SQL execution block is constructed.
    Essentially an execution block is made of 3 sections...
    +---------------------------+
    |    Declaration Section    |
    +---------------------------+
    |    Statements  Section    |
    +---------------------------+
    |     Exception Section     |
    +---------------------------+
    The Declaration section is the part defined between the PROCEDURE/FUNCTION header or the DECLARE keyword (for anonymous blocks) and the BEGIN keyword.  (Optional section)
    The Statements section is where your code goes and lies between the BEGIN keyword and the EXCEPTION keyword (or END keyword if there is no EXCEPTION section).  (Mandatory section)
    The Exception section is where any exception handling goes and lies between the EXCEPTION keyword at the END keyword. (Optional section)
    Example of an anonymous block...
    DECLARE
      .. declarative statements go here ..
    BEGIN
      .. code statements go here ..
    EXCEPTION
      .. exception handlers go here ..
    END;
    Example of a procedure/function block...
    [CREATE OR REPLACE] (PROCEDURE|FUNCTION) <proc or fn name> [(<parameters>)] [RETURN <datatype>] (IS|AS)
      .. declarative statements go here ..
    BEGIN
      .. code statements go here ..
    EXCEPTION
      .. exception handlers go here ..
    END;
    (Note: The same can also be done for packages, but let's keep it simple)
    2. Execution of the Execution Block
    This may seem a simple concept, but it's surprising how many people have issues showing they haven't grasped it.  When an Execution block is entered, the declaration section is processed, creating a scope of variables, types , cursors, etc. to be visible to the execution block and then execution enters into the Statements section.  Each statment in the statements section is executed in turn and when the execution completes the last statment the execution block is exited back to whatever called it.
    3. Exceptions
    Exceptions generally happen during the execution of statements in the Statements section.  When an exception happens the execution of statements jumps immediately into the exception section.  In this section we can specify what exceptions we wish to 'capture' or 'trap' and do one of the two following things...
    (Note: The exception section still has access to all the declared items in the declaration section)
    3.i) Handle the exception
    We do this when we recognise what the exception is (most likely it's something we expect to happen) and we have a means of dealing with it so that our application can continue on.
    Example...
    (without the exception handler the exception is passed back to the calling code, in this case SQL*Plus)
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    v_name VARCHAR2(20);
      3  begin
      4    select ename
      5    into   v_name
      6    from   emp
      7    where  empno = &empno;
      8    dbms_output.put_line(v_name);
      9* end;
    SQL> /
    Enter value for empno: 123
    old   7:   where  empno = &empno;
    new   7:   where  empno = 123;
    declare
    ERROR at line 1:
    ORA-01403: no data found
    ORA-06512: at line 4
    (with an exception handler, we capture the exception, handle it how we want to, and the calling code is happy that there is no error for it to report)
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    v_name VARCHAR2(20);
      3  begin
      4    select ename
      5    into   v_name
      6    from   emp
      7    where  empno = &empno;
      8    dbms_output.put_line(v_name);
      9  exception
    10    when no_data_found then
    11      dbms_output.put_line('There is no employee with this employee number.');
    12* end;
    SQL> /
    Enter value for empno: 123
    old   7:   where  empno = &empno;
    new   7:   where  empno = 123;
    There is no employee with this employee number.
    PL/SQL procedure successfully completed.
    3.ii) Raise the exception
    We do this when:-
    a) we recognise the exception, handle it but still want to let the calling code know that it happened
    b) we recognise the exception, wish to log it happened and then let the calling code deal with it
    c) we don't recognise the exception and we want the calling code to deal with it
    Example of b)
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    v_name VARCHAR2(20);
      3    v_empno NUMBER := &empno;
      4  begin
      5    select ename
      6    into   v_name
      7    from   emp
      8    where  empno = v_empno;
      9    dbms_output.put_line(v_name);
    10  EXCEPTION
    11    WHEN no_data_found THEN
    12      INSERT INTO sql_errors (txt)
    13      VALUES ('Search for '||v_empno||' failed.');
    14      COMMIT;
    15      RAISE;
    16* end;
    SQL> /
    Enter value for empno: 123
    old   3:   v_empno NUMBER := &empno;
    new   3:   v_empno NUMBER := 123;
    declare
    ERROR at line 1:
    ORA-01403: no data found
    ORA-06512: at line 15
    SQL> select * from sql_errors;
    TXT
    Search for 123 failed.
    SQL>
    Example of c)
    SQL> ed
    Wrote file afiedt.buf
      1  declare
      2    v_name VARCHAR2(20);
      3    v_empno NUMBER := &empno;
      4  begin
      5    select ename
      6    into   v_name
      7    from   emp
      8    where  empno = v_empno;
      9    dbms_output.put_line(v_name);
    10  EXCEPTION
    11    WHEN no_data_found THEN
    12      INSERT INTO sql_errors (txt)
    13      VALUES ('Search for '||v_empno||' failed.');
    14      COMMIT;
    15      RAISE;
    16    WHEN others THEN
    17      RAISE;
    18* end;
    SQL> /
    Enter value for empno: 'ABC'
    old   3:   v_empno NUMBER := &empno;
    new   3:   v_empno NUMBER := 'ABC';
    declare
    ERROR at line 1:
    ORA-06502: PL/SQL: numeric or value error: character to number conversion error
    ORA-06512: at line 3
    SQL> select * from sql_errors;
    TXT
    Search for 123 failed.
    SQL>
    As you can see from the sql_errors log table, no log was written so the WHEN others exception was the exception that raised the error to the calling code (SQL*Plus)
    4. Understanding Execution Blocks (part 2)
    Ok, so now we understand the very basics of an execution block and what happens when an exception happens.  Let's take it a step further...
    Execution blocks are not just a single simple block in most cases.  Often, during our statements section we have a need to call some reusable code and we do that by calling a procedure or function.  Effectively this nests the procedure or function's code as another execution block within the current statement section so, in terms of execution, we end up with something like...
    +---------------------------------+
    |    Declaration Section          |
    +---------------------------------+
    |    Statements  Section          |
    |            .                    |
    |  +---------------------------+  |
    |  |    Declaration Section    |  |
    |  +---------------------------+  |
    |  |    Statements  Section    |  |
    |  +---------------------------+  |
    |  |     Exception Section     |  |
    |  +---------------------------+  |
    |            .                    |
    +---------------------------------+
    |     Exception Section           |
    +---------------------------------+
    Example... (Note: log_trace just writes some text to a table for tracing)
    SQL> create or replace procedure a as
      2    v_dummy NUMBER := log_trace('Procedure A''s Declaration Section');
      3  begin
      4    v_dummy := log_trace('Procedure A''s Statement Section');
      5    v_dummy := 1/0; -- cause an exception
      6  exception
      7    when others then
      8      v_dummy := log_trace('Procedure A''s Exception Section');
      9      raise;
    10  end;
    11  /
    Procedure created.
    SQL> create or replace procedure b as
      2    v_dummy NUMBER := log_trace('Procedure B''s Declaration Section');
      3  begin
      4    v_dummy := log_trace('Procedure B''s Statement Section');
      5    a; -- HERE the execution passes to the declare/statement/exception sections of A
      6  exception
      7    when others then
      8      v_dummy := log_trace('Procedure B''s Exception Section');
      9      raise;
    10  end;
    11  /
    Procedure created.
    SQL> exec b;
    BEGIN b; END;
    ERROR at line 1:
    ORA-01476: divisor is equal to zero
    ORA-06512: at "SCOTT.B", line 9
    ORA-06512: at line 1
    SQL> select * from code_trace;
    TXT
    Procedure B's Declaration Section
    Procedure B's Statement Section
    Procedure A's Declaration Section
    Procedure A's Statement Section
    Procedure A's Exception Section
    Procedure B's Exception Section
    6 rows selected.
    SQL>
    Likewise, execution blocks can be nested deeper and deeper.
    5. How to continue exection of statements after an exception
    One of the common questions asked is how to return execution to the statement after the one that created the exception and continue on.
    Well, firstly, you can only do this for statements you expect to raise an exception, such as when you want to check if there is no data found in a query.
    If you consider what's been shown above you could put any statement you expect to cause an exception inside it's own procedure or function with it's own exception section to handle the exception without raising it back to the calling code.  However, the nature of procedures and functions is really to provide a means of re-using code, so if it's a statement you only use once it seems a little silly to go creating individual procedures for these.
    Instead, you nest execution blocks directly, to give the same result as shown in the diagram at the start of part 4 of this article.
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace procedure b (p_empno IN VARCHAR2) as
      2    v_dummy NUMBER := log_trace('Procedure B''s Declaration Section');
      3  begin
      4    v_dummy := log_trace('Procedure B''s Statement Section');
      5    -- Here we start another execution block nested in the first one...
      6    declare
      7      v_dummy NUMBER := log_trace('Nested Block Declaration Section');
      8    begin
      9      v_dummy := log_trace('Nested Block Statement Section');
    10      select empno
    11        into   v_dummy
    12        from   emp
    13       where  empno = p_empno; -- Note: the parameters and variables from
                                         parent execution block are available to use!
    14    exception
    15      when no_data_found then
    16        -- This is an exception we can handle so we don't raise it
    17        v_dummy := log_trace('No employee was found');
    18        v_dummy := log_trace('Nested Block Exception Section - Exception Handled');
    19      when others then
    20        -- Other exceptions we can't handle so we raise them
    21        v_dummy := log_trace('Nested Block Exception Section - Exception Raised');
    22        raise;
    23    end;
    24    -- ...Here endeth the nested execution block
    25    -- As the nested block handled it's exception we come back to here...
    26    v_dummy := log_trace('Procedure B''s Statement Section Continued');
    27  exception
    28    when others then
    29      -- We'll only get to here if an unhandled exception was raised
    30      -- either in the nested block or in procedure b's statement section
    31      v_dummy := log_trace('Procedure B''s Exception Section');
    32      raise;
    33* end;
    SQL> /
    Procedure created.
    SQL> exec b(123);
    PL/SQL procedure successfully completed.
    SQL> select * from code_trace;
    TXT
    Procedure B's Declaration Section
    Procedure B's Statement Section
    Nested Block Declaration Section
    Nested Block Statement Section
    No employee was found
    Nested Block Exception Section - Exception Handled
    Procedure B's Statement Section Continued
    7 rows selected.
    SQL> truncate table code_trace;
    Table truncated.
    SQL> exec b('ABC');
    BEGIN b('ABC'); END;
    ERROR at line 1:
    ORA-01722: invalid number
    ORA-06512: at "SCOTT.B", line 32
    ORA-06512: at line 1
    SQL> select * from code_trace;
    TXT
    Procedure B's Declaration Section
    Procedure B's Statement Section
    Nested Block Declaration Section
    Nested Block Statement Section
    Nested Block Exception Section - Exception Raised
    Procedure B's Exception Section
    6 rows selected.
    SQL>
    You can see from this that, very simply, the code that we expected may have an exception was able to either handle the exception and return to the outer execution block to continue execution, or if an unexpected exception occurred then it was able to be raised up to the outer exception section.
    6. User defined exceptions
    There are three sorts of 'User Defined' exceptions.  There are logical situations (e.g. business logic) where, for example, certain criteria are not met to complete a task, and there are existing Oracle errors that you wish to give a name to in order to capture them in the exception section.  The third is raising your own exception messages with our own exception numbers.  Let's look at the first one...
    Let's say I have tables which detail stock availablility and reorder levels...
    SQL> select * from reorder_level;
       ITEM_ID STOCK_LEVEL
             1          20
             2          20
             3          10
             4           2
             5           2
    SQL> select * from stock;
       ITEM_ID ITEM_DESC  STOCK_LEVEL
             1 Pencils             10
             2 Pens                 2
             3 Notepads            25
             4 Stapler              5
             5 Hole Punch           3
    SQL>
    Now, our Business has told the administrative clerk to check stock levels and re-order anything that is below the re-order level, but not to hold stock of more than 4 times the re-order level for any particular item.  As an IT department we've been asked to put together an application that will automatically produce the re-order documents upon the clerks request and, because our company is so tight-ar*ed about money, they don't want to waste any paper with incorrect printouts so we have to ensure the clerk can't order things they shouldn't.
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace procedure re_order(p_item_id NUMBER, p_quantity NUMBER) is
      2    cursor cur_stock_reorder is
      3      select s.stock_level
      4            ,r.stock_level as reorder_level
      5            ,(r.stock_level*4) as reorder_limit
      6      from stock s join reorder_level r on (s.item_id = r.item_id)
      7      where s.item_id = p_item_id;
      8    --
      9    v_stock cur_stock_reorder%ROWTYPE;
    10  begin
    11    OPEN cur_stock_reorder;
    12    FETCH cur_stock_reorder INTO v_stock;
    13    IF cur_stock_reorder%NOTFOUND THEN
    14      RAISE no_data_found;
    15    END IF;
    16    CLOSE cur_stock_reorder;
    17    --
    18    IF v_stock.stock_level >= v_stock.reorder_level THEN
    19      -- Stock is not low enough to warrant an order
    20      DBMS_OUTPUT.PUT_LINE('Stock has not reached re-order level yet!');
    21    ELSE
    22      IF v_stock.stock_level + p_quantity > v_stock.reorder_limit THEN
    23        -- Required amount is over-ordering
    24        DBMS_OUTPUT.PUT_LINE('Quantity specified is too much.  Max for this item: '
                                     ||to_char(v_stock.reorder_limit-v_stock.stock_level));
    25      ELSE
    26        DBMS_OUTPUT.PUT_LINE('Order OK.  Printing Order...');
    27        -- Here goes our code to print the order
    28      END IF;
    29    END IF;
    30    --
    31  exception
    32    WHEN no_data_found THEN
    33      CLOSE cur_stock_reorder;
    34      DBMS_OUTPUT.PUT_LINE('Invalid Item ID.');
    35* end;
    SQL> /
    Procedure created.
    SQL> exec re_order(10,100);
    Invalid Item ID.
    PL/SQL procedure successfully completed.
    SQL> exec re_order(3,40);
    Stock has not reached re-order level yet!
    PL/SQL procedure successfully completed.
    SQL> exec re_order(1,100);
    Quantity specified is too much.  Max for this item: 70
    PL/SQL procedure successfully completed.
    SQL> exec re_order(2,50);
    Order OK.  Printing Order...
    PL/SQL procedure successfully completed.
    SQL>
    Ok, so that code works, but it's a bit messy with all those nested IF statements. Is there a cleaner way perhaps?  Wouldn't it be nice if we could set up our own exceptions...
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace procedure re_order(p_item_id NUMBER, p_quantity NUMBER) is
      2    cursor cur_stock_reorder is
      3      select s.stock_level
      4            ,r.stock_level as reorder_level
      5            ,(r.stock_level*4) as reorder_limit
      6      from stock s join reorder_level r on (s.item_id = r.item_id)
      7      where s.item_id = p_item_id;
      8    --
      9    v_stock cur_stock_reorder%ROWTYPE;
    10    --
    11    -- Let's declare our own exceptions for business logic...
    12    exc_not_warranted EXCEPTION;
    13    exc_too_much      EXCEPTION;
    14  begin
    15    OPEN cur_stock_reorder;
    16    FETCH cur_stock_reorder INTO v_stock;
    17    IF cur_stock_reorder%NOTFOUND THEN
    18      RAISE no_data_found;
    19    END IF;
    20    CLOSE cur_stock_reorder;
    21    --
    22    IF v_stock.stock_level >= v_stock.reorder_level THEN
    23      -- Stock is not low enough to warrant an order
    24      RAISE exc_not_warranted;
    25    END IF;
    26    --
    27    IF v_stock.stock_level + p_quantity > v_stock.reorder_limit THEN
    28      -- Required amount is over-ordering
    29      RAISE exc_too_much;
    30    END IF;
    31    --
    32    DBMS_OUTPUT.PUT_LINE('Order OK.  Printing Order...');
    33    -- Here goes our code to print the order
    34    --
    35  exception
    36    WHEN no_data_found THEN
    37      CLOSE cur_stock_reorder;
    38      DBMS_OUTPUT.PUT_LINE('Invalid Item ID.');
    39    WHEN exc_not_warranted THEN
    40      DBMS_OUTPUT.PUT_LINE('Stock has not reached re-order level yet!');
    41    WHEN exc_too_much THEN
    42      DBMS_OUTPUT.PUT_LINE('Quantity specified is too much.  Max for this item: '
                                  ||to_char(v_stock.reorder_limit-v_stock.stock_level));
    43* end;
    SQL> /
    Procedure created.
    SQL> exec re_order(10,100);
    Invalid Item ID.
    PL/SQL procedure successfully completed.
    SQL> exec re_order(3,40);
    Stock has not reached re-order level yet!
    PL/SQL procedure successfully completed.
    SQL> exec re_order(1,100);
    Quantity specified is too much.  Max for this item: 70
    PL/SQL procedure successfully completed.
    SQL> exec re_order(2,50);
    Order OK.  Printing Order...
    PL/SQL procedure successfully completed.
    SQL>
    That's better.  And now we don't have to use all those nested IF statements and worry about it accidently getting to code that will print the order out as, once one of our user defined exceptions is raised, execution goes from the Statements section into the Exception section and all handling of errors is done in one place.
    Now for the second sort of user defined exception...
    A new requirement has come in from the Finance department who want to have details shown on the order that show a re-order 'indicator' based on the formula ((maximum allowed stock - current stock)/re-order quantity), so this needs calculating and passing to the report...
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace procedure re_order(p_item_id NUMBER, p_quantity NUMBER) is
      2    cursor cur_stock_reorder is
      3      select s.stock_level
      4            ,r.stock_level as reorder_level
      5            ,(r.stock_level*4) as reorder_limit
      6            ,(((r.stock_level*4)-s.stock_level)/p_quantity) as finance_factor
      7      from stock s join reorder_level r on (s.item_id = r.item_id)
      8      where s.item_id = p_item_id;
      9    --
    10    v_stock cur_stock_reorder%ROWTYPE;
    11    --
    12    -- Let's declare our own exceptions for business logic...
    13    exc_not_warranted EXCEPTION;
    14    exc_too_much      EXCEPTION;
    15  begin
    16    OPEN cur_stock_reorder;
    17    FETCH cur_stock_reorder INTO v_stock;
    18    IF cur_stock_reorder%NOTFOUND THEN
    19      RAISE no_data_found;
    20    END IF;
    21    CLOSE cur_stock_reorder;
    22    --
    23    IF v_stock.stock_level >= v_stock.reorder_level THEN
    24      -- Stock is not low enough to warrant an order
    25      RAISE exc_not_warranted;
    26    END IF;
    27    --
    28    IF v_stock.stock_level + p_quantity > v_stock.reorder_limit THEN
    29      -- Required amount is over-ordering
    30      RAISE exc_too_much;
    31    END IF;
    32    --
    33    DBMS_OUTPUT.PUT_LINE('Order OK.  Printing Order...');
    34    -- Here goes our code to print the order, passing the finance_factor
    35    --
    36  exception
    37    WHEN no_data_found THEN
    38      CLOSE cur_stock_reorder;
    39      DBMS_OUTPUT.PUT_LINE('Invalid Item ID.');
    40    WHEN exc_not_warranted THEN
    41      DBMS_OUTPUT.PUT_LINE('Stock has not reached re-order level yet!');
    42    WHEN exc_too_much THEN
    43      DBMS_OUTPUT.PUT_LINE('Quantity specified is too much.  Max for this item: '
                                  ||to_char(v_stock.reorder_limit-v_stock.stock_level));
    44* end;
    SQL> /
    Procedure created.
    SQL> exec re_order(2,40);
    Order OK.  Printing Order...
    PL/SQL procedure successfully completed.
    SQL> exec re_order(2,0);
    BEGIN re_order(2,0); END;
    ERROR at line 1:
    ORA-01476: divisor is equal to zero
    ORA-06512: at "SCOTT.RE_ORDER", line 17
    ORA-06512: at line 1
    SQL>
    Hmm, there's a problem if the person specifies a re-order quantity of zero.  It raises an unhandled exception.
    Well, we could put a condition/check into our code to make sure the parameter is not zero, but again we would be wrapping our code in an IF statement and not dealing with the exception in the exception handler.
    We could do as we did before and just include a simple IF statement to check the value and raise our own user defined exception but, in this instance the error is standard Oracle error (ORA-01476) so we should be able to capture it inside the exception handler anyway... however...
    EXCEPTION
      WHEN ORA-01476 THEN
    ... is not valid.  What we need is to give this Oracle error a name.
    This is done by declaring a user defined exception as we did before and then associating that name with the error number using the PRAGMA EXCEPTION_INIT statement in the declaration section.
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace procedure re_order(p_item_id NUMBER, p_quantity NUMBER) is
      2    cursor cur_stock_reorder is
      3      select s.stock_level
      4            ,r.stock_level as reorder_level
      5            ,(r.stock_level*4) as reorder_limit
      6            ,(((r.stock_level*4)-s.stock_level)/p_quantity) as finance_factor
      7      from stock s join reorder_level r on (s.item_id = r.item_id)
      8      where s.item_id = p_item_id;
      9    --
    10    v_stock cur_stock_reorder%ROWTYPE;
    11    --
    12    -- Let's declare our own exceptions for business logic...
    13    exc_not_warranted EXCEPTION;
    14    exc_too_much      EXCEPTION;
    15    --
    16    exc_zero_quantity EXCEPTION;
    17    PRAGMA EXCEPTION_INIT(exc_zero_quantity, -1476);
    18  begin
    19    OPEN cur_stock_reorder;
    20    FETCH cur_stock_reorder INTO v_stock;
    21    IF cur_stock_reorder%NOTFOUND THEN
    22      RAISE no_data_found;
    23    END IF;
    24    CLOSE cur_stock_reorder;
    25    --
    26    IF v_stock.stock_level >= v_stock.reorder_level THEN
    27      -- Stock is not low enough to warrant an order
    28      RAISE exc_not_warranted;
    29    END IF;
    30    --
    31    IF v_stock.stock_level + p_quantity > v_stock.reorder_limit THEN
    32      -- Required amount is over-ordering
    33      RAISE exc_too_much;
    34    END IF;
    35    --
    36    DBMS_OUTPUT.PUT_LINE('Order OK.  Printing Order...');
    37    -- Here goes our code to print the order, passing the finance_factor
    38    --
    39  exception
    40    WHEN exc_zero_quantity THEN
    41      DBMS_OUTPUT.PUT_LINE('Quantity of 0 (zero) is invalid.');
    42    WHEN no_data_found THEN
    43      CLOSE cur_stock_reorder;
    44      DBMS_OUTPUT.PUT_LINE('Invalid Item ID.');
    45    WHEN exc_not_warranted THEN
    46      DBMS_OUTPUT.PUT_LINE('Stock has not reached re-order level yet!');
    47    WHEN exc_too_much THEN
    48      DBMS_OUTPUT.PUT_LINE('Quantity specified is too much.  Max for this item: '
                                  ||to_char(v_stock.reorder_limit-v_stock.stock_level));
    49* end;
    SQL> /
    Procedure created.
    SQL> exec re_order(2,0);
    Quantity of 0 (zero) is invalid.
    PL/SQL procedure successfully completed.
    SQL>
    Lastly, let's look at raising our own exceptions with our own exception numbers...
    SQL> ed
    Wrote file afiedt.buf
      1  create or replace procedure re_order(p_item_id NUMBER, p_quantity NUMBER) is
      2    cursor cur_stock_reorder is
      3      select s.stock_level
      4            ,r.stock_level as reorder_level
      5            ,(r.stock_level*4) as reorder_limit
      6            ,(((r.stock_level*4)-s.stock_level)/p_quantity) as finance_factor
      7      from stock s join reorder_level r on (s.item_id = r.item_id)
      8      where s.item_id = p_item_id;
      9    --
    10    v_stock cur_stock_reorder%ROWTYPE;
    11    --
    12    exc_zero_quantity EXCEPTION;
    13    PRAGMA EXCEPTION_INIT(exc_zero_quantity, -1476);
    14  begin
    15    OPEN cur_stock_reorder;
    16    FETCH cur_stock_reorder INTO v_stock;
    17    IF cur_stock_reorder%NOTFOUND THEN
    18      RAISE no_data_found;
    19    END IF;
    20    CLOSE cur_stock_reorder;
    21    --
    22    IF v_stock.stock_level >= v_stock.reorder_level THEN
    23      -- Stock is not low enough to warrant an order
    24      [b]RAISE_APPLICATION_ERROR(-20000, 'Stock has not reached re-order level yet!');[/b]
    25    END IF;
    26    --
    27    IF v_stock.stock_level + p_quantity > v_stock.reorder_limit THEN
    28      -- Required amount is over-ordering
    29     

    its nice article, have put up this one the blog
    site,Nah, I don't have time to blog, but if one of the other Ace's/Experts wants to copy it to a blog with reference back to here (and all due credit given ;)) then that's fine by me.
    I'd go for a book like "Selected articles by OTN members" or something. Does anybody have a list of links of all those mentioned articles?Just these ones I've bookmarked...
    Introduction to regular expressions ... by CD
    When your query takes too long ... by Rob van Wijk
    How to pipeline a function with a dynamic number of columns? by ascheffer
    PL/SQL 101 : Exception Handling by BluShadow

  • Use of WITH clause

    Hi,
    I am using Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 .
    I am working in a procedure where I want to manipulate the data produced by a WITH AS clause.  But it is giving "PL/SQL: ORA-00942: table or view does not exist" error. A small example to illustrate my problem is given below. Here in the example am just trying to get a replaced string by using the out put of a WITH AS clause.
    SET SERVEROUTPUT ON;
    DECLARE
    CNT INTEGER;
    LETTER CHAR(1);
    REPLACED_STRING VARCHAR2(10);
    BEGIN
    REPLACED_STRING := 'ABC';
    WITH T AS
      (SELECT 'ABC' VAL FROM DUAL),
      TMP (LEN, SUBVAL) AS
      (SELECT LENGTH(VAL) LEN,
        SUBSTR(VAL, 1, INSTR(VAL, 'B', 1, 1)) SUBVAL
       FROM T
       UNION ALL
       SELECT LENGTH(VAL)-1 LEN,
       SUBSTR(VAL, 2, INSTR(VAL, 'C', 1, 1)) SUBVAL
       FROM T
      SELECT COUNT(*) INTO CNT FROM TMP,T ;
      FOR I IN 1..CNT LOOP
      SELECT SUBSTR(SUBVAL,1,1) INTO LETTER FROM  TMP,T;
      SELECT REPLACE(REPLACED_STRING,LETTER,'X')INTO REPLACED_STRING FROM DUAL;
      DBMS_OUTPUT.PUT_LINE(REPLACED_STRING);
    END LOOP;
    END;
    I thought of declaring a cursor which will hold the data produced by WITH clause but it did not work. Can you please let me know what are the possible options to do this.
    Thanks

    I think, I can not use the WITH inside loop as, I want to manipulate on data resulted by WITH reading row by row from it. I have a complex procedure and I wont be able to explain that scenario here and thus i came up with a similar problem through a very simple example. I will try to explain my problem thru my example here.
    The WITH in my example give an out put as :
    SUBVAL
    AB
    BC
      WITH T AS
      (SELECT 'ABC' VAL FROM DUAL),
      TMP (LEN, SUBVAL) AS
      (SELECT LENGTH(VAL) LEN,
        SUBSTR(VAL, 1, INSTR(VAL, 'B', 1, 1)) SUBVAL
       FROM T
       UNION ALL
       SELECT LENGTH(VAL)-1 LEN,
       SUBSTR(VAL, 2, INSTR(VAL, 'C', 1, 1)) SUBVAL
       FROM T
      SELECT subval FROM TMP,T;
    and then by using this in the PLSQL block mentioned above
      FOR I IN 1..CNT LOOP
      SELECT SUBSTR(SUBVAL,1,1) INTO LETTER FROM  TMP,T;
      SELECT REPLACE(REPLACED_STRING,LETTER,'X')INTO REPLACED_STRING FROM DUAL;
      DBMS_OUTPUT.PUT_LINE(REPLACED_STRING);
      END LOOP;
    I want to have an output like:
    XBC
    XXC
    Please note that nature of my original problem is that I want to manipulate the data given by WITH clause in the same procedure by passing it to other functions/procs to get the desired result. So please advice me following this approach only which would be helpful.
    Thanks

  • What's the easiest way to move app data and data structures to a server?

    Hi guys,
    I've been developing my app locally with Apex 4.2 and Oracle 11g XE on Windows 7. It's getting close to the time to move the app to an Oracle Apex server. I imagine Export/Import is the way to move the app. But what about the app tables and data (those tables/data like "customer" and "account" created specifically for the app)? I've been using a data modeling tool, so I can run a DDL script to create the data structures on the server. What is the easiest way to move the app data to the server? Is there a way to move both structures and data in one process?
    Thanks,
    Kim

    There's probably another way to get here, but, in SQL Developer, on the tree navigation, expand the objects down to your table, right click, then click EXPORT.. there you will see all the options. This is a tedious process and it sucks IMO, but yeah, it works. It sucks mostly because 1) it's one table at a time, 2) if your data model is robust and has constraints, and sequences and triggers, then you'll have to disable them all for the insert, and hope that you can re-enable constraints, etc without a glitch (good luck, unless you have only a handful of tables)
    I prefer using the oracle command line EXP to export an entire schema, then on the target server I use IMP to import the schema. That way, it's near exact. This makes life messy if you develop more than one application in a single schema, and I've felt that pain -- however -- it's a whole lot easier to drop tables and other objects than it is to create them! (thus, even if the process of EXP/IMP moved more than you wanted to "move".. just blow away what you don't want on the target after the fact..)
    You could use oracle's datapump method too.
    Alternatively, what can be done, IF you have access to both servers from your SQL developer instance (or if you can tnsping them both already from the command line, you can use SQL*PLUS), is run a script that will identify your apex apps' objects (usually by prefix to object names, like EBA_PROJ_%, etc) and do all the manual work for you. I've created a script that does exactly this so that I can move data from dev to prod servers over a dblink. It's tricky because of the order that must be executed to disable constraints and then re-enable them, and of course, trickier if you don't consistently prefix ALL of your "application objects"... (tables, views, triggers, sequences, functions, procs, indexes, etc)

  • Users and Tablespaces

    Specs:
    OS: Win 2003 Sp1
    Oracle 9i - rel2 (9.2.0.5.0)
    I had something like 200 users and dedicated tablespaces associated to them. Eventually, I ran into a usual very natural and obvious problem of -running low on disk space. So I took a task to free some space off by deleting some tablespaces - not realising that there will be users who will have these tablespaces assigned to them as their default tablespace.
    Now, having deleted these tablespaces - I need to clear these users off - so whats the best way to do it?
    What will happen to these users?

    Eric,
    The objects owned by those users were dropped with the tablespaces.Not all objects, but all segments. If users are owners of procedures/functions..., these ones still exists.
    Paul,
    cascade is probably redundant,That depend, for the same reason (if functions/proc exists) :
    SQL> create user testuser identified by testuser;
    User created.
    SQL> grant create session, create procedure to testuser;
    Grant succeeded.
    SQL> conn testuser/testuser;
    Connected.
    SQL> create or replace procedure test_proc is begin null; end;
    SQL> /
    Procedure created.
    SQL> conn / as sysdba
    Connected.
    SQL> select default_tablespace from dba_users where username='TESTUSER';
    DEFAULT_TABLESPACE
    USERS
    SQL> select segment_name from dba_segments where tablespace_name='USERS' and owner='TESTUSER';
    no rows selected
    SQL> drop user testuser;
    drop user testuser
    ERROR at line 1:
    ORA-01922: CASCADE must be specified to drop 'TESTUSER'
    SQL> drop user testuser cascade;
    User dropped.
    SQL> @OP,
    You probably need to take care with a script which drop users, in case of some users are users without being schema (not owner of any objects), and for users which aren't the owner of any segments, and which you want to keep.
    Nicolas.
    Message was edited by:
    N. Gasparotto

  • "Before Form Trigger Failed" in Oracle Reports

    Hi,
    I have RDFs stored in the Oracle Reports Server (installed in Solaris Server1). These RDFs access a common package (in compiled status) which resides in Oracle DB (installed in another Solaris Server2).
    Everytime whenever there is a change in this common package I compile this and I verify the status to be in VALID status. After this I execute my RDF through a shell script and my report fails with the above error message.
    WITHOUT RECOMPILING, when I RE-EXECUTE the report, it works fine.
    Can anyone please help me to resolve this issue as it happens everytime in Production when I promote this package to Production DB, compile and execute a report.
    The execution of ANY report fails (immediately after compilation) and is NOT consistent with one particular report. What I mean is, any RDF executed after the compilation fails and succeeds when it is re-executed without any changes.
    All the file access paths are availables for reading, writing and executing the file.
    Thanks in advance!
    Regards,
    Teenu

    After you re-compile your packages,
    Open up the affected .RDF's in Report Builder
    Choose 'Save As' from File toolbar
    Overwrite the existing file in the $reports directory on the server.
    For some reason Reports gets "out of sync" so to speak with packages and even local PL/SQL triggers/functions/procs... This is why sometimes even after you compile your local functions and triggers you still get the "Report contains uncompiled PL/SQL" error. Try the suggestion and let me know if it resolves your issue.
    HTH,
    Steve

  • Pre-mapping problem

    Hello ,
    I would like to delete some records before inserting new records to the target table. So I use the Pre-mapping process for this situation. I wrote a simple "Delete record" procedure in the "Public transformation/Customs/Procedures. But when I deploy the mapping , there is an error.
    PLS-00201: identifier 'DELETE_RECORD' must be declared
    My delete_record procedure is as follow
    --initialize variables here
    -- main body
    BEGIN
    NULL; -- allow compilation
    delete from ora_tb5 where c1=1
    EXCEPTION
    WHEN OTHERS THEN
    NULL; -- enter any exception code here
    END;
    Is there any problems in the above procedure code ? How to declare the procedure in OWB ? How can I deploy the mapping successfully ? Thanks !
    Dan

    Hi,
    Sorry I did not realize that you were trying the Custom functions.
    Deploying Custom Functions it is bit trivial. There are 2 ways to deploy them.
    1. Using GUI - Copy and Paste the Function into the module where you have your mapping and then deply it into that location.
    2. Using OMB+ -
    OMBCONNECT < to design repo>
    OMBCC '<your project>'
    OMBCONN RUNTIME '<ur RT connection>' USE PASSWORD '<rt password>'
    OMBCC '<ur project>/WB_CUSTOM_TRANS'
    --list available functions / procs
    OMBLIST FUNCTIONS
    OMBLIST PROCEDURES
    --create deployment action plan
    OMBCREATE TRANSIENT DEPLOYMENT_ACTION_PLAN 'DEP_PLAN'\
    ADD ACTION 'DEP_FUNC' SET PROPERTIES (OPERATION) \
    VALUES ('CREATE') SET REFERENCE FUNCTION '<your func/proc name>'
    --Change back to the module where your mapping exists
    OMBCC '/<ur project>/<your module>'
    OMBDEPLOY DEPLOYMENT_ACTION_PLAN 'DEP_PAN'
    OMBCOMMIT
    The above steps will deploy the function. Reconcile the pre-mapping. Deploy mapping. This should work.
    Yes. I think you are right regarding the usage of DELETEs.
    hope the above resolves your issues.
    Thanks
    mahesh

  • Error in Simple Stored Precedure!!

    Hi Folks,
    I am new to oracle...At present i'm working in MS SQL Server...I am trying to write a small stored procedure which retrieves a result set(ie rows) from a given table in Oracle 8i.I have written a procedure as
    create procedure test is
    begin
    select * from stu;
    end
    and I executed the above procedure.It was showing Procedure created with compilation errors.What would be the problem?.Same procedure is executing with out any errors in SQL Server.
    Can anyone pls give me a solution for this?.
    Thanks in advance,
    Murali

    Murali,
    I answered a question just like this a little while ago. I programmed TSQL for about 5 years and yes it would be nice if PL/SQL could return a data stream, but it doesn't. However as I explain below I use a method I like even better, since I would rather have an object (a view) that I can get this data from anyway. Do remeber a function can return a data stream though so you might want to consider that as well. Anyway this is what I had said ...
    --[START NOTE]
    I've run into this problem allot with Oracle. If I was to point out the biggest difference between PL/SQL and TSQL it is this ability your wanting, to have a data stream come back from a oracle function/proc/package. In TSQL you can make a proc that simply says, SELECT * from T1, and when you execute this, you get a data stream back. Oracle does not do this, but there is a flip side. There is a different approach I've realized to this and I would NOT use this data return stream ability even if it was supported. This is what I usually do when I want data from a package ...
    Use a VIEW.
    Call a procedure that creates a database VIEW of the SELECT query you want. (you will have to remember the name of the view) , Then simply do SELECT * FROM <view name you made>. Doing it in this fashion allows so many more abilities than just getting a data set back. Your data set is now an object which you can query over again and even other sessions have access to it. See the basic example below ...
    SQL> create or replace PROCEDURE sp_sql (ps_in_sql in varchar2)
    2 as
    3 ls_sql varchar2(2000) := upper(trim(ps_in_sql));
    4 BEGIN
    5 execute immediate ls_sql;
    6 end sp_sql;
    7 /
    Procedure created.
    SQL> show errors
    No errors.
    SQL>
    SQL> execute sp_sql('create or replace view v1 (N1) as select distinct t1.n1 from t1 order by t1.n1'
    PL/SQL procedure successfully completed.
    SQL> select * from v1;
    N1
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    10 rows selected.
    This is just the basic principle to get a data stream back from running a single execute command, with one additional SELECT * from VIEW. The main way I use this ability is just passing the WHERE clause and recompile the view inside the procedure, since I may want a date range, an IN clause, other criteria, but in the end I just do 1 EXECUTE and SELECT * from VIEW.
    This method is better that just trying to get a proc to return a data stream. Make the proc create an object that you can bind to with active objects (like grids, drop down boxes, etc.), and after you now have the view to even do more complex SQL on, since you CANT query your data stream to get only the 'JOHN DOE' entries back.
    Anyway I hope this helps a little, try it and you'll find this works very well.
    Tyler.
    --[END NOTE]

  • Display column values as zeros

    I am having three select queries with union below:
    select col1, col2 from table1 where condition; -> fetches 1 record
    union
    select col1, col2 from table2 where condition; -> fetches no row
    union
    select col1, col2 from table3 where condition; -> fetches no row
    so output is 1 row. example;
    col1 col2
    1 1
    The 2nd and 3rd select doesnt fetch any record. My req is to dislplay the col values as zeros for any of 3 select statements which doesnt fetch any records from table
    so req output which looks like:
    col1 col2
    1 1
    0 0 -> norecords fetched(displaying zeros)
    0 0 -> norecords fetched(displaying zeros)
    Please let me know how can i do this in the query? I need to do this in the same qury and not using any functions/proc..
    Edited by: user11942774 on Aug 22, 2010 4:13 AM

    MichaelS wrote:
    Or
    SQL> var deptno1 number
    SQL> var deptno2 number
    SQL> begin
    :deptno1 := 20;
    :deptno2 := 100;
    end;
    PL/SQL procedure successfully completed.
    SQL> select nvl (deptno, 0) deptno
    from (select :deptno1 dn from dual), dept
    where deptno(+) = dn
    union all
    select nvl (deptno, 0) deptno
    from (select :deptno2 dn from dual), dept
    where deptno(+) = dn
    DEPTNO
    20
    0
    2 rows selected.Note: Above worked on my old 9.8.0.2 but strange enough not on my 11.2.0.1 (Only the first part of the UNION ALL displayed)! A bug???Looks to be.
    set serveroutput off
    ALTER SESSION SET STATISTICS_LEVEL = ALL;
    select nvl (deptno, 0) deptno
      from (select :deptno1 dn from dual), scott.dept
    where deptno(+) = dn
    union all
    select nvl (deptno, 0) deptno
      from (select :deptno2 dn from dual), scott.dept
    where deptno(+) = dn
      8  /
                DEPTNO
                    20
    1 row selected.
    Elapsed: 00:00:00.01
    TUBBY_TUBBZ?SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL, NULL, 'ALL'));
    PLAN_TABLE_OUTPUT
    SQL_ID  ap0cr5cut2ucn, child number 0
    select nvl (deptno, 0) deptno   from (select :deptno1 dn from dual),
    scott.dept  where deptno(+) = dn union all select nvl (deptno, 0)
    deptno   from (select :deptno2 dn from dual), scott.dept  where
    deptno(+) = dn
    Plan hash value: 18139613
    | Id  | Operation            | Name               | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT     |                    |       |       |     2 (100)|          |
    |   1 |  NESTED LOOPS OUTER  |                    |     2 |    26 |     2   (0)| 00:00:01 |
    |   2 |   FAST DUAL          |                    |     1 |       |     2   (0)| 00:00:01 |
    |   3 |   VIEW               | VW_JF_SET$03B38961 |     2 |    26 |     0   (0)|          |
    |   4 |    UNION-ALL         |                    |       |       |            |          |
    |*  5 |     INDEX UNIQUE SCAN| PK_DEPT            |     1 |     3 |     0   (0)|          |
    |*  6 |     INDEX UNIQUE SCAN| PK_DEPT            |     1 |     3 |     0   (0)|          |
    Query Block Name / Object Alias (identified by operation id):
       1 - SEL$51CD7FBE
       2 - SEL$51CD7FBE / DUAL@SEL$2
       3 - SET$03B38961 / VW_JF_SET$03B38961@SEL$7D8CA889
       4 - SET$03B38961
       5 - SEL$09480F13 / DEPT@SEL$1
       6 - SEL$05ED6B18 / DEPT@SEL$3
    Predicate Information (identified by operation id):
       5 - access("DEPTNO"=:DEPTNO1)
       6 - access("DEPTNO"=:DEPTNO2)
    Column Projection Information (identified by operation id):
       1 - "ITEM_1"[NUMBER,22]
       3 - "ITEM_1"[NUMBER,22]
       4 - STRDEF[22]
       5 - "DEPTNO"[NUMBER,22]
       6 - "DEPTNO"[NUMBER,22]
    46 rows selected.
    Elapsed: 00:00:00.05So we can see through rows 5 and 6 the predicates were pushed into DEPT query (which shouldn't have happened).
    A simple change to the query alleviates the bug.
    select
       nvl(d1.deptno, 0) as deptno
    from
       select :deptno1 dn from dual
          union all
       select :deptno2 dn from dual
    )  d,
       scott.dept d1
    where
    11     d.dn = d1.deptno (+)
    12  /
                DEPTNO
                    20
                     0
    2 rows selected.
    Elapsed: 00:00:00.01
    TUBBY_TUBBZ?SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(NULL, NULL, 'ALL'));
    PLAN_TABLE_OUTPUT
    SQL_ID  4x59nkxusp1p8, child number 0
    select    nvl(d1.deptno, 0) as deptno from (    select :deptno1 dn from
    dual       union all    select :deptno2 dn from dual )  d,
    scott.dept d1 where    d.dn = d1.deptno (+)
    Plan hash value: 1564933512
    | Id  | Operation          | Name    | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |         |       |       |     4 (100)|          |
    |   1 |  NESTED LOOPS OUTER|         |     2 |    32 |     4   (0)| 00:00:01 |
    |   2 |   VIEW             |         |     2 |    26 |     4   (0)| 00:00:01 |
    |   3 |    UNION-ALL       |         |       |       |            |          |
    |   4 |     FAST DUAL      |         |     1 |       |     2   (0)| 00:00:01 |
    |   5 |     FAST DUAL      |         |     1 |       |     2   (0)| 00:00:01 |
    |*  6 |   INDEX UNIQUE SCAN| PK_DEPT |     1 |     3 |     0   (0)|          |
    Query Block Name / Object Alias (identified by operation id):
       1 - SEL$1
       2 - SET$1 / D@SEL$1
       3 - SET$1
       4 - SEL$2 / DUAL@SEL$2
       5 - SEL$3 / DUAL@SEL$3
       6 - SEL$1 / D1@SEL$1
    Predicate Information (identified by operation id):
       6 - access("D"."DN"="D1"."DEPTNO")
    Column Projection Information (identified by operation id):
       1 - "D1"."DEPTNO"[NUMBER,22]
       2 - "D"."DN"[NUMBER,22]
       3 - STRDEF[22]
       6 - "D1"."DEPTNO"[NUMBER,22]
    43 rows selected.
    Elapsed: 00:00:00.05
    TUBBY_TUBBZ?I ran these tests on
    TUBBY_TUBBZ?select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE     11.2.0.1.0     Production
    TNS for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    5 rows selected.
    Elapsed: 00:00:00.02
    TUBBY_TUBBZ?

  • OSB, XSLT, Assign and Replace

    Hi
    We are using OSB and using Assign and Replace over our codes....
    Noticed 2 things:
    Using ASSIGN, created a non-referential variable.... (ie When I am working with a XML (ie $body), if I grab certain parts of it's element, the new variable is a copy of the element and its not a reference therefore any change in the variable does not reflect on $body)... Is this TRUE? Will using an XQUERY function/proc give me a referential context?
    Using a REPLACE/INSERT, the XPATH setting cannot accept a variable ie //targetlist/targetitem[{$idx}]/targetdata.... IS this TRUE? How can variables be used within XPATH?
    Regards,
    Dax

    >
    Noticed 2 things:
    Using ASSIGN, created a non-referential variable.... (ie When I am working with a XML (ie $body), if I grab certain parts of it's element, the new variable is a copy of the element and its not a reference therefore any change in the variable does not reflect on $body)... Is this TRUE?
    >
    This is correct. New variable is a copy of the element and its not a reference.
    >
    Will using an XQUERY function/proc give me a referential context?
    >
    Xquery will return a new thing. So, it will not give you a referential context.
    >
    Using a REPLACE/INSERT, the XPATH setting cannot accept a variable ie //targetlist/targetitem[{$idx}]/targetdata.... IS this TRUE? How can variables be used within XPATH?
    >
    Never tried this. Will have to check.
    By the way what exactly is the problem statement. What you want to do?

  • HTTP ACCESS enabled but not to all

    Hi guys,
    Security question regarding HTTP access without managing it via firewall / VPN.
    I would like to have the access only for one ip (of my workstation) + the server itself.
    Can i modify some flows function / proc to achieve this?
    Maybe Dietmar can help me.....
    thanx a lot

    I must admit that I'm reluctant to change ISP but this action on Verizon’s part is leaving a bitter taste in my mouth. It might be somewhat of an inconvenience for me because I've had my Verizon account for such a long time but maybe another ISP might satisfy my needs and for much less.

Maybe you are looking for

  • Family sharing using iTunes cards

    both my wife and I use iTunes cards for the purchase of apps and music in the App Store. We now want to enable family sharing on our devies and are being forced to provide credit card or bank details in our accounts to use it. apple need to allow the

  • HT1338 How can I get my photo to work again? the app will not open on my desk top any more. I can not dave my photo on my desk top

    How can I get my photo to work again? the app will not open on my desk top any more. I can not dave my photo on my desk top

  • Collecting Message based on Delivery Id

    Hi, We have an scenario to collect the messages based on delviery number, like customer sends the bulk order and SAP splits that order and create the delivery for each splitted orders . Eg. Sales Order     Batch Order PO#      1234 This Batch order i

  • ITunes Gives me a BSOD

    My iTunes randomly will give me a Blue Screen of Death or it will tell me is has encountered a problem and has to quit. I have reinstaled both the latest iTunes and quicktime and nothing has worked so far. Granted it is not every time i open iTunes j

  • Mail data from listbox

    Hello, dear developer, kindly please i need your support it this issue as i have exported data to listbox, is that any way to mail these data via outlook mail, you have to take a look to the whole workbook, you can call the listbox from sheet that ca