PLS-00455: cursor 'CUR_1' cannot be used in dynamic SQL OPEN statement

create or replace function f_my_test_func
return refcur_pkg.refcur_t1
is
cur_1  refcur_pkg.refcur_t1;
begin
open cur_1
for
'select * from dept';
return cur_1;
exception
when others
then
insert into ddl_log (SQLTEXT)
values
('fucntion error'); 
end;

I would suggest that cur_1 refcur_pkg.refcur_t1 is a stongly typed ref cursor i.e. it has RETURN dept%ROWTYPE or something similar in the declaration. You can't use strongly typed ref cursors with dynamic SQL in this way. The declaration should be weakly typed or just use sys_refcursor.
DTYLER_APP@pssdev2> DECLARE
  2
  3      TYPE t_Strong   IS REF CURSOR RETURN dual%ROWTYPE;
  4
  5      lc_Strong       t_Strong;
  6
  7  BEGIN
  8
  9      OPEN lc_Strong FOR
10      'SELECT * FROM dual';
11
12  END;
13  /
    OPEN lc_Strong FOR
ERROR at line 9:
ORA-06550: line 9, column 10:
PLS-00455: cursor 'LC_STRONG' cannot be used in dynamic SQL OPEN statement
ORA-06550: line 9, column 5:
PL/SQL: Statement ignored
DTYLER_APP@pssdev2>
DTYLER_APP@pssdev2> DECLARE
  2
  3      TYPE t_Weak   IS REF CURSOR;
  4
  5      lc_Weak       t_Weak;
  6
  7  BEGIN
  8
  9      OPEN lc_Weak FOR
10      'SELECT * FROM dual';
11
12  END;
13  /
PL/SQL procedure successfully completed.
DTYLER_APP@pssdev2> DECLARE
  2
  3      lc_Weak       sys_refcursor;
  4
  5  BEGIN
  6
  7      OPEN lc_Weak FOR
  8      'SELECT * FROM dual';
  9
10  END;
11  /
PL/SQL procedure successfully completed.
DTYLER_APP@pssdev2>HTH
David

Similar Messages

  • Re: PLS-00455: cursor 'CUR_1' cannot be used in dynamic SQL OPEN statement

    create or replace package cognos_pk as /* Creates Package Header*/
    TYPE project_type IS record( /* A record declaration is used to */
    c1 NUMBER /* provide a definition of a record */
    ); /* that can be used by other variables*/
    TYPE project_type1 IS REF CURSOR  return project_type; /* Variable declaration */
    procedure conosg_sp (result1  out project_type1); /* SP declaration */
    end;
    CREATE OR REPLACE PACKAGE BODY cognos_pk AS /* Name of package body must be same as header */
    PROCEDURE conosg_sp(result1  OUT project_type1) IS
    countrow  number;
    BEGIN
    FOR X IN (SELECT TABLE_NAME
    FROM USER_TAB_COLUMNS
    WHERE COLUMN_NAME='PROC_STAT_CODE' AND TABLE_NAME LIKE 'INPT%')
    LOOP
    execute immediate 'select count(*)   from '||X.TABLE_NAME ||' WHERE PROC_STAT_CODE <>10 ' into countrow;
    --result1 := X.TABLE_NAME|| ROW_CNT;
    -- dbms_output.put_line(result1 );
    OPEN result1 for countrow;
    END loop;
    END;
    end;
    /This is my requirement ...
    I want to count the table starting with Inpt and and proc stat _code =10 which is the column name in all the table.
    i wan to return the count and the table name to be used in my cognos report.
    Edited by: BluShadow on 10-May-2013 09:22
    added {noformat}{noformat} tags around the code/data for readability (no accounting for OP's lack of formatting)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    1005181 wrote:
    create or replace package cognos_pk as /* Creates Package Header*/
    TYPE project_type IS record( /* A record declaration is used to */
    c1 NUMBER /* provide a definition of a record */
    ); /* that can be used by other variables*/
    TYPE project_type1 IS REF CURSOR  return project_type; /* Variable declaration */
    procedure conosg_sp (result1  out project_type1); /* SP declaration */
    end;
    CREATE OR REPLACE PACKAGE BODY cognos_pk AS /* Name of package body must be same as header */
    PROCEDURE conosg_sp(result1  OUT project_type1) IS
    countrow  number;
    BEGIN
    FOR X IN (SELECT TABLE_NAME
    FROM USER_TAB_COLUMNS
    WHERE COLUMN_NAME='PROC_STAT_CODE' AND TABLE_NAME LIKE 'INPT%')
    LOOP
    execute immediate 'select count(*)   from '||X.TABLE_NAME ||' WHERE PROC_STAT_CODE <>10 ' into countrow;
    --result1 := X.TABLE_NAME|| ROW_CNT;
    -- dbms_output.put_line(result1 );
    OPEN result1 for countrow;
    END loop;
    END;
    end;
    /This is my requirement ...
    I want to count the table starting with Inpt and and proc stat _code =10 which is the column name in all the table.
    i wan to return the count and the table name to be used in my cognos report.The execute immediate statement you have, is doing the actual count and returning the count into the variable "countrow".
    The subsequent OPEN statement for the ref cursor is trying to open a cursor, and is expecting an SQL query to do that, but you are passing it your numeric value instead.
    All you need to open a ref cursor is:
    e.g.
    OPEN result1 for 'select count(*) from '||x.table_name||' where proc_stat_code != 10';However, your code is so seriously flawed in many ways.
    a) you don't need to declare a type of "REF CURSOR" yourself. Oracle provides a type called "SYS_REFCURSOR" that you can use already.
    b) Your procedure is supplying a single ref cursor as an OUT variable, yet it tries to loop through multiple tables and re-use the same ref cursor over and over. That's not going to work. You can only pass one thing out in your OUT parameter.
    I don't know how congos expects it's results, but I assume a ref cursor is acceptable to it, so what you're actually looking for is to pass back a single ref cursor that is based on a query that can give the results for all your tables in one go.
    There are various queries that can be used to count records on multiple tables e.g.
    (ref. Laurent Schneider's blog: http://laurentschneider.com/wordpress/2007/04/how-do-i-store-the-counts-of-all-tables.html )
    SQL> select
      2    table_name,
      3    to_number(
      4      extractvalue(
      5        xmltype(
      6 dbms_xmlgen.getxml('select count(*) c from '||table_name))
      7        ,'/ROWSET/ROW/C')) count
      8  from user_tables
      9 where iot_type != 'IOT_OVERFLOW'
    10 or    iot_type is null;
    TABLE_NAME                      COUNT
    DEPT                                4
    EMP                                14
    BONUS                               0
    SALGRADE                            5You could therefore open your refcursor using a single query based on the above (adapting it for your own needs and restrictions).

  • Workaround for opening a strongly typed cursor using native dynamic SQL

    Hi All,
    In reading the PL/SQL documentation for Oracle 9i, I noted that the OPEN-FOR
    statement with a dynamic SQL string only allows the use of weakly typed cursors.
    I have verified this limitation with my own experimentation as follows:
    DECLARE
    type rec_type is record(
    str     varchar2(40),
    num     number(22)
    type cur_type is ref cursor return rec_type;
    my_cur     cur_type;
    que     varchar2(100);
    tab     varchar2(40);
    BEGIN
    tab := 'dynamic_table_name';
    que := 'select key_name, key_value from ' || tab || ' where key_name like ''01%''';
    open my_cur for que;
    loop
    if my_cur%found then
    dbms_output.put_line('source_name: ' || my_cur.str || ', page_sn: ' || my_cur.num);
    exit;
    end if;
    end loop;
    close my_cur;
    END;
    Running the above trivial example in an anonymous sql block yields the following
    errors as expected:
    ORA-06550: line 10, column 8:
    PLS-00455: cursor 'MY_CUR' cannot be used in dynamic SQL OPEN statement
    ORA-06550: line 10, column 3:
    PL/SQL: Statement ignored
    ORA-06550: line 13, column 54:
    PLS-00487: Invalid reference to variable 'MY_CUR'
    ORA-06550: line 13, column 7:
    PL/SQL: Statement ignored
    Is there a workaround to the situation? Since I do not know the table name at run
    time, I must use Native Dynamic SQL. I have a long and complex record type
    that I wish to return through JDBC using the REFCURSOR Oracle type in order to
    avoid having to register an inordinate number of OUT parameters. Moreover, I
    would like to return potentially one or more results in a ResultSet. Using the
    standard method of registering native SQL types for the IN and OUT bindings
    can only return one result. Hence the reason I would like to return a strong
    cursor type. Also, the type of query I am doing is complex, and needs to be
    executed in a PL/SQL procedure for performance reasons. Therefore simply
    executing a SELECT query dynamically built up on the the JDBC client won't
    do the trick.
    If anybody has experience with a similar problem and would like to volunteer
    information on their workaround, I would really appreciate it.
    Best Regards,
    J. Metcalf

    We can use strongly-typed REF CURSORs in DNS, but the typing derives from a table e.g.
    TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
    so the problem is your use of "return rec_type" bit.
    Forgive my bluntness but I think you have misunderstood strong and weak typing. You actually want to be using weakly-typed cursors. I mean this:
    Moreover, I would like to return potentially one or more results in a ResultSet. suggests that the structure of your resultset may vary, which is precisely what a weakly-typed ref cursor allows us to do. Then we can use the JDBC metadata methods to interrogate the structure of the resultset, innit.
    so try this:
    DECLARE
    type cur_type is ref cursor;
    my_cur cur_type;
    que varchar2(100);
    tab varchar2(40);
    BEGIN
    tab := 'dynamic_table_name';
    que := 'select key_name, key_value from ' || tab || ' where key_name like ''01%''';
    open my_cur for que;
    loop
    if my_cur%found then
    dbms_output.put_line('source_name: ' || my_cur.str || ', page_sn: ' || my_cur.num);
    exit;
    end if;
    end loop;
    close my_cur;
    END;
    ras malai, APC
    Cheers, APC

  • PLS-00363: expression 'I' cannot be used as an assignment target

    Hello all
    I have a Package and I have one procedure in it .
    I have use dmlset inside this .
    Inside that procedure I have a cursor and inside the FOR loop I have mentioned something .
    FOR i IN 1 .. No_of_rec LOOP
    If....
    End if ;
    i := i+1 ;
    END LOOP;
    I have mentioned before end loop i := i+1 ; when i execute this package it is showing this error .
    "PLS-00363: expression 'I' cannot be used as an assignment target"
    What could be the problem?

    Of course,
    My example is showing that index I in loop is same thing as parameter IN in procedure1. Its value, not reference. I is passed as VALUE to LOOP just like PARAM1 is passed as value to PROCEDURE1. Trying to assignment something to I or PARAM1 will generate same error.
    Also another interesting example is
    CREATE OR REPLACE
    PROCEDURE procedure1(
        param1 IN OUT NUMBER)
    AS
    BEGIN
      param1 := 0;
    END procedure1;
    BEGIN
      FOR i IN 1..3
      LOOP
        procedure1(i);
      END LOOP;
    END;
    In this case procedure1 is correct but loop stmt is not. It will generate same error.
    After doing this examples i also concluded that procedure cant return value it can modify existing value of variable which is declared (uninitialized or initialized, OUT or IN OUT ) in upper PLSQL block (named or unnamed PLSQL block)

  • Error PLS 00363  expression "string" cannot be used as an assignment target in sentence SELF.ATTRIBUTE1:=PARAMETER;

    Hi everybody. I wrote de following  type
    create or replace TYPE ALMACEN AS OBJECT
      id_almacen number(10),
      descripcion varchar2(40),
      existencias number(6),
      precio number(4),
      member function movimiento (p_num number)  return boolean
    create or replace TYPE BODY ALMACEN AS
      member function movimiento (p_num number)  return boolean AS
      v_inf boolean;
      n number(6);
      BEGIN
        if self.existencias+p_num>=0 then
        self.existencias:=existencias+p_num;
        return TRUE;
        else return FALSE;
        end if;
      END movimiento;
    END;
    I have Oracle 11g release I.
    In previous releases it worked, but now SQLDeveloper marks
    self.existencias:=existencias+p_num;
    Error PLS 00363  expression "string" cannot be used as an assignment target in sentence
    Please, What's wrong?
    Thanking in advance

    Hi,
    Not quite a PL/SQL XML question but anyway...
    Since the member function modifies the object instance, the implicit argument "self" must be declared explicitly as "IN OUT" :
    member function movimiento (self in out nocopy almacen, p_num number)  return boolean

  • Using Native Dynamic SQL in Forms

    Can Native Dynamic SQL be used in Forms 5.0 or Forms 6.0? (Database 8.1.6.0.0)
    I have tried the following code (examples below) from the PL/SQL User's Guide and Reference Release 8.1.6 and the Metalinks Note: 62592.1 and the trigger/procedure (in Forms) will not compile. I appreciate any help given.
    Example1:
    (I have a table named temp_jane with a column named companies and a value 'Hello'. When compiling, I receive the error: 'Error 103 at line 8, column 11 Encountered the symbol ''IMMEDIATE" when expecting one of the following :=.(@%; ')
    declare
    str varchar2( 200 );
    val varchar2( 20 );
    ret temp_jane%rowtype;
    begin
    str := 'select company from temp_jane where company = :b1';
    val := 'Hello';
    execute immediate str into ret using val;
    message('Value fetched from table: '| |ret.company);
    end;
    Example2:
    (Here is the real issue, I don't know what the select statement, so I need to be able to assign a variable. When compiling, I receive the error: 'Error 103 at line 28, column 21 Encountered the symbol "VSQLSTATEMENT" when expecting one of the following: select ').
    declare
    type ItemsControlCurTyp is ref cursor;
    ItemsCur ItemsControlCurTyp;
    ItemsRec Items%rowtype;
    vSQLStatement varchar2( 5000 );
    vExecuteSQL varchar2( 5000 );
    vNumRows integer;
    vValue varchar2( 2000 );
    vFirstOne varchar2( 1 ) := 'Y';
    vRetval varchar2( 2000 );
    begin
    -- Display the column prompts with the right text.
    set_item_property( 'ITEMS_AVAILABLE.NDB_VALUE', PROMPT_TEXT, :ITEMS_CONTROL.AVAILABLE_LABEL );
    set_item_property( 'ITEMS_CHOSEN.NDB_VALUE', PROMPT_TEXT, :ITEMS_CONTROL.CHOSEN_LABEL );
    -- Save the original version of CHOSEN_STRING in case the user reverts or cancels.
    :ITEMS_CONTROL.CHOSEN_STRING_ORIG := :ITEMS_CONTROL.CHOSEN_STRING;
    vSQLStatement := :ITEMS_CONTROL.SELECT_STATEMENT;
    vExecuteSQL := vSQLStatement;
    -- Open the cursor
    open ItemsCur for vSQLStatement;

    Hi JTaylor
    You cannot use NDS in Client side (Developer). You have to use DBMS_SQL only.
    Regards
    A K Srinivasan
    Oracle.

  • How to use a dynamic SQL data as the header ?

    I'm using BO XI Rel 2. I have hard coded the report headers, but i do have a table wherein the header data is available. I like to fetch the HEADER information from the table, rather than hard coding. How to go about it?
    Example: "Statement of Closing" is the header.
    The above output can be retrieved by using the below query!
    Select Form_desc from TBS_FORMS where form_id = 'tbs1a';
    form_id is a common link between tables!! Since the actual report data has multiple value as output, just by plugging the query in the header, i'm getting #multivalue error!!!!
    In oracle reports, i have something called place holder to achieve the above objective. In BO, how to go about it?
    Edited by: Karthik  Ganesan on Dec 28, 2008 1:22 PM

    Sorry, that doesn't solve my problem. Please read the question more closely - I want my USERS to be able to do this without changing their configurations. My users are public school elementary teachers and parents. I can't ask them to toggle any settings - I'm looking for a way that my users can do this on their own.
    Thanks

  • Create table using a dynamic SQL returns error.

    DBMS_UTILITY.exec_ddl_statement (
    'create table test_table as select column_names from table_name@dblink
    where condition' )
    i am using the above statement in a pl/sql procedure.
    It throws an error saying
    "Exact fetch returns more than requested no. of rows"
    can any one help me on this please!!!
    Very Urgent
    Thanks in Advance.
    Bala.

    Works for me. But the more important question would be the need to have this run within PL/SQL? Why do you want to do that? what is the requirement? can you not do this one time at SQL*Plus prompt and be done with it?
    SQL> drop table emp ;
    Table dropped.
    SQL>
    SQL>
    SQL> exec dbms_utility.exec_ddl_statement('create table emp as select * from [email protected] where deptno = 10') ;
    PL/SQL procedure successfully completed.
    SQL> select count(*) from emp ;
      COUNT(*)
             3
    1 row selected.
    SQL> select count(*) from [email protected] ;
      COUNT(*)
            14
    1 row selected.
    SQL> select count(*) from [email protected] where deptno = 10 ;
      COUNT(*)
             3
    1 row selected.
    SQL>Message was edited by:
    Kamal Kishore

  • Open cursor for dynamic sql

    Hi
    I am using oracle 8.1.7 on solaris.
    I have created
    SQL> CREATE OR REPLACE PACKAGE TEST_PKG AS
    2 TYPE row_cursor IS REF CURSOR RETURN TEMP_TAB%ROWTYPE;
    3 PROCEDURE Return_Columns_proc (c_return IN OUT row_cursor);
    4 END TEST_PKG;
    5 /
    Package created.
    now i am trying to create the procedure Return_Columns_proc by
    CREATE OR REPLACE PACKAGE BODY TEST_PKG AS
    PROCEDURE Return_Columns_proc (c_return IN OUT row_cursor) AS
    QUERY_STR VARCHAR2(850);
    x number ;
    BEGIN
    x:=1;
    QUERY_STR :='SELECT * FROM temp_tab where order_line_id = '||x;
    OPEN c_return FOR QUERY_STR;
    END Return_Columns_proc;
    END TEST_PKG;
    I am getting following error.
    SQL> show error
    Errors for PACKAGE BODY TEST_PKG:
    LINE/COL ERROR
    8/4 PL/SQL: Statement ignored
    8/9 PLS-00455: cursor 'C_RETURN' cannot be used in dynamic SQL OPEN
    statement
    any help for this error.

    The error says it all. You have defined a strong ref cursor and it cannot be used with dynamic sql. However, that does not mean you cannot use the query directly in the OPEN clause
    OPEN c_Return FOR SELECT * FROM temp_tab where order_line_id = X ;

  • How can I open a cursor for dynamic sql statement

    Hi,
    I'm facing issues opening a cursor for dynamic sql statement : PLS-00455: cursor 'RESULT1' cannot be used in dynamic SQL OPEN statement.
    CREATE OR REPLACE FUNCTION DEMO
    (MN_I in VARCHAR)
    return AB_OWNER.ABC_Type.NonCurTyp is
    RESULT1 AB_OWNER.ABC_Type.NonCurTyp;
    sql_stmt VARCHAR2(4000);
    BEGIN
    sql_stmt := 'SELECT * FROM AB_OWNER.DUN WHERE JZ_I in ('||mn_i||') ORDER BY app.ACC_I';
    OPEN RESULT1 FOR sql_stmt;
    END IF;
    return RESULT1;
    END DEMO;
    What changes should I make in the code so that it doesn't fail? I can't change the definition of RESULT1 cursor though.

    Gangadhar Reddy wrote:
    I used SYS REFCURSOR and was able to implement successfully.How many times did you run this successful implementation that does not use bind variables?
    Because this is what will happen when it runs a lot.
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17766/e2100.htm#sthref1874
    http://forums.oracle.com/forums/search.jspa?q=%2BORA-04031%20%2Bbind&objID=c84&dateRange=all&rankBy=10001&start=30
    And you will have to regularly restart the server, or possibly slightly less invasive, flush the shared pool.
    Flushing Shared Pool regularly
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1516005546092
    >
    Ok, this is an easy one to diagnose.
    You are not using bind variables. This is terrible. Flushing the shared pool is a bad
    solution -- you are literally killing the performance on your box by not using them.
    If I was to write a book on how to build “non scalable applications in Oracle”, this
    would be the first and last chapter. This is a major cause of performance issues and a
    major inhibitor of scalability in Oracle. The way the Oracle shared pool (a very
    important shared memory data structure) operates is predicated on developers using bind
    variables. If you want to make Oracle run slowly, even grind to a total halt – just
    refuse to use them.
    >
    But, please feel free to go ahead with this successful implementation.
    I just hope anyone else who reads this doesn't make the same mistake.

  • PLS-00363: expression cannot be used as an assignment target

    Hi,
    Oralce9.2
    when I run the insert procedure I get the below error:
    Procedure
    PROCEDURE proc_one_insert(col1 IN OUT numeric,
    col2           IN num,
    col3     IN numeric
    BEGIN
    execute immediate proc_one_insert(2,1,111);
    END;
    Error
    PLS-00363: expression '2' cannot be used as an assignment target
    How to solve the above error ?
    With Regards
    Edited by: user640001 on Dec 2, 2010 3:04 AM

    Arun has shown you an example using PL/SQL. If you want to do something similar in other languages you have to use their style of variable declaration e.g. if you wanted to do it through SQL*Plus, you need to declare the variable within SQL*Plus itself and bind that into your calls e.g.
    SQL> create procedure p_inout (p_val in out number) is
      2  begin
      3    p_val := p_val*10;
      4  end;
      5  /
    Procedure created.
    SQL> var mynum number
    SQL> exec :mynum := 10;
    PL/SQL procedure successfully completed.
    SQL> print mynum
         MYNUM
            10
    SQL> exec p_inout(:mynum);
    PL/SQL procedure successfully completed.
    SQL> print mynum
         MYNUM
           100
    SQL>

  • PLS-00363: expression '' cannot be used as an assignment target - HELP :-(

    Hi Guys,
    This is a procedure I have in the body of a package:
    PROCEDURE SUM_EVENTS (p_trial_no IN NUMBER,
                                  p_country_resion IN VARCHAR2,
                                  p_loc_no IN NUMBER,
                                  p_setup_flag IN VARCHAR2,
                                  p_event_changed IN OUT NUMBER) ISWhen I call this in SQLplus with this:
    exec DB_CALC.sum_events(340,'USA',1,'Y',3700);I get this:
    ERROR at line 1:
    ORA-06550: line 1, column 54:
    PLS-00363: expression '3700' cannot be used as an assignment target
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignoredAny ideas what I'm doing wrong?
    Thanks!

    p_event_changed is declared as an IN OUT parameter. You need to provide a variable in which the OUT values can be written to..
    something like
    declare
    out_val number := 3700;
    begin
    DB_CALC.sum_events(340,'USA',1,'Y',out_val);
    end;

  • Types of functions cannot used in PL/SQL

    I'm trying to find out information on what types of functions cannot be used in PL/SQL. Can someone provide me with some directions and assistance?
    Thanks a lot.
    Tony

    its really depends upon your implementation way..
    if u are callinga pl/sql from a trigger, then you can't use any DDL or DML effecting on the same table.
    If u are calling a function then it must return only one value, it should not written more than one value.

  • Cannot surfing using safari after upgrade to OS X Lion

    Hi,
    i just upgrade to OS X Lion, the problem now i cannot surfing using safari, i try open up chrome and firefox they can work well
    FYI, i already empty cookies adn not using any plug-ing
    i also already update the software.
    there any options can i do?
    thank you

    So you can't login to a site? "click enter" ??
    Which website are you referring to?
    Please post the link in your reply  

  • Cursor query retrieves records in anon pl/sql block but no data in store pr

    Hello,
    Can any one please help me,
    I am using the below query, to get the table name and constraint name
    select table_name,constraint_name
    from all_constraints
    where constraint_type in ('R','P')
    and status = 'ENABLED'
    and owner='IRIS_DATA'
    order by constraint_type desc;
    The below query retrieves data in anonymous pl/sql block and retrieve no data when i use the same cursor with the same query in procedure inside the package.
    CREATE USER CLONEDEV
    IDENTIFIED BY CLONE123
    DEFAULT TABLESPACE IRIS
    TEMPORARY TABLESPACE TEMP;
    GRANT DBA TO CLONEDEV;
    the user from which i am executing this query is granted dba role.
    My oracle version is 10.2.0.4
    Please update if you any other information.
    Please advice.
    Thanks

    >
    Roles cannot be used by pl/sql.
    >
    NOT TRUE!
    That is an oft quoted myth. There are many posts in the forum that mis-state this.
    Roles can be, and are used by PL/SQL. In fact, OP stated and demonstrated that in their question: their anonymous block worked.
    The Oracle docs provide a very clear explanation - the core restriction is for NAMED PL/SQL blocks that use DEFINER's rights (the default):
    >
    Roles Used in Named Blocks with Definer's Rights
    All roles are disabled in any named PL/SQL block (stored procedure, function, or trigger) that executes with definer's rights. Roles are not used for privilege checking and you cannot set roles within a definer's rights procedure.
    >
    The Database Security Guide has the information in the section 'How Roles Work in PL/SQL Blocks (which, of course, wouldln't be needed if they didn't work. ;) )
    http://docs.oracle.com/cd/B28359_01/network.111/b28531/authorization.htm#i1007304
    >
    The use of roles in a PL/SQL block depends on whether it is an anonymous block or a named block (stored procedure, function, or trigger), and whether it executes with definer's rights or invoker's rights.
    Roles Used in Named Blocks with Definer's Rights
    All roles are disabled in any named PL/SQL block (stored procedure, function, or trigger) that executes with definer's rights. Roles are not used for privilege checking and you cannot set roles within a definer's rights procedure.
    The SESSION_ROLES view shows all roles that are currently enabled. If a named PL/SQL block that executes with definer's rights queries SESSION_ROLES, then the query does not return any rows.
    See Also:
    Oracle Database Reference
    Roles Used in Named Blocks with Invoker's Rights and Anonymous PL/SQL Blocks
    Named PL/SQL blocks that execute with invoker's rights and anonymous PL/SQL blocks are executed based on privileges granted through enabled roles. Current roles are used for privilege checking within an invoker's rights PL/SQL block. You can use dynamic SQL to set a role in the session.

Maybe you are looking for

  • Is office home and business 2013 compatible with windows 8.1?

    I have read several issues with installing Microsoft home and business 2013 and the system running right on windows 8.1 has the issue been resolved or is there another version of Microsoft home and business I should download?

  • Can I access my icloud from an android phone?

    I have a few questions as I am about to receive my first ipod Touch.  Please forgive my ignorance.  I've had a few 5G nanos but that's pretty much just itunes stuff; I'm not really apple-experienced and even on my (non-Apple) touch phone, I'm not ver

  • Photos imported but not written to disk

    Strange Problem - normally I import from my CF card, copy as DNG as write out to an external USB drive. Lightroom normally creates a folder on the USB drive and the DNG files are there. For some reason the photos are in the catalog, BUT..... not foun

  • When is the next update?

    I really need to know.

  • System preferences slideshow and iPhoto

    The system preferences screensaver and desktop keep recycling the same 20 photos out of my foler, I have over 2,500 photos in the folder and they keep using the same 15-20 photos. What's going on? This is a g5 10.4.8 and a g4 (version ?) Thanks