PL/SQL block autocommit option

Hi all,
I have a question about SQL Developer V1.5.5. I have created a procedure to insert a couple rows into a table and there is NO commit statement in my procedure. When I right-click on a "Procedure" in the Procedures tree and run the procedure, the "Run PL/SQL" opened and I click ok to run it. After the procedure finished the changes were committed.
Does anyone know is there a disable autocommit option for "Run PL/SQL"? I found the autocommit option for worksheet, but I couldn't find that option for "Run PL/SQL".
Thanks,

I wish the tool will prompt the user to commit the changes or not when disconnecting.What are you asking for? The tool does ask to commit changes when disconnecting.
Of course it doesn't ask when disconnecting a run/debug session because you'd lose your changes... are you sure you get this (how sessions work)?
K.

Similar Messages

  • Pl/sql block is too slow, should  procedure a better option

    Hi all,
    how to tune A PL/SQL block that traverse cursors and fetch millions of records then execute inserts in different tables,
    using execute immediate statement.
    It's too slow and takes 10 hours to populate 40 tables having millions of records,
    as i have to do some modifications in data so can not do it by CTAS,
    i.e. a single sql statement.
    Should i make a procedure, does it help .
    Please help or suggest As i am New to PL/Sql
    My code look like,
    declare
    cursor     cur_table1 is
         select field1,field2,field3,field4 from table1;
    begin
    for i in cur_table1
    loop
         execute immediate 'insert into table2 (field1,field2,field3,field4) '||
    'select :1,field2,field3,field4 '||
    ' from table1 where field3= :2'
    using i.field1||'_'||to_char(sysdate,'ddmmyyyy hh12:mi:ss',i.field1;
    commit;
    end if;
    end;
    Thanks and Regards,

    declare
    cursor cur_projects is
         select PROJECTID, PROJECTNAME, DESCRIPTION, DELETED, DELETINGDATE, ACTIVE, ADMINONLY, READONLY, SECURITYCLASS, PROJECTCONTACT, DEFAULTVERSION, DEFAULTSTARTPAGE, IMAGEPATH, MAXEXAMINEERRORS, LOCKTIMEOUT, MEMORYSAVINGLEVEL, PRELOADOBJECTS, PUBLICATIONSRCPROJNAME, CREATOR, CREATED, MODIFIER, MODIFIED from projects ;
    cursor cur_projectversion(p_projectid projects.projectid%TYPE) is
         select PROJECTID, PROJECTVERSIONID, PROJECTVERSIONNAME, DESCRIPTION, DELETED , DELETINGDATE, ACTIVE , ADMINONLY, READONLY, decode(EFFECTIVEDATE,null,trunc(sysdate),EFFECTIVEDATE) EFFECTIVEDATE, EXPIRATIONDATE, SECURITYCLASS, PROJECTCONTACT, DEFAULTVERSION, DEFAULTSTARTPAGE, IMAGEPATH, MAXEXAMINEERRORS, LOCKTIMEOUT, MEMORYSAVINGLEVEL, PRELOADOBJECTS, PUBLICATIONSRCPROJNAME, PUBLICATIONSRCPROJVERNAME, CREATOR, CREATED, MODIFIER, MODIFIED, PROFILELOADERCLASS /*, TRACKCHANGES */
         from projectversions where PROJECTID=p_projectid ;
    cursor cur_objects(p_projectid projects.projectid%TYPE,p_projectversionid projectversions.projectversionid%TYPE) is
         select PROJECTID , PROJECTVERSIONID, OBJECTID , OBJECTKEY , PARENTID, KIND , NAME , TITLE , OWNER , CREATED, MODIFIER , MODIFIED , READY_TO_PUBLISH, LAST_PUBLISHED_DATE , LAST_PUBLISHER , EFFECTIVE_PUBLISHING_DATE , PUBLISHER , PUBLISHING_DATE /*, to_lob(scripttext) */ from OBJECTS where PROJECTID=p_projectid and PROJECTVERSIONID=p_projectversionid /*order by objectid */;
    begin
    for i in cur_projects
    loop
    dbms_output.put_line('PROJECTID => '||i.projectid);
    dbms_output.put_line('_________________________________');
    execute immediate 'insert into &TARGET_USER\.projects(locktimeout, memorysavinglevel , preloadobjects, projectid, projectname, description, deleted, deletingdate, active, adminonly, readonly, securityclass, projectcontact, defaultversion, defaultstartpage, imagepath, maxexamineerrors ) values (:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13,:14,:15,:16,:17) '
    using i.locktimeout, i.memorysavinglevel, i.preloadobjects,i.projectid ,i.projectname , i.description , i.deleted , i.deletingdate , i.active , i.adminonly , i.readonly, i.securityclass, i.projectcontact , i.defaultversion, i.defaultstartpage , i.imagepath, i.maxexamineerrors;
    for k in cur_projectversion(i.projectid)
         loop
    for l in cur_objects(k.projectid,k.projectversionid)
              loop
                   cnt:=cnt+1;
    select count(1) into object_exists from &TARGET_USER\.objects where objectid=l.objectid and projectversionid=1 and projectid=l.projectid;
              if object_exists = 0
              then
              if l.objectid = 1 ------Book Object , objectid = 1 and parentid = 0
              then
              execute immediate 'INSERT INTO &TARGET_USER\.objects(PROJECTID,PROJECTVERSIONID,OBJECTID, OBJECTKEY,PARENTID,NAME, KIND,LAST_PUBLISHED_DATE,LAST_PUBLISHER,REVISIONID,DISPLAYORDER,READONLY,DELETED) values( :1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13)'
                        using l.PROJECTID, 1, l.OBJECTID,l.OBJECTKEY, 0 , l.NAME,l.KIND, '' , '' , '', 0, 'N', 'N';
                   else
                        select count(1) into object_parentid_exists from objects where objectid=l.parentid and projectversionid=1 and projectid=l.projectid;
                        if object_parentid_exists = 0 ---Set Parentid as 1
                        then
                                  cnt_parentid_1:=cnt_parentid_1+1;
                                  execute immediate 'INSERT INTO &TARGET_USER\.objects(PROJECTID,PROJECTVERSIONID,OBJECTID, OBJECTKEY,PARENTID,NAME, KIND,LAST_PUBLISHED_DATE,LAST_PUBLISHER,REVISIONID,DISPLAYORDER,READONLY,DELETED) values( :1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13)'
                                  using l.PROJECTID, 1, l.OBJECTID,l.OBJECTKEY, 1 , l.NAME,l.KIND, '' , '' , '', 0, 'N', 'N';
                        else
                                  execute immediate 'INSERT INTO &TARGET_USER\.objects(PROJECTID,PROJECTVERSIONID,OBJECTID, OBJECTKEY, PARENTID, NAME, KIND,LAST_PUBLISHED_DATE,LAST_PUBLISHER,REVISIONID,DISPLAYORDER,READONLY,DELETED) values( :1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12,:13)'
                                  using l.PROJECTID, 1, l.OBJECTID,l.OBJECTKEY,l.PARENTID,l.NAME,l.KIND, '' , '' , '', 0, 'N', 'N';
                        end if;
                   end if ;
         end if;
                   execute immediate 'INSERT INTO &TARGET_USER\.objectversions( PROJECTID, OBJECTID, PROJECTVERSIONID ,VERSIONNAME,OBJECTVERSIONID, REVISIONID,DESCRIPTION, TITLE , OWNER, CREATED, MODIFIER, MODIFIED, READY_TO_PUBLISH , LAST_PUBLISHED_DATE, LAST_PUBLISHER, EFFECTIVEDATE, SCRIPTTEXT, REVIEWSTATUS, READONLY, PUBLISHED, DELETED ) '||
                             'SELECT PROJECTID, OBJECTID, 1, owner||:1, PROJECTVERSIONID , '''', '''', TITLE, OWNER, CREATED, MODIFIER, MODIFIED, ''N'', '''' , '''', :2 , to_lob(SCRIPTTEXT), '''', ''N'', ''N'', '''' '||
                             'FROM OBJECTS '||
                             'WHERE PROJECTID= :3 and PROJECTVERSIONID= :4 and OBJECTID= :5'
                             using '_'||TO_CHAR(k.EFFECTIVEDATE,'DDMMYYHHMISS'),k.EFFECTIVEDATE,l.projectid,l.projectversionid,l.objectid;
         end loop;
         dbms_output.put_line(cnt||' OBJECTS, OBJECTVERIONS POPULATED');
         dbms_output.put_line(cnt_parentid_1||' DUMPED UNDER BOOK FOLDER ');
         cnt_parentid_1:=0;
         cnt:=0;
    ............

  • Pl/sql block on block trigger

    I have a pl/sql block in when-new-block-instance trigger on forms 10g.
    Basically, these trigger fires after user selection of the search criteria block.
    Exist one condition which is totaly important:
    One of the search criteria is a list of document type. So the user, can check one, all or none of the doc types.
    See this pictures:
    doc type options: TRRLS, ADS, SIQD
    If the user check only the TRRLS, the next block will display only the record match the doc type selected. If the user check none doc type, all the record will be displayed.
    For those purpose, in the trigger I talk before (when new block instance) in the results block, I use two cursors, one for all the record (if the user check none doc type). And the other cursor for the records with specific doc type.
    The first one works just fine, but the second one, do nothing. Part of the where in the cursor is the following:
    where ........... and
    dim.doc:typ IN (:global.doc_typ_where_clasue) and
    The value of the :global.doc_typ_where:clause is the list of all the doc type selected by the user. In example, if the user check TRRLS and ADS, the global variable will have 'TRRLS', 'ADS'.
    But it doesn't work..... I don't know why....
    Any idea to pass a list of doc to a cursor and use in a where clause dynamically.
    thanks a lot,
    abdel.

    If you search for "dynamic in list" on http://asktom.oracle.com/ you'll find a solution to exactly the same problem you're facing. The solution is:
    1. Strip the string into an array
    2. Use the array in the where clause.
    But maybe you can also create your own where clause and use that one by setting set_block_property( <block>, onetime_where, <where clause>)
    HTH
    Roel

  • Pl/sql block reading reading table data from single point in time

    I am trying to figure out whether several cursors within a PL/SQL block are executed from within a Single Point In Time, and thus do not see any updates to tables made by other processes or procedures running at the same time.
    The reason I am asking is since I have a block of code making some data extraction, with some initial Sanity Checks before the code executes. However, if some other procedure would be modifying the data in between, then the Sanity Check is invalid. So I am basically trying to figure out if there is some read consistency within a PL/SQL, preventing updates from other processes to be seen.
    Anyone having an idea?.
    BR,
    Cenk

    "Transaction-Level Read Consistency
    Oracle also offers the option of enforcing transaction-level read consistency. When a transaction runs in serializable mode, all data accesses reflect the state of the database as of the time the transaction began. *This means that the data seen by all queries within the same transaction is consistent with respect to a single point in time, except that queries made by a serializable transaction do see changes made by the transaction itself*. Transaction-level read consistency produces repeatable reads and does not expose a query to phantoms."
    http://www.oracle.com/pls/db102/search?remark=quick_search&word=read+consistency&tab_id=&format=ranked

  • Displaying a Message from PL/SQL block to Java Application

    Hi
    How can One display or populate a message in Java Application, that is generated from a PL/SQL block?

    Well, the easiest option would be to have a "message" parameter that gets passed back from the PL/SQL block to the calling Java application.
    I'm guessing, though, that you wouldn't be asking the question if the easy solution was a viable option... If that's the case, you're going to have to describe the problem in a bit more detail...
    Justin

  • Why named parameter can't be used multiple times in PL/SQL block in JDBC

    with the following PL/SQL block, when I run int in JDBC, I get an error,
    it says, The number of parameter names does not match the number of registered parameters.
    if all named parameters are used only once, then my program works fine.
    My old program uses Oracle Forms to run the attached PL/SQL block correctly, I just want to run them in JDBC without more efforts, I don't want to rewrite all PL/SQL blocks.
    Does oracle driver support this case? why the PL/SQL block can work in Oracle Forms but failed in JDBC?
    Can we have an another solutions to avoid rewriting the PL/SQL block to stored procedure?
    if I use following SQL:
    BEGIN if :q is null then :q := 'X'; else :q := 'Y'; end if; END;
    , Using java program:
    import java.sql.*; public class RunPLSQLBlock { public static void main(String s[]) throws SQLException { String URL = "jdbc:oracle:thin:@192.168.11.199:1521:TIBSTEST"; Connection con = null; try { Class.forName("oracle.jdbc.driver.OracleDriver"); con = (Connection) DriverManager.getConnection(URL, "FBP1DEV", "FBP1DEV"); String SQL = "BEGIN  if :q is null then  :q := 'X'; else :q := 'Y'; end if; END;"; CallableStatement stmt = con.prepareCall(SQL); stmt.registerOutParameter("q", Types.VARCHAR); stmt.setString("q", "A"); stmt.execute(); } catch (Exception e) { e.printStackTrace(); } finally { if (con != null) { con.close(); } } } }
    in the coding, only "q" registered, I got:
    java.sql.SQLException: The number of parameter names does not match the number of registered praremeters at oracle.jdbc.driver.OracleSql.setNamedParameters(OracleSql.java:314) at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:10096) at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:5693) at RunPLSQLBlock.main(RunPLSQLBlock.java:28)
    now, tried to register 3 indexes, changed fragments are below.
    import java.sql.*; public class RunPLSQLBlock { public static void main(String s[]) throws SQLException { String URL = "jdbc:oracle:thin:@192.168.11.199:1521:TIBSTEST"; Connection con = null; try { Class.forName("oracle.jdbc.driver.OracleDriver"); con = (Connection) DriverManager.getConnection(URL, "FBP1DEV", "FBP1DEV"); String SQL = "BEGIN  if :q is null then  :q := 'X'; else :q := 'Y'; end if; END;"; CallableStatement stmt = con.prepareCall(SQL); stmt.registerOutParameter(1, Types.VARCHAR); stmt.registerOutParameter(2, Types.VARCHAR); stmt.registerOutParameter(3, Types.VARCHAR); stmt.setString(1, "A"); stmt.execute(); } catch (Exception e) { e.printStackTrace(); } finally { if (con != null) { con.close(); } } } }
    now error changed to:
    java.sql.SQLException: ORA-01006: bind variable does not exist at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:457) at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:400) at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:926) at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:476) at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:200) at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:543) at oracle.jdbc.driver.T4CCallableStatement.doOall8(T4CCallableStatement.java:208) at oracle.jdbc.driver.T4CCallableStatement.executeForRows(T4CCallableStatement.java:1416) at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1757) at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:4372) at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:4595) at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:10100) at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:5693) at RunPLSQLBlock.main(RunPLSQLBlock.java:26)
    , now tried register only 1 position like below,
      CallableStatement stmt = con.prepareCall(SQL);   stmt.registerOutParameter(1, Types.VARCHAR);   stmt.setString(1, "A");   stmt.execute();
    , it says:
    java.sql.SQLException: Missing IN or OUT parameter at index:: 2 at oracle.jdbc.driver.OraclePreparedStatement.processCompletedBindRow(OraclePreparedStatement.java:2177) at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:4356) at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:4595) at oracle.jdbc.driver.OracleCallableStatement.execute(OracleCallableStatement.java:10100) at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:5693) at RunPLSQLBlock.main(RunPLSQLBlock.java:26)
    , now let try a OK case, which use all named parameters only once. coding like below, SQL and Java listed below.
    BEGIN if :q is null then :r := 'X'; else :s := 'Y'; end if; EXCEPTION   WHEN NO_DATA_FOUND THEN     NULL; END;
    import java.sql.*; public class RunPLSQLBlock { public static void main(String s[]) throws SQLException { String URL = "jdbc:oracle:thin:@192.168.11.199:1521:TIBSTEST"; Connection con = null; try { Class.forName("oracle.jdbc.driver.OracleDriver"); con = (Connection) DriverManager.getConnection(URL, "FBP1DEV", "FBP1DEV"); String SQL = "BEGIN  if :q is null then  :r := 'X'; else :s := 'Y'; end if; END;"; CallableStatement stmt = con.prepareCall(SQL); stmt.registerOutParameter("q", Types.VARCHAR); stmt.registerOutParameter("r", Types.VARCHAR); stmt.registerOutParameter("s", Types.VARCHAR); stmt.setString("q", "A"); stmt.execute(); System.out.println("Q :" + stmt.getString("q")); System.out.println("R :" + stmt.getString("r")); System.out.println("S :" + stmt.getString("s")); } catch (Exception e) { e.printStackTrace(); } finally { if (con != null) { con.close(); } } } }
    , the case give us the following output:
    Q :A R :null S :Y
    2nd part, I also tried another scheme, to use 'execute immediate', test code attached below, it also have errors.
    begin execute immediate 'begin if :q is null then :q := ''X''; else :q := ''Y''; :r := ''Z''; end if; end;' using in out :q, out :r; end;
    , Java Code:
    import java.sql.*; public class RunDynamicSQL { public static void main(String s[]) throws SQLException { String URL = "jdbc:oracle:thin:@192.168.11.199:1521:TIBSTEST"; Connection con = null; try { Class.forName("oracle.jdbc.driver.OracleDriver"); con = (Connection) DriverManager.getConnection(URL, "FBP1DEV", "FBP1DEV"); String SQL ="begin execute immediate 'begin if :q is null then :q := ''X''; else :q := ''Y''; :r := ''Z''; end if; end;' using in out :q, out :r; end;"; CallableStatement stmt = con.prepareCall(SQL); stmt.registerOutParameter("q", Types.VARCHAR); stmt.registerOutParameter("r", Types.VARCHAR); stmt.setString("q", "A"); stmt.execute(); System.out.println("Q :" + stmt.getString("q")); System.out.println("R :" + stmt.getString("r")); } catch (Exception e) { e.printStackTrace(); } finally { if (con != null) { con.close(); } } } }
    , the output is, we can find when parameter 'q' is IN OUT mode, we can't get its final value:
    Q :null R :Z
    , now I tried my workaround, it works fine by using a temporary variable, now my named parameter is split to 2 roles, one is for IN, another is for OUT, now I can get final out value.
    declare q clob; r clob; begin q := ?; r := ?; execute immediate 'begin if :q is null then :q := ''X''; else :q := ''Y''; :r := ''Z''; end if; end;' using in out q, out r; ? := q; ? := r; end;
    , my test java code,
    import java.sql.*; public class RunDynamicSQL { public static void main(String s[]) throws SQLException { String URL = "jdbc:oracle:thin:@192.168.11.199:1521:TIBSTEST"; Connection con = null; try { Class.forName("oracle.jdbc.driver.OracleDriver"); con = (Connection) DriverManager.getConnection(URL, "FBP1DEV", "FBP1DEV"); String SQL ="declare q clob;r clob; begin q := ?; r := ?; execute immediate 'begin if :q is null then :q := ''X''; else :q := ''Y''; :r := ''Z''; end if; end;' using in out q, out r; ? := q; ? := r; end;"; CallableStatement stmt = con.prepareCall(SQL); stmt.registerOutParameter(3, Types.VARCHAR); stmt.registerOutParameter(4, Types.VARCHAR); stmt.setString(1, "A"); stmt.setString(2, "A"); stmt.execute(); System.out.println("Q :" + stmt.getString(3)); System.out.println("R :" + stmt.getString(4)); } catch (Exception e) { e.printStackTrace(); } finally { if (con != null) { con.close(); } } } }
    , the output is expected,
    Q :Y R :Z
    Database:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    JDBC Driver, extracted from ojdbc6_g.jar/META-INF/MANIFEST.MF :
    Created-By: 1.5.0_30-b03 (Sun Microsystems Inc.)
    Implementation-Vendor: Oracle Corporation
    Implementation-Title: JDBC debug
    Implementation-Version: 11.2.0.3.0
    Repository-Id: JAVAVM_11.2.0.3.0_LINUX_110823
    Specification-Vendor: Sun Microsystems Inc.
    Specification-Title: JDBC
    Specification-Version: 4.0
    Main-Class: oracle.jdbc.OracleDriver
    JDK:
    java version "1.7.0"
    Java(TM) SE Runtime Environment (build 1.7.0-b147)
    Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode, sharing)
    Edited by: jamxval on 2013-3-22 2:01PM (UTC+08:00), Give full test java program and SQL, added environment/API level; Attached another problem.
    Edited by: jamxval on 2013-3-26 17:57 (UTC +08), Adjust code style

    Hi, thanks for your response, now I see, the named parameter is for stored procedure only, for PL/SQL block we name it placeholder name.
    After cast my java.sql.CallableStatement to oracle.jdbc.OracleCallableStatement, I can find setStringAtName,
    now, I have only one question:I can't find corresponding methods for registerOutputParameter, how we fetch output value?
    I tried to callableStatement.getString("q"); it reports errors, but there are no ordinal binding in my source code, does placeholder names doesn't support OUT mode?
    Java:
    CallableStatement stmt = con.prepareCall("BEGIN  if :q is null then  :r := 'X'; else :s := 'Y'; end if; END;");
    oracle.jdbc.OracleCallableStatement call = (oracle.jdbc.OracleCallableStatement) stmt;
    call.registerOutParameter("q", Types.VARCHAR);
    call.registerOutParameter("r", Types.VARCHAR);
    call.registerOutParameter("s", Types.VARCHAR);
    call.setStringAtName("q", "A");
    call.setStringAtName("r", "A");
    call.setStringAtName("s", "A");
    call.execute();
    System.out.println("Q :" + call.getString("q"));
    </Java>
    <output>
    java.sql.SQLException: 不允许的操作: Ordinal binding and Named binding cannot be combined!
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
         at oracle.jdbc.driver.OracleCallableStatement.getString(OracleCallableStatement.java:2834)
         at RunPLSQLBlock.main(RunPLSQLBlock.java:33)
    </output>by the way, in my below-mentioned SQL 'problematic', when my code uses 'execute immediate' and use placeholder names in IN OUT mode, we always get NULL value (i.e. ':q'), but we can get final value of ':r' when ':r' is OUT mode only; now I get a workaround attached in below-mentioned 'my workaround' block, which split the IN OUT roles to 2 parts, it can work now;
    It seems that the difference between 'problematic' and 'my workaround' imply that there are something work unexpectedly when the driver process the placeholder names, because 'my workaround' and ':r in problematic case' make sure the 'execute immediate' returned output values correctly, unluckly driver layer can't get return values.
    <SQL name = 'problematic'>
    begin
         execute immediate 'begin if :q is null then :q := ''X''; else :q := ''Y''; :r := ''Z''; end if; end;'
         using in out :q, out :r;
    end;
    </SQL>
    <SQL name='my workaround'>
    declare     
         q clob;
         r clob;
    begin
         q := ?;
         r := ?;
         execute immediate 'begin if :q is null then :q := ''X''; else :q := ''Y''; :r := ''Z''; end if; end;' using in out q, out r;
         ? := q;
         ? := r;
    end;Edited by: EJP on 26/03/2013 14:14

  • Resolved: Use value from select list in pl/sql block

    Hello,
    I have a form with a select list: P18_BONUSTYPE, the values of which come from a LOV.
    When the user clicks a button, a page process is used to insert a row into a table.
    When I use the :P18_BONUSTYPE bind variable in my insert statement I get an error "Invalid number" I get an "Invalid number" error. I assume that APEX is using the displayed text in that bind variable, not its actual (html option) value.
    I checked the HTML of the page, and the correct values are in the select list.
    Can someone tell me how to get the value into a bind variable that can be used in a pl/sql block for a page process?
    Thanks
    Message was edited by:
    Neeko
    Issue was a value in another item.

    Did you tried changing the value using "to_number"? (i.e. to_number(:P18_BONUSTYPE)).
    Max.

  • Copy Command in Pl/Sql block

    Can I use Copy command in Pl/Sql.For example :-
    Declare
    cursor c1 is select table_name from all_tables
    where owner = 'LSP' and rownum = 1;
    v1 varchar2(2000);
    Begin
    for c2 in c1 loop
    v1:='copy from lsp/lsp123479@dvlaq to scott/[email protected] create '|| c2.table_name ||' using select * from '||c2.table_name;
    execute immediate v1;
    end loop;
    end;
    Its not running properly giving an error as invalid Sql statement .
    Is it bcoz Copy command cannot be used in a Pl/Sql Block.

    Is there any other way to move the Table & data to another Data Base .Database link is the obvious one. And the SQL statement would look something like this (on the target database):
    SQL> create table FOO nologging as select * from FOO@sourcedb;
    However, the first question I always ask if why? What one may think is the solution to a problem is not always the best solution. So one need to identify the problem first, and then see what solutions there are and which one is the best fit.
    Other options are replication (using materialised views for example), Data Pump (available with 10G) - even could be Data Guard, a standby database, or a Real Application Cluster... depending on just what the problem and actual requirements are.
    Also important to note that SQL*Plus has its own set of commands. Do not confuse these commands (like EXEC, COPY, CONNECT, HOST etc) with the SQL and PL/SQL Languages. Not only are they executed by different software products, SQL*Plus commands are executed on the client and SQL (and PL/SQL) runs inside the Oracle database instance.

  • Obtaining a collection as a return from an execute immediate pl/sql block

    version 10.2
    I need to obtain the collection back from the execute immediate of a pl/sql block:
    procedure block(owner varchar2) is
    stmt                   long;
    objecttab_coll         dbms_stats.objecttab;
    begin
    stmt := '
       begin
        dbms_stats.gather_schema_stats(''' || owner || '''
         ,options => ''LIST AUTO''
         ,objlist => :objecttab_coll
       end;'; 
    execute immediate stmt returning into objecttab_coll;
    -- do more stuff here
    end block;I have tried this + a few variations but with no luck. In looking through the docs I do not see an example. can this be done?
    Thanks
    Ox

    I dont find any need for an execute immediate here. This must be just enough.
    procedure block(owner varchar2)
    is
         objecttab_coll         dbms_stats.objecttab;
    begin
         dbms_stats.gather_schema_stats(ownname => owner, options => 'LIST AUTO', objlist => objecttab_coll);
         -- do more stuff here
    end block;Thanks,
    Karthick.

  • How to search source of pl/sql block in database?

    Hi Guys,
    We have an issue in database, there is PL/SQL block running in my database as below which deleting very important historical data.
    begin
    loop
    delete from tabl_name where created_date<sysdate -100 and ronum<10000;
    EXIT WHEN SQL%NOTFOUND;
    commit;
    end loop;
    end;
    I tried following,
    1) I found this block in v$sqlarea
    2) I searched in dba_source,user_source,all_source but no luck.
    3) I checked all the triggeres but no luck.
    4) I checked all the cron entries for oracle/root/app owner in os but no luck.
    5 I checked all the jobs in dba_jobs but no lcuk
    would appreciated if anyone can assist on this.
    I want to disable/remove this query to be executed.
    Regards,
    Rikki

    For ASH,
    I am trying to confirure the OEM and not able to access the OEM from remotely. However any idea from commad prompt.
    I believe there is a script ashrpt.sql but while running this script format is not supporting.
    any idea if you have run it before.
    I agree for log miner utilities, but I need to configure the UTL dir and need to bounce it and its a critical production environment so looking for alternatives. if not possible I would go for this option.
    It seems ASH report is being geneated lets see how does it go.
    Regards,
    Pradeep
    Edited by: user13049723 on Jul 26, 2010 8:07 PM

  • Spooling from PL/SQL Block

    Hi,
    Is it possible to do spooling from a pl/sql block.The spool cannot be the first command because I want to give the spool file name in a loop and each time the spool name should change based on the value.
    I tried all possiblities,but I couldn't can anyone give me some idea on how to do this.
    I cannot use UTL_FILE option ,because the client agreed only for spooling.
    Is it possible to write the spool data is excel format..
    Please find below an example of my requirement..
    DECLARE
    CurSor Cur_Designation IS
    Select Designation from tbl_Designation;
    N_Desig Cur_Designation%RowType;
    Cursor Cur_Emp(Desig Number) IS
    Select Emp_no,Emp_name
    From Employee Where Emp_Designation = Desig;
    N_Emp Cur_Emp%RowType;
    BEGIN
    Open Cur_Designation ;
    Loop
    Fetch Cur_Designation INTO N_Desig;
    EXIT WHEN Cur_Designation %NOTFOUND;
    --Here I want to give the spool file name
    Spool --Should be designation name
    Open Cur_Emp(N_Desig.Designation);
    Loop
    Fetch Cur_Emp INTO N_Emp ;
    EXIT WHEN Cur_Emp %NOTFOUND;
    -- All employee details I need to come to log file
    End Loop;
    Close Cur_Emp;
    End Loop;
    Close Cur_Desingnation;
    End;
    Please advice me how to do this..
    Thanks,
    Bindu

    << I cannot use UTL_FILE option ,because the client agreed only for spooling. >>
    << I want to use it in a PL/SQL Block.I have some variables to declare and some cursors to be used.
    So where should I use the spool command.
    I tried to given after a fetch command ,but it is not working. >>
    you can't use SPOOL inside PLSQL
    you may use dbms_output calls in PLSQL
    so create a procedure test2 instead of sqlscript test2 and you will be fine
    rem =========== procedure test2 ================
    create or replace
    procedure test2 (p_param number) is
    begin
                 dbms_output.enable (1000000);
                 dbms_output.put_line('A' || chr(9) || 'B' || chr(9) || 'C' ) ;
                 FOR i_rec in (select a,b.c from xyz where a = p_param) LOOP
                     dbms_output.put_line (to_char(a) || chr(9) || b || chr(9) || c ) ;
                 END LOOP ;
    end ;
    REM ====================================================                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • 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

  • Use Chains, or PL/SQL Block of calls.

    I currently have a half dozen cron jobs that kick off different batches of processing. Originally, these were generally a sequence of C programs that did different operations (fetch student info from student record system and load into IdM system, process directory changes, etc). Over the years, most of the program logic has been rewritten as PL/SQL packages and the cron jobs basically drop into SQL*PLUS and do things like:
    prompt "Do Spbpers delta"
    execute simon.employee_maint.Spbpers_Delta;
    commit;
    prompt "Do People.Update_From_Employees"
    execute simon.People_Maint.Update_From_Employees;
    commit;
    prompt "Do SGBSTDN_Full"
    execute Simon.Bstudent_Maint.Sgbstdn_Full;
    commit;
    prompt "Do SPRIDEN_Full (Student)"
    execute Simon.Bstudent_Maint.Spriden_Full;
    These procedures generally connect to other Oracle databases and get or push data around, and are hitting a number of different databases. The biggest of these scripts has 45 execute statements in it. (This script started in 1992.....)
    Anyway, we are getting some issues with and it is time to clean things up. This is my first foray into Scheduler and I am hoping to get some philosophical guidance on how best I should restructure things. One obvious thing, is to break up the big script into a couple of smaller ones. In some cases, order matters and in other, it doesn't - although I would prefer not to have several jobs hitting the admin system at the same time.
    I have been playing a bit with the scheduler, mostly via the EM web interface, and have come up with a few questions - some pretty specific, others more stylistic.
    1) Procedures as jobs - it seemed to want stand alone procedures, and NOT procedures that were part of a package. True?
    2) How fine grained should I make the steps in a chain? For example, I call 5 procedures in the same package (student_maint), each to to some specific aspect of the processing (each represents a different source table). Should I create 5 programs, and make them 5 steps in the chain, or just have 5 calls in a PL/SQL block in one program?
    3) I don't care what order these 5 run in, but I don't want more than one running at once - thoughts on approaches to this?
    4) I will on occasion want to turn off sets of these tasks (like when the remote system is going to be down for an upgrade) - how best to structure things to make this easy to do (and how do I do this?)
    The Scheduler system seems to be a very rich and flexible environment, with a lot more options and features than I need, but I feel I should do more than just scheduling a single program with 45 procedure calls in it....

    Hi,
    I can try to answer some of these questions
    1) Procedures as jobs - it seemed to want stand alone procedures, and NOT procedures that were part of a package. True?
    False. The EM interface does have this restriction, but if you use dbms_scheduler directly there is no such restrisction. Even in the EM interface you can workaround this by using a PL/SQL block which calls the package procedure (although argument handling is a little less flexible this way).
    2) How fine grained should I make the steps in a chain? For example, I call 5 procedures in the same package (student_maint), each to to some specific aspect of the processing (each represents a different source table). Should I create 5 programs, and make them 5 steps in the chain, or just have 5 calls in a PL/SQL block in one program?
    The answer to this depends on what you are doing. If the 5 steps run serially one after the other, using one pl/sql block may be easier. If you want some pieces to run in parallel, then creating a simple chain is better. A bit more effort spent setting up the chain will result in much faster execution times if you can run pieces in parallel.
    3) I don't care what order these 5 run in, but I don't want more than one running at once - thoughts on approaches to this?
    This has come up on the forum a few times and there are basically two different approaches. One is to use dbms_lock to ensure that only one runs at a time. This is the easiest way and the way that I recommend.
    The other way is to set up a job class with a resource consumer group and put into effect a resource consumer plan that specifies that only one session from that resource consumer group can run at a time. This is easily extensible to cases where you want 2 or more running at a time from a certain job class (which dbms_lock doesn't support).
    Code on how to set this up and more discussion is located here
    Run Jobs One After Another
    4) I will on occasion want to turn off sets of these tasks (like when the remote system is going to be down for an upgrade) - how best to structure things to make this easy to do (and how do I do this?)
    Jobs and programs can be disabled. But if a job or chain tries to run a disabled program it will result in a failure (though it will be retried if you say that the job can be restarted).
    [ 5) ] The Scheduler system seems to be a very rich and flexible environment, with a lot more options and features than I need, but I feel I should do more than just scheduling a single program with 45 procedure calls in it....
    The Scheduler was intended to accommodate a wide range of usage from simple one-off background tasks to complex sequences of interrelated tasks. As with any other software development you should use it in the simplest way possible that does what you need it to do.
    Hope this helps. Feel free to post any further questions.
    -Ravi

  • PL/SQL block to sql case

    Hello,
    I have a newbie sql question:
    I have the following pl/sql block that I want to transform in sql case code:
                 IF Num_WholesaleNonDiscountValue > 0.0 THEN
                      UsageStatus := 'CHARGE';
                      if Num_WholesaleNonDiscountValue < 1.0 then
                          WholesaleNonDiscountValue := '0' || TO_CHAR(Num_WholesaleNonDiscountValue);
                        else
                          WholesaleNonDiscountValue := TO_CHAR(Num_WholesaleNonDiscountValue);
                      end if;
                  ELSE
                      UsageStatus := 'FREE';
                      WholesaleNonDiscountValue := TO_CHAR(Num_WholesaleNonDiscountValue);
                  END IF;All I do is the following code:
    select (case when Num_WholesaleNonDiscountValue > 0.0 then
                              (case Num_WholesaleNonDiscountValue < 1.0 then  '0' || TO_CHAR(Num_WholesaleNonDiscountValue
                               else TO_CHAR(Num_WholesaleNonDiscountValue))
             else TO_CHAR(Num_WholesaleNonDiscountValue)) from table_name;I do not know how to evaluate the UsageStatus variable, where to put it in the select statement.
    This is for my learning process.
    Thanks in advanced,
    Dan
    Edited by: danut68 on Jan 13, 2010 5:52 AM

    Hi, Dan,
    I think you want something like this:
    SELECT     CASE
              WHEN  Num_WholesaleNonDiscountValue > 0
              THEN  'CHARGE'
              ELSE  'FREE'
         END                              AS UsageStatus
    ,     CASE
              WHEN  Num_WholesaleNonDiscountValue > 0
              AND   Num_WholesaleNonDiscountValue < 1
              THEN  '0'
         END || TO_CHAR (Num_WholesaleNonDiscountValue)     AS WholesaleNonDiscountValue
    FROM     table_x
    ;A CASE expression returns one value.
    In PL/SQL, you can do two or more completely separate things (set two different variables, for example) in the same IF-THEN-ELSE block.
    To get the same results in SQL requires a completely different approach.
    The clearest is to use a different CASE expression for each of the things you're trying to do, as I did above. The WHEN clauses of those CASE statements may be very similar, even identical.
    Sometimes you can factor out some of the logic (using a sub-query, perhaps) so that the logic that has to be repeated in each CASE expression is very simple.
    Another option for setting two variables is to have a single CASE expression that returns a string wihich is the concatenation of two different varibales, which you later parse into two separate variables. I would do this only as a last resort.

  • Executing ddl statment in pl/sql block

    Hi all,
    could anyone pls help in method for executing ddl statment in pl/sql block other than 'execute immediate' ?

    could anyone pls help in method for executing ddl statment in pl/sql block other than 'execute immediate' ?On newer db versions you have more options:
    SQL> desc t
    Error: object t does not exist
    SQL> exec sys.dbms_prvtaqim.execute_stmt('create table michael.t (a integer)')
    PL/SQL procedure successfully completed.
    SQL> desc t
    TABLE t
    Name                                      Null?    Type                       
    A                                                  NUMBER                     
    SQL> exec sys.dbms_utility.exec_ddl_statement('drop table michael.t')
    PL/SQL procedure successfully completed.
    SQL> desc t
    Error: object t does not exist;)

Maybe you are looking for