Create publicsynonyms for anonymous pl/sql block

Hi,
How do I create a public synonym for an anonymous PL/SQL block?
BEGIN
     IF a IS NOT NULL
     THEN
          OPEN b;
          LOOP
               FETCH b INTO Func;
          EXIT WHEN b%NOTFOUND;
               c := c || Func || ',';
          END LOOP;
          CLOSE b;
          c := SUBSTR(c, 1, LENGTH(TRIM(c))-1);
     END IF;
     return c;
END abc;
ERROR at line 2:
ORA-06550: line 2, column 5:
PLS-00201: identifier 'a' must be declared
ORA-06550: line 2, column 2:
PL/SQL: Statement ignored
ORA-06550: line 19, column 2:
PLS-00372: In a procedure, RETURN statement cannot contain an expression
ORA-06550: line 19, column 2:
PL/SQL: Statement ignored

Hi,
CrackerJack wrote:
Hi,
How do I create a public synonym for an anonymous PL/SQL block?A synonym is an alternate name.
Anonymous bblocks, by definition, don't have names, so they can't have alternate names. Also, they're not stored, so what good would it do if you could have synonyms for them?
An anonymous block is just a quick and dirty alternative to a procedure, anyway. Why not make a procedure, or a function?
BEGIN
     IF a IS NOT NULL
     THEN
          OPEN b;
          LOOP
               FETCH b INTO Func;
          EXIT WHEN b%NOTFOUND;
               c := c || Func || ',';
          END LOOP;
          CLOSE b;
          c := SUBSTR(c, 1, LENGTH(TRIM(c))-1);
     END IF;
     return c;
END abc;
ERROR at line 2:
ORA-06550: line 2, column 5:
PLS-00201: identifier 'a' must be declared
ORA-06550: line 2, column 2:
PL/SQL: Statement ignored
ORA-06550: line 19, column 2:
PLS-00372: In a procedure, RETURN statement cannot contain an expression
ORA-06550: line 19, column 2:
PL/SQL: Statement ignoredThis code looks like part of a function, that was named abc. Where is the beginning part of that function? The errors are caused because it is missing the part where this was declared as a function, and the part where the local variables a, c and func, and the cursor b, were defined.
Does thsi function have something to do with the original question: "How do I create a public synonym for an anonymous PL/SQL block?"?
What are you trying to do?

Similar Messages

  • Pass values to Guid collection/array parameter for anonymous pl/sql block

    The following code pops the System.ArgumentException: Invalid parameter binding
    Parameter name: p_userguids
    at Oracle.DataAccess.Client.OracleParameter.GetBindingSize_Raw(Int32 idx)
    at Oracle.DataAccess.Client.OracleParameter.PreBind_Raw()
    at Oracle.DataAccess.Client.OracleParameter.PreBind(OracleConnection conn, IntPtr errCtx, Int32 arraySize)
    at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery()
    Any help or advice ?
    anonymous pl/sql block text:
    DECLARE
    TYPE t_guidtable IS TABLE OF RAW(16);
    p_userguids t_guidtable;
    BEGIN
    DELETE testTable where groupname=:groupname;
    INSERT INTO testTable (userguid, groupname)
    SELECT column_value, :groupname FROM TABLE(p_userguids);
    END;
    c# code:
    public static void SetGroupUsers(string group, List<Guid> users)
    OracleConnection conn = Database.ConnectionEssentus;
    try
    conn.Open();
    OracleCommand sqlCmd = new OracleCommand();
    sqlCmd.CommandText = sqls["SetGroupUsers"]; // above anonymous block
    sqlCmd.Connection = conn;
    sqlCmd.BindByName = true;
    OracleParameter p_guidCollection = sqlCmd.Parameters.Add("p_userguids", OracleDbType.Raw);
    p_guidCollection.Size = users.Count;
    p_guidCollection.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
    p_guidCollection.UdtTypeName = "t_guidtable";
    p_guidCollection.Value = users.ToArray();
    sqlCmd.Parameters.Add("groupname", OracleDbType.Varchar2, 30).Value = group;
    sqlCmd.ExecuteNonQuery();
    catch(Exception ex)
    System.Diagnostics.Debug.WriteLine(ex.ToString());
    finally
    conn.Close();
    }

    New question,
    How can I select records using "in" condition clause likes the following sentence?
    SELECT userguid, firstname, lastname FROM UserTable WHERE userguid in (SELECT column_value FROM TABLE(p_userguids))
    I tried using PIPE ROW like this, but ORACLE said "PLS-00629: PIPE statement cannot be used in non-pipelined functions"
    FOR i in p_userguids.first .. p_userguids.last
    LOOP
    SELECT userguid, firstname, lastname INTO l_userrecord FROM UserTable WHERE userguid=p_userguids(i);
    PIPE ROW(l_userrecord);
    END LOOP;

  • Anonymous PL SQL block runs in 2 minutes but runs for 4 hours in Applicatio

    We are facing an issue with a custom code. When we run the custom code as anonymous pl/sql block , it completes in 2 minutes.
    But when we run the same from Oracle Application as a concurrent program, it runs for more than 4 hours.
    There is absolute no change in the code.
    Anyone faced this issue?

    Does your code use context sensitive views such as po_headers?
    Maybe you have not set the context in the pl/sql block so the view returns 0 records.
    But when you run it in Apps, the context is automatically set and so it processes a large number of records.
    Set the context if you have not and then try again.
    begin
    dbms_application_info.set_client_info('&org_id'); --
    end;
    Sandeep Gandhi

  • Running a anonymous PL/SQL block

    Hi,
    I have created an anonymous PL/SQL block and saved it in a file. And I am now trying to run it from the sql prompt using @.
    But this doesn't seem to be working. I get a wierd number as output and then it hangs.
    This is not the case if I copy paste the anonymous block. In this case I get the correct output.
    Please assist as to whether it is possible to run it using @ as it is important for me to do so..

    Hi,
    You forgot the slash after the anonymous block:
    USER is "YJAM"
    TEST>-- Create anonymous Block
    TEST>BEGIN
      2    NULL;
      3  END;
    4 /
    PL/SQL procedure successfully completed.
    TEST>-- save as script
    TEST>save ab.sql
    Created file ab.sql
    TEST>get ab
      1  BEGIN
      2    NULL;
      3* END;
    TEST>@ab
    PL/SQL procedure successfully completed.
    TEST>ed ab Here, I delete line 4. hence the Block won't run.
    TEST>@ab
      4
      5
      6
      7
      8  . a dot to exit input mode. a slash would run the block
    TEST>Regards,
    Yoann.

  • Alter database statement in anonymous pl/sql block

    Is it possible to include an alter database statement in an anonymous pl/sql block?
    When I execute this code to query user_tables for all table names, disable their constraints and drop the table, I got the following error:
    ***MY CODE
    -- DECLARE VARIABLE(S)
    DECLARE
         v_TABLE_NAME TABLE_NAME.USER_TABLE%TYPE;
    -- DECLARE AND DEFINE CURSOR
    CURSOR c_GETTABLES is
         SELECT TABLE_NAME from USER_TABLES;
    BEGIN
    OPEN c_GETTABLES;
    LOOP
    FETCH c_GETTABLES into v_TABLE_NAME;
    EXIT when c_GETTABLES%notfound;     
    ALTER TABLE v_TABLE_NAME DISABLE PRIMARY KEY CASCADE;
    DROP TABLE v_TABLE_NAME;
    END LOOP;
    CLOSE c_GETTABLES;
    END;
    ***RESPONSE FROM SERVER
    ALTER TABLE v_TABLE_NAME DISABLE PRIMARY KEY CASCADE;
    ERROR at line 15:
    ORA-06550: line 15, column 1:
    PLS-00103: Encountered the symbol "ALTER" when expecting one of the following:
    begin case declare exit for goto if loop mod null pragma
    raise return select update while with <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> <<
    close current delete fetch lock insert open rollback
    savepoint set sql execute commit forall merge
    <a single-quoted SQL string> pipe
    Thanks

    When you want to perform ddl statements in a (anonymous) PL/SQL block, you have to use dynamic SQL because ddl is not possible in pl/sql.
    Dynamic sql means that you sort of execute ddl statements in a sql manner. To use dynamic sql, two options exist:
    - dbms_sql package : for oracle before 8i. To use this package is not always easy. Read about it carefully first before using.
    - Native Dynamic SQL : implemented in 8i and very easy to use. An example would be :
    declare
    lv_statement varchar2(32676);
    begin
    lv_statement := 'ALTER TABLE MY_TABLE DISABLE CONSTRAINT MY_TABLE_CK1';
    execute immediate lv_statement;
    lv_statement := 'ALTER TABLE MY_TABLE ENABLE CONSTRAINT MY_TABLE_CK1';
    execute immediate lv_statement;
    end;
    Good luck.
    Edwin van Hattem

  • ODP 10.2.0.100 + anonymous PL/SQL block

    hi,
    my ODP dont wants anonymous PL/SQL blocks...
    my code:
    OracleConnection conn = new OracleConnection(sConnectionString);
    string text =
    "declare
    d int;
    begin
    SELECT nr INTO d FROM TMPTEXTS;
    end;
    OracleCommand cmd = new OracleCommand(text, conn);
    cmd.CommandType = CommandType.Text;
    conn.Open();
    cmd.ExecuteNonQuery();
    conn.Close();
    // error message
    Oracle.DataAccess.Client.OracleException ORA-06550: Zeile 1, Spalte 1:
    PLS-00103: encountered the symbol "" expecting
    begin case declare exit for function ...
    any ideas ?
    lg dan

    The sample code at
    http://www.oracle.com/technology/oramag/oracle/06-jan/o16odpnet.html
    demonstrates using an anon block with a bind.

  • How to re-execute anonymous PL/SQL block in package definition ?

    Hi all,
    I implemented a package which contains procedures and an anonymous PL/SQL block.
    This anonymous PL/SQL block is executed only once when the package is called.
    and charge in-memory the content of table to avoid multiple SQL access each
    time one procedure is called.
    As my application open many sessions to the Oracle database, I would like to try
    a solution to signal all sessions to reload the content of table when the content
    of table is modified. The solution to stop and to restart the connection is not
    acceptable.
    Best regards
    Sylvain

    > .. to avoid multiple SQL access each time one procedure is called.
    As I understand your posting, this is the actual technical requirement. You want to force serialisation of PL/SQL code. Correct? (only one session at a time can run the procedure)
    This feature typically used to accomplish this in o/s code is called a semaphore. PL/SQL does not specifically support semaphores. However, it supports a range of IPC (Inter Process Communication) methods - from message queues to pipes.
    One of these IPC interfaces is DBMS_LOCK - which allows a unique lock to be defined and processes to manage their resource usage/execution/etc via this lock using the DBMS_LOCK API.
    I've found this a pretty clean and manageable solution to enforce serialisation. Of course, it is even better not to enforce serialisation. Rather design the code to be thread safe and capable of multi-processing/parallel processing.
    Personally, I would not use a table as an IPC mechanism as Oracle already provides better IPC mechanisms for PL/SQL code. As for "signalling sessions to re-load the table" - not possible as Oracle sessions cannot register callbacks to handle events. Oracle sessions are not event driven processes from a PL/SQL (application development) perspective.

  • Execute anonymous PL/SQL block via JDBC - OUT parameter not available

    I have a simple proc on the database:
    CREATE PROCEDURE TEST(X OUT BINARY_INTEGER, Y IN VARCHAR) AS
    BEGIN
      X := 33;
    END; I am trying to invoke it via JDBC using an anonymous PL/SQL block:
            try {
                Connection connection =
                  DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL",
                    "scott", "tiger");
                CallableStatement stproc_stmt = connection.prepareCall(
                    "DECLARE\n" +
                    " X_TARGET BINARY_INTEGER;\n" +
                    " Y_TARGET VARCHAR(20) := :2;\n" +
                    "BEGIN\n" +
                    " TEST(X=>X_TARGET, Y=>Y_TARGET);\n" +
                    " :1 := X_TARGET;\n" +
                    "END;"
                stproc_stmt.registerOutParameter(1, Types.NUMERIC);
                stproc_stmt.setString(2, "test");
                stproc_stmt.executeUpdate();
                Object o = stproc_stmt.getObject(1);
            catch (Exception e) {
                e.printStackTrace();
            } No exceptions are thrown, but the Object o does not get the value '33' - it is NULL.
    Any ideas?
    thanks in advance,
    Mike Norman

    I think the issue may be in how JDBC parameter binding is being managed throughout the block's lifecycle.
    The slightly-different TEST2 works:
    CREATE PROCEDURE TEST2(Y IN VARCHAR, X OUT BINARY_INTEGER) AS
    BEGIN
      X := 33;
    END;
    try {
        Connection connection =
          DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL",
         "scott", "tiger");
        CallableStatement stproc_stmt = connection.prepareCall(
         "DECLARE\n" +
         " Y_TARGET VARCHAR(20) := :1;\n" +
         " X_TARGET BINARY_INTEGER;\n" +
         "BEGIN\n" +
         " TEST2(Y=>Y_TARGET, X=>X_TARGET);\n" +
         " :2 := X_TARGET;\n" +
         "END;"
        stproc_stmt.setString(1, "test");
        stproc_stmt.registerOutParameter(2, Types.NUMERIC);
        stproc_stmt.executeUpdate();
        Object o = stproc_stmt.getObject(1);
    catch (Exception e) {
        e.printStackTrace();
    }The order of the bind indices ':1' and ':2' are reversed in the above anonymous block - we are returning via ':2'.
    I am wondering if 'under the covers' there isn't perhaps a cursor issue. When the original block is parsed and the first bind index is found to be position 2, somehow we can't go back to position 1 - a forwards-only cursor?

  • JDBC: send batch of SQL commands as anonymous PL/SQL block

    Hi All,
    I did a little measurement to see if I can improve jdbc
    applications by batching dissimilar SQL commands into one
    anonymous PL/SQL block and execute it once. To my surprise, for
    a batch of 5 SQL commands, it take 60% more time than execute
    each of the 5 SQL commands separately.
    The same JDBC code, using similar SQL text batching, running
    against Sybase or MSSQL shows 60%-300% improvement.
    Is there any other way to batch dynamic dissimilar SQL commands
    in Oracle other than using anonymous PL/SQL block? Here is an
    example of how the "text-batching" PL/SQL block looks like:
    "begin insert into testtab1(col1, col2) values(1, 'row1');
    insert into testtab2(col1, col2) values(100, 1);....; end;"
    Thanks,
    Nam Nguyen
    null

    If you do:
    declare
    l_sql varchar2(32767);
    l_value varchar2(32767);
    begin
    select query_sql into l_sql from lov where lov_id = 100;
    dbms_output.put_line(l_sql);
    end;
    You'll see something like that:
    SELECT
    l.DESCRIPTION || decode(l2.DESCRIPTION,null,'',l2.description, '-' || l2.description) || decode(a.DT,'Y',' - Distributed Training','N',null,null) as value1
    FROM ACTIVITY a
    ,MOUNTAINEERING m
    ,LOV l
    ,LOV l2
    WHERE a.JSATFA_ID = 82
    AND a.SPECIFIC_ACTIVITY_LOV_ID = l.LOV_ID
    AND m.ACTIVITY_ID(+) = a.ACTIVITY_ID
    AND m.CLASSIFICATION_LOV_ID = l2.LOV_ID(+);
    you need to duplicate the '
    you can do many things like:
    CTH@> select * from sqls;
    C
    select first_name || ' ' || last_name as value1 from employees where rownum=1
    1 fila seleccionada.
    CTH@>
    CTH@> ;
    1 declare
    2 l_sql varchar2(32767);
    3 l_value varchar2(32767);
    4 type generic_cursor is ref cursor;
    5
    6 c generic_cursor;
    7
    8 begin
    9 select replace(c, ''', ''''') into l_sql from sqls;
    10
    11 execute immediate l_sql into l_value;
    12 dbms_output.put_line(l_value);
    13* end;
    CTH@> /
    Ellen Abel
    Procedimiento PL/SQL terminado correctamente.
    CTH@>

  • Anonymous PL/SQL block within a select statement

    I read somewhere that it was possible to build an anonymous pl/sql block within a sql statement. Something along the lines of:
    select
    begin
    i = 0;
    return i;
    end;
    from dual;
    However, for the life of me, I can't find documentation on this. Could someone please point me to the right place, assuming I'm not just imagining it.
    Thanks.

    Did you mean, executing a pl/sql block generated from an sql.
    declare
    cmd varchar2(100);
    begin
    select 'declare i pls_integer := 0; begin i:=1; end;' into cmd from dual;
    execute immediate cmd;
    end;
    [pre]                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Debugging Anonymous PL/SQL Block

    Does sql developer allow you to debug an anonymous PL/SQL block or is the debugging restricted to compiled procedures/functions? Am a TOAD user but am looking at SQL Developer. Thanks

    As you can only set breakpoints inside a code editor, you'll have to wrap your code in a stored procedure.
    You could request this at the SQL Developer Exchange, but I guess it'll be too much work to add vs. the relative ease of using a stored proc.
    Regards,
    K.

  • Creating temporary table in pl/sql block problem

    hello
    i have a problem in creating and using temporary table in pl/sql block
    please verify below block
    begin
    execute immediate 'create global temporary table alitemp1 (co_t varchar2(10),color varchar2(10))';
    insert into alitemp1 (co_t,color) values ('001','red');
    execute immediate 'DROP TABLE alitemp1';
    end;
    when i execute that block i will receive this error
    insert into alitemp1 (co_t,color) values ('001','red');
    ERROR at line 3:
    ORA-06550: line 3, column 14:
    PL/SQL: ORA-00942: table or view does not exist
    ORA-06550: line 3, column 2:
    PL/SQL: SQL Statement ignored
    i think it because that alitemp1 table don't create
    but two below block run fine
    begin
    execute immediate 'create global temporary table alitemp1 (co_t varchar2(10),color varchar2(10))';
    execute immediate 'DROP TABLE alitemp1';
    end;
    begin
    execute immediate 'create global temporary table alitemp1 (co_t varchar2(10),color varchar2(10))';
    end;
    select table_name from user_tables where table_name='ALITEMP1';
    TABLE_NAME
    ALITEMP1
    it means that problem is when the below line exists in block
    insert into alitemp1 (co_t,color) values ('001','red');
    if may please guide me

    In addition to the comments by Justin and 3360, you cannot do what you want the way you are doing it.
    All objects referred to in a PL/SQL block must exist at the time the block is compiled. In your case, since it is an anonomous block, that is run time. Since you are dynamically creating the temporary table you need to refer to it dynamically as well. More like:
    BEGIN
    EXECUTE IMMEDIATE 'create global temporary table alitemp1 (co_t varchar2(10),
                                                               color varchar2(10))';
    EXECUTE IMMEDIATE 'insert into alitemp1 (co_t,color) values (:b1,:b2)' USING '001', 'red';
    EXECUTE IMMEDIATE 'DROP TABLE alitemp1';
    END;However, don't do that it is a really bad idea. Just create the temporary table, if you really need it, once and use it in your processing.
    In most cases, things that SQL Server needs temporary tables for can be done easily in Oracle with a single SQL statement,
    John

  • How to report an error from anonymous PL/SQL blocks

    Hello,
    The following SQL*Plus script
    WHENEVER OSERROR EXIT FAILURE
    WHENEVER SQLERROR EXIT FAILURE
    DECLARE
    EXIST_INDEXES BOOLEAN := FALSE;
    BEGIN
    FOR INDEX IN (SELECT * FROM INDEXES)
    LOOP
    EXIST_INDEXES := TRUE;
    DBMS_OUTPUT.PUT_LINE(INDEX.SCHEMA || '.' || INDEX.NAME);
    END LOOP;
    IF EXIST_INDEXES THEN
    RAISE_APPLICATION_ERROR(-20000,'Before proceeding, it is recommended to drop the indexes listed above');
    END IF;
    END;
    -- Here go SQL statements that should be executed if no indexes were found
    produces this output when there is an entry in table/view INDEXES:
    SCHEMA_1.INDEX_1
    DECLARE
    ERROR at line 1:
    ORA-20000: Before proceeding, it is recommended to drop the indexes listed above
    ORA-06512: at line 13
    When there are entries in table/view INDEXES, how to:
    - suppress the 'DECLARE' and '*' lines from appearing in the script output;
    - skip executing the SQL statements after the PL/SQL block;
    - have the script return a non-zero code?
    Regards,
    Angel Tsankov

    1 You want the rest of the code not to execute, SO all code should be in one anonymous block.
    The scope of exceptions is one block.
    2 If you want to suppress
    - suppress the 'DECLARE' and '*' lines from appearing in the script output;you should not use raise_application_error, because this is how raise_application_error works.
    - whenever you raise an exception, the return code will be non-zero.
    The code you posted is really very poor, and inefficient, but as it is unclear what you are up to (you seem to want to skip executing everything when there are any indexes, if so you can just count them), it is not possible to provide working code.
    If you want to skip the rest of the code, you can declare your own exceptions, and you should just raise your own exception and the block will abort.
    Hth
    Sybrand Bakker
    Senior Oracle DBA

  • Anonymous PL/SQL Block

    Hello,
    How could I execute an anonymous PL/SQL using ODP.NET? I have de object OracleConnection and the object OracleCommand but I can only set the commandType of this last object to Text or Storedprocedure. Is there any way of doing this?
    Thank you!

    Sure ....
    public decimal OraFGFXCHDelete(decimal key)
                decimal k = -1M;
                StringBuilder sb = new StringBuilder();
                sb.Append("DECLARE");
                sb.Append("\nBEGIN");
                sb.Append("\nDELETE FROM " + PPKS["XCHG_TABLE_NAME"]);
                sb.Append(" WHERE " + FGFXCHG_FIELDS.FGFXCHG_ID.ToString() + " = :P1;");
                sb.Append("\n:O1 := 0;");
                sb.Append("\nIF SQL%FOUND THEN\n :O1 := 1;\nEND IF;");
                sb.Append("\nEXCEPTION\nWHEN OTHERS THEN\n");
                sb.Append(":O1 := -1;");
                sb.Append("\nEND; ");
                using (OracleCommand cmd = new OracleCommand(sb.ToString(), OraConnRef))
                    cmd.CommandType = System.Data.CommandType.Text;
                    cmd.Parameters.Add("P1", OracleDbType.Decimal, ParameterDirection.Input).Value = key;
                    OracleParameter returnkey = new OracleParameter();
                    returnkey.OracleDbType = OracleDbType.Decimal;
                    returnkey.DbType = DbType.Decimal;
                    returnkey.Direction = ParameterDirection.Output;
                    returnkey.Value = key;
                    returnkey.ParameterName = "O1";
                    cmd.Parameters.Add(returnkey);
                    try
                        cmd.ExecuteNonQuery();
                        k = (decimal)cmd.Parameters["O1"].Value;
                    catch (System.Exception)
                        k = -1M;
                return k;
            }r,
    dennis

  • Execute immediate of Anonymous pl/sql block stored in a VARCHAR2 DB Column

    Hi Guys,
    I really hope someone can help me with this.
    I have the following pl/sql anonymous block stored in a varchar2 database column.
    declare
        l_my_val varchar2(32767);
                cursor c_activity is
                SELECT
                      l.DESCRIPTION || decode(l2.DESCRIPTION,null,'',l2.description,  '-' || l2.description) || decode(a.DT,'Y',' - Distributed Training','N',null,null) as value1
                FROM   ACTIVITY a
                      ,MOUNTAINEERING m
                      ,LOV l
                      ,LOV l2
                WHERE  a.JSATFA_ID = 82
                AND    a.SPECIFIC_ACTIVITY_LOV_ID = l.LOV_ID
                AND    m.ACTIVITY_ID(+) = a.ACTIVITY_ID
                AND    m.CLASSIFICATION_LOV_ID = l2.LOV_ID(+);
    begin
    for each_row in c_activity loop
      l_my_val := l_my_val ||  ', ' || each_row.value1;
    end loop;
    :l_value := ltrim (l_my_val, ', ');
    end;  The code is select out of the database and assigned to a local variable within my pl/sql package. The following code should demonstrate what I'm trying to achieve:
    declare
      l_sql varchar2(32767);
      l_value varchar2(32767);
    begin
      select query_sql into l_sql from lov where lov_id = 100;
      execute immediate l_sql using out :l_value;
      dbms_output.put_line(l_value);
    end;However Oracle (10.2.0.2) seems to be doing something funny with the single quotes. and gives the following error:
    ORA-06550: line 1, column 1:
    PLS-00103: Encountered the symbol "" when expecting one of the following:
       begin case declare exit for function goto if loop mod null
       package pragma procedure raise return select separate type
       update while with <an identifier>
       <a double-quoted delimited-identifier> <a bind variable> <<
       form table call close current define delete fetch lock insert
       open rollback savepoint set sql execute commit forall merge
       library OPERATOR_ pipe
    errorIf I embed the code I'm trying to execute within the package i.e
    declare
      l_sql varchar2(32767);
      l_value varchar2(32767);
    begin
      l_sql := q'~declare
        l_my_val varchar2(32767);
                cursor c_activity is
                SELECT
                      l.DESCRIPTION || decode(l2.DESCRIPTION,null,'',l2.description,  '-' || l2.description) || decode(a.DT,'Y',' - Distributed Training','N',null,null) as value1
                FROM   ACTIVITY a
                      ,MOUNTAINEERING m
                      ,LOV l
                      ,LOV l2
                WHERE  a.JSATFA_ID = 82
                AND    a.SPECIFIC_ACTIVITY_LOV_ID = l.LOV_ID
                AND    m.ACTIVITY_ID(+) = a.ACTIVITY_ID
                AND    m.CLASSIFICATION_LOV_ID = l2.LOV_ID(+);
    begin
    for each_row in c_activity loop
      l_my_val := l_my_val ||  ', ' || each_row.value1;
    end loop;
    :l_value := ltrim (l_my_val, ', ');
    end; 
      ~';
      execute immediate l_sql using out :l_value;
      dbms_output.put_line(l_value);
    end;It works perfectly. Notice I have used the q syntax when embedding the sql directly into the package.
    I have tried
    - appending the q syntax directly to query_sql stored in the database
    - escaping the quotes i.e. ' become ''
    Neither method seem to work. We are running 10.2.0.2 on Windows Server 2003. If anyone has any suggestions I would love to hear from you as this has me stumped.
    Regards
    Kris
    - http://kristianjones.blogspot.com

    If you do:
    declare
    l_sql varchar2(32767);
    l_value varchar2(32767);
    begin
    select query_sql into l_sql from lov where lov_id = 100;
    dbms_output.put_line(l_sql);
    end;
    You'll see something like that:
    SELECT
    l.DESCRIPTION || decode(l2.DESCRIPTION,null,'',l2.description, '-' || l2.description) || decode(a.DT,'Y',' - Distributed Training','N',null,null) as value1
    FROM ACTIVITY a
    ,MOUNTAINEERING m
    ,LOV l
    ,LOV l2
    WHERE a.JSATFA_ID = 82
    AND a.SPECIFIC_ACTIVITY_LOV_ID = l.LOV_ID
    AND m.ACTIVITY_ID(+) = a.ACTIVITY_ID
    AND m.CLASSIFICATION_LOV_ID = l2.LOV_ID(+);
    you need to duplicate the '
    you can do many things like:
    CTH@> select * from sqls;
    C
    select first_name || ' ' || last_name as value1 from employees where rownum=1
    1 fila seleccionada.
    CTH@>
    CTH@> ;
    1 declare
    2 l_sql varchar2(32767);
    3 l_value varchar2(32767);
    4 type generic_cursor is ref cursor;
    5
    6 c generic_cursor;
    7
    8 begin
    9 select replace(c, ''', ''''') into l_sql from sqls;
    10
    11 execute immediate l_sql into l_value;
    12 dbms_output.put_line(l_value);
    13* end;
    CTH@> /
    Ellen Abel
    Procedimiento PL/SQL terminado correctamente.
    CTH@>

Maybe you are looking for

  • Custom message is not getting displayed after raising do_not_save

    Hi all, In Order_save BADI, based some conditions, we were throwing custom messages. FYI., code used, CV_OWN_MESSAGE = 'X'. MESSAGE 'xxxxxxxxxxxxxx' TYPE 'W' Raising do_not_save. After Solman upgrade from 7.0 to 7.1, system is not displaying custom m

  • Thunderbolt and older DVI Apple display

    Hi, My current 15" MacBook Pro is linked to a Apple Cinema display using the mini DP to DVI adapter. I'm considering a new MacBook Pro whose Thunderbolt port I understand supports data and video. I understand that if I only replace the MacBook Pro th

  • Bapiekkn

    Hi, I am having a problem with Bapiekkn.  On execution to create a Purchase order I get the following message: Asset 40061 1 not in company code.  40061 is the Asset_No and 1 is the Sub_Number What could possibly be wrong?  Is there a certain combina

  • Altering indents on formatted Word (.doc) files

    I am laying out a legal book which has been formatted in Word. The original has a sub para numbering hierachy of 1 1.1 1.1.1 1.1.2... 1.2 1.2.1 1.2.2... etc. This has been set up in Word as an auto numbering system, to have a fist line indent of 15mm

  • Clean up of objects created using NewObject()

    Hello I've just started playing around with JNI in order to create a Java API layer on top of an existing C++ library. I figured out how to create an instance of a Java class in native code using env->NewObject() method. My question is who takes care