How to execute dynamic if statement...

Hi All,
My PL/SQL Blocks looks like this
declare
i_string :='if 3>20 then 1 else 2 end if;' varchar2(100);
begin
end;
Between begin and end i want a piece of code which executes that if statement and sends 2 as output in dbms_output.put_line since 3 is not >20 .Basically i want to know how to execute dynamic if statement.Please help
Thanks,
Preethi

Hi,
i agree with Cyn. Dynamic SQL is often a bad idea. Try to avoid it.
Dynamic PL/SQL is even worse. If you really must do something dynamic, at least try to cast it as SQL rather than PL/SQL.
Does this do what you want?
CREATE OR REPLACE FUNCTION     eval_case
(     in_txt     IN     VARCHAR2
RETURN     NUMBER
DETERMINISTIC
IS
     return_val     NUMBER;
     sql_txt          VARCHAR2 (1000);
BEGIN
     sql_txt := 'SELECT  CASE '
          ||           in_txt
          || '         END'
          || '  FROM  dual';
     EXECUTE IMMEDIATE sql_txt INTO return_val;
     RETURN     return_val;
END     eval_case;
SHOW ERRORSYou might use the function above like this:
declare
     i_string  varchar2(100) :='WHEN 3>20 THEN 1 ELSE 2';
begin
     dbms_output.put_line (  TO_CHAR (eval_case (i_string))
                    || ' = results of eval_case ('''
                    || i_string
                    || ''')'
end;
/

Similar Messages

  • How can I execute Dynamic SQL statement in Forms?

    Hi All,
    I have to execute dynamic SQL statement from Forms
    Below statement I have to execute
    "EXECUTE IMMEDIATE v_stmt INTO v_return;".
    Googled for the same got results saying, Better use Database function or procedures to execute these Dynamic Statements but We want to execute in forms only.
    Can any one help me..
    Thanks,
    Madhu

    So in short you are trading code obfuscation for maintainability and the ability to share code between tools? If from somewhere else you need a procedure already implemented in database PL/SQL (and now ported to forms) this would mean you'd need to implement it in every other tool. In times where you might want to integrate your forms with $other_technology and putting stuff on the database is the first step to share functionality you just go the opposite way? And all that because someone is afraid that somebody might steal your source code? I am sorry to be blunt, but this is just plain stupid.
    Leaving aside that some things like Analytic Functions, Bulk processing or execute immediate are not even available in forms your software consists of how many LOC? How long does it take to bring a new developer up to speed with your source code? Imagine how long that would take for a developer who doesn't have coleagues who know their way around.
    And just so you know: I work for a ISV selling a closed-source product as well. We have 200+ customers all over the planet. We are well aware that wrapped packages can be reverse engineered. The premise is: stored procedures can be reused in every tool we have, if it makes sense to put stuff on the database by all means do it. If someone would want to reverse engineer our software I'd wish him good luck as some parts are implemented in such a hilarious complicated way I have troubles understanding them (and quite frankly I refuse to understand certain parts, but that's another story). I do work for almost 10 years for that ISV.
    In any case the possible solutions have already been mentioned: you have exec_sql, create_group_from_query and forms_ddl to execute dynamic SQL in forms whereas forms_ddl is a one way street and most certainly not the thing you need or want. Take a look at the documentation for the other 2 things.
    cheers

  • How to execute a SELECT statement  in java??

    Hello !!
    In my java program , i need to delete a record of number X, so
    i accept the number X from the keyboard
    Then before deleting it
    i want the program to show me the name, age of the record which has the number X
    How to do this

    hello kylas
    actually i didnt get why this program example?? wats
    its executing ??? Look at reply #3 in your other thread:
    http://forum.java.sun.com/thread.jspa?threadID=713289&messageID=4126346
    Notice the similarity? You've now asked "How to delete a record in Java" and "how to execute a select statement in java". You may have noticed that, aside from the SQL and the call to execute and executeUpdate (for delete) it's the same code. This is because you don't so much do these things in Java, you do them in SQL. The Java code simply asks the Driver to execute whatever SQL you write. So, I really hope your next post isn't "how do I execute an UPDATE statement in Java".
    Good Luck
    Lee

  • How to execute a select statement in unix shell script

    Hi,
    How to execute the below statement in unix shell .
    select count( ID) into v_count from tbl_data1
    where ID =V_ID;
    thanks
    BCJ

    Thanks for the reply.
    few more doubts,
    the V_ID value is a user input getting inside the unix script, so how can i pass the value in to the a.sql.
    also needs the v_count value inside the unix script for further process.actual requirement is like,
    declare
    v_count number;
    begin
    select count( ID) into v_count from tbl_data1
    where ID =$V_ID;
    if v_count>1 then
    process 1;
    else
    process2;
    end if;
    end;
    thanks a lot

  • How to execute multiple sql statements in parallel ?

    Hi There,
    I have 10 stored procedures, each one will take approximately 5 seconds to run individually.
    Now I need to combine the results of these 10 stored procedures into single result set.
    So I have created one more stored procedure "proc_AllSPs" to get the single result set.
    The procedure "proc_AllSPs" is taking one minute to run because all the procedures inside the "proc_AllSPs" are running
    one after the other and taking 5 seconds each.
    If there is any other way that all the procedures run parallelly, then the procedure "proc_AllSPs" can run in 5 seconds time.
    Sorry if I am not being elaborated.
    PLease get back to me if any piece of information is needed.
    Any kind of help is truly thankful.
    Thanks,
    SequelBug

    Could you tell me how to execute two stored procedures or two sql statements in parallel
    For eg:
    First procedure name is proc_sp1 which takes 1 minute to run
    Second procedure name is proc_sp2 which takes 1 minute to run
    I want to accomplish the below query in 1 minute by executing statement1 and statement2 parallelly.
    go
    select * from openrowswt('sqloledb','server','exec proc_sp1')    --statement1
    union
    select * from openrowset('sqloledb','server','exec proc_sp2')     --statement2
    go
    OR
    go
    Select * into #Temp1  from openrowswt('sqloledb','server','exec proc_sp1') --statement1
    select * into #Temp2 from openrowset('sqloledb','server','exec proc_sp2') --statement2
    Select * from #Temp1
    UNION ALL
    Select * from #Temp2
    go
    Thanks,
    SequelBug

  • How to execute multiple sql statements

    hi all
    i am wondering if i can execute multiple sql statements in one shot with >> execute immediate command
    for example:
    i define the variable as X := sql statement
    Y := sql statement
    z := sql statement
    can i do execute immediate (X,Y, Z);
    if yes how ?? and if not any possible alternate
    thanks

    Starting with Ganesh's code
    DECLARE
       l_statement                 VARCHAR2 (2000);
       v_passwd                    VARCHAR2 (200);
       v_username                  VARCHAR2 (200) := 'test';
       v_pwd_key                   VARCHAR2 (200) := 'lwty23';
       v_dblink_name               VARCHAR2 (2000);
       v_dblink_drop               VARCHAR2 (2000);
       v_dblink_create             VARCHAR2 (2000);
       v_dblink_check_connection   VARCHAR2 (2000);
       l_number                    NUMBER;
    BEGIN
       --<<c_instance>>
       FOR c_instance IN (SELECT *
                            FROM v_oracle_instances
                           WHERE environment = 'Developement')
       LOOP
          SELECT encpwd_owner.display_db_encpwd (v_username,
                                                 c_instance.host_name,
                                                 c_instance.instance_name,
                                                 v_pwd_key)
            INTO v_passwd
            FROM DUAL;
          v_dblink_name := c_instance.host_name || '_' || c_instance.instance_name;
          v_dblink_create :=
                ' CREATE DATABASE LINK '
             || v_dblink_name
             || ' CONNECT TO '
             || v_username
             || ' '
             || 'IDENTIFIED BY '
             || v_passwd
             || ' USING'
             || ' ''(DESCRIPTION=
    (ADDRESS=(PROTOCOL=TCP)(HOST= '
             || c_instance.host_name
             || ')(PORT='
             || c_instance.LISTENER_PORT
             || '))(CONNECT_DATA=(SID='
             || c_instance.instance_name
             || ')))''';
          v_dblink_check_connection := 'select 1 from global_name@' || v_dblink_name || '.QCM';    --- Notice this change. I am simply selecting 1. That should be enough to test the database link.
          v_dblink_drop := 'drop database link ' || v_dblink_name || '.QCMTLAF';
          -- l_statement := 'BEGIN ' || v_dblink_create ';' || v_dblink_check_connection ';' || v_dblink_drop '; END ;'
          BEGIN
              EXECUTE IMMEDIATE (v_dblink_create);
              DBMS_OUTPUT.PUT_LINE ('DB Link ' || v_dblink_name || ' Created');
         EXCEPTION
            WHEN others THEN
               dbms_output.put_line( 'Failed to create the database link ' || v_dblink_name  );
               dbms_output.put_line( dbms_utility.format_error_backtrace() );
               INSERT INTO error_table( column_list )
                 VALUES( <<list of values>> );
         END;
          EXECUTE IMMEDIATE (v_dblink_check_connection) INTO l_number;    --- Notice this.
          DBMS_OUTPUT.PUT_LINE ('DB Link ' || v_dblink_name || ' Tested');
          BEGIN
             EXECUTE IMMEDIATE (v_dblink_drop); 
             DBMS_OUTPUT.PUT_LINE ('DB Link ' || v_dblink_name || ' Dropped');
          EXCEPTION
             WHEN others THEN
               dbms_output.put_line( 'Failed to drop the database link ' || v_dblink_name  );
               dbms_output.put_line( dbms_utility.format_error_backtrace() );
               INSERT INTO error_table( column_list )
                 VALUES( <<list of values>> );
         END;
       END LOOP;
    END;But I agree with the point that others have brought up that it really doesn't make sense to create and drop a database link like this.
    Justin

  • How to execute multiple sql statement?

    In an single transaction I want to execute two update statements. I don't know how to break those statements and send to oracle from Asp.Net to execute.
    I tried go and ; .
    Below is myQuery string*
    update abc set One = 10 where Two = 3 ; update xyz set Three = 10 where Four = 3 ;
    Additional info
    I am using sql comment text in asp.net
    I am using executenonquery command in asp.net.

    Hi,
    If you want to execute multiple statements in a single transaction, you could either:
    a) create a local transaction (via an OracleTransaction object), then call executenonquery multiple times within that transaction, or
    b) pass them all in an anonymous block for a single round trip.. ie, begin update abc set One = 10 where Two = 3 ; update xyz set Three = 10 where Four = 3 ;end;
    The database doesn't permit multiple statements passed at once (other than in a plsql block).
    Hope it helps, corrections/comments welcome
    Greg
    PS, questions such as this would be better posted in the ODP.NET forum; this forum is for issues regarding ODT.NET (a VS plugin)
    ODP.NET

  • How to execute "gather schema stats" in parallel?

    Hi,
    I've a 11.2 Standard Edition and I need to gather stats for about 20 schemas.
    It's possible to execute with a plsql (or other) dbms_stats.gather_schema_stats in parallel?
    I want to execute 4 schema stats at time, and when one finish another one starts.
    It's possible?
    Thanks

    Mr.D. wrote:
    Hi,
    I've a 11.2 Standard Edition and I need to gather stats for about 20 schemas.
    It's possible to execute with a plsql (or other) dbms_stats.gather_schema_stats in parallel?
    I want to execute 4 schema stats at time, and one finish another one starts.
    It's possible?
    Thanks
    yes it is possible by opening 4 different   sessions
    which system resource will be saturated first?

  • How to execute multiple SQL statements thru frontend?

    With SQL Server database, you can execute multiple SQL statements.
    Ex.
    SQLCommand cmd = new SQLCommand();
    cmd.CommandText = "SELECT * FROM EMP; SELECT * FROM DEPT";
    cmd.ExecuteXXX();
    Note that for SQL Server, ";" (semocolon) is used as a separator.
    What separator is required for Oracle ? Or rather, can I execute multiple SQL statements against Oracle database (10g) ?
    (Why I want to do it is a totally diff. subject !)
    Thanks,
    Ami.

    Hello,
    You could use an anonymous PL/SQL block to batch multiple statements.
    If you want to use SELECT statements, you would open a REF CURSOR for each SELECT and return the REF CURSOR to your application. INSERT, UPDATE, and DELETE statements can just be passed as is.
    A simple REF CURSOR example might look like:
    begin
      open :v_refcursor1 for select * from emp;
      open :v_refcursor2 for select * from dept;
    end;Where v_refcursor1 and v_refcursor2 are parameters defined as a REF CURSOR type.
    Hope that helps a bit...
    - Mark

  • Execute Dynamic SQL statement using procedure builder

    i want to execute a dynamic SQL statment using procedure builder not using forms
    because my statement depending on a variable table name
    i know that i can do that from forms using
    FORMS_DDL('SQL_STAT');
    but i wanna to use the procedure builder
    which function i should use and how?
    please explain in example if you don't mind.
    thanks

    Hi,
    You can very well use DBMS_SQL Package supplied by Oracle for doing this.
    Search for DBMS_SQL in OTN. You will get all info regarding this.
    Regards.
    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by itslul:
    i want to execute a dynamic SQL statment using procedure builder not using forms
    because my statement depending on a variable table name
    i know that i can do that from forms using
    FORMS_DDL('SQL_STAT');
    but i wanna to use the procedure builder
    which function i should use and how?
    please explain in example if you don't mind.
    thanks<HR></BLOCKQUOTE>
    null

  • How to execute multiple sql statements in oracle?

    I want to execute multiple statements in a single transaction in oracle. Following are my queries:
    Create table temp_table as Select * from table;
    SELECT * FROM temp_table d;
    drop table temp_table ;
    I am using sql comment text in asp.net
    I am using executenonquery command in asp.net.
    Thanks,
    Divya

    SigCle ,
    Here's an example that executes 3 statements;
    begin insert into foo values(1); insert into foo values(2); insert into foo values(3); end;
    923354,
    The block doesn't compile because temp_table doesn't exist at the point you're trying to compile the anonymous block. I'd recommend re-reading the doc link and forum link provided to get a better understanding of how temp tables work, as it's simply different with Oracle. You don't create Oracle temporary tables on the fly; you create them ahead of time and then just use them. The data itself is already specific to a particular session; you don't create and drop the table each time.
    Also, you can't just "select * from table" in plsql. The results have to GO SOMEWHERE. Usually you'd either open a cursor and process it in the block, or send out a ref cursor if you want to send the data to a client side app. The ref cursor data wouldn't actually be fetched until the block completes though, so you'd need to use ON COMMIT PRESERVE ROWS, which would also mean you'd need to clean up the data yourself (delete the data from the table when you're done with it).
    Corrections/comments welcome.
    Greg

  • ADF with JSF: How to execute a Sql statement created in a form

    Hello to every body,
    I'm working in JDeveloper 11.1.2.1.0, I have to do a development when the user can create a SQL statement and I have execute that before to do commit to the DB(Oracle DB).
    Example:
    The user create the next query:
    "+Select id_boss, boss_name from boss where boss_salary>5000+"
    I don't know how to do that with the current persistence and without create a Connection Method.

    The video tutorial is excellent but I have a problem because I'm working with Release 2 and when I try to do something like the video I had the next error:
    FachadaConsultaLocalImp cannot be cast to ApplicationModule
    the code to try to create a ViewObject is the next:
    DCDataControl dc = this.getBinding().findDataControl("FachadaConsultaLocal");
    String dataProvider=dc.getDataProvider().toString();
    ApplicationModule appModule = (ApplicationModule)dc.getDataProvider();
    Some idea?

  • How to execute these insert statements as a batch?

    Hello,
    I have these three insert sql statements which execute individually. I want to execute them as a batch:
    sql = "Insert into FirstTable (MessageId, MsgDate, MsgTitle) values (?, ?, ?)";
    insertStatement = connection.prepareStatement(sql);
    insertStatement.setInt(1, jmsgid);
    insertStatement.setString(2, jlogdate);
    insertStatement.setString(3, jmsgtitle);
    insertStatement.executeUpdate();
    sql = "Insert into SecondTable (MessageId, MsgDate, MsgTitle) values (?, ?, ?)";
    insertStatement = connection.prepareStatement(sql);
    insertStatement.setInt(1, jmsgid);
    insertStatement.setString(2, jlogdate);
    insertStatement.setString(3, jmsgtitle);
    insertStatement.executeUpdate();
    sql = "Insert into ThirdTable (MessageId, MsgDate, MsgTitle) values (?, ?, ?)";
    insertStatement = connection.prepareStatement(sql);
    insertStatement.setInt(1, jmsgid);
    insertStatement.setString(2, jlogdate);
    insertStatement.setString(3, jmsgtitle);
    insertStatement.executeUpdate();
    I tried the following method, but something is wrong. Can somebody help with executing these inserts as a batch?
    stmt = connection.createStatement(); // connection pool
    sql = "Insert into FirstTable (MessageId, MsgDate, MsgTitle) values (?, ?, ?)";
    insertStatement.setInt(1, jmsgid);
    insertStatement.setString(2, jlogdate);
    insertStatement.setString(3, jmsgtitle);
    stmt.addBatch(sql);
    sql = "Insert into SecondTable (MessageId, MsgDate, MsgTitle) values (?, ?, ?)";
    insertStatement.setInt(1, jmsgid);
    insertStatement.setString(2, jlogdate);
    insertStatement.setString(3, jmsgtitle);
    stmt.addBatch(sql);
    sql = "Insert into ThirdTable (MessageId, MsgDate, MsgTitle) values (?, ?, ?)";
    insertStatement.setInt(1, jmsgid);
    insertStatement.setString(2, jlogdate);
    insertStatement.setString(3, jmsgtitle);
    stmt.addBatch(sql);
    stmt.executeBatch();
    Thank you,
    Logan

    Errr I can't for the life of me understand why you thought that would work. I am bit concerned about how you assembled this code... did you copy and paste and hope for the best?
    It should be.....
    1) Get a preparedStatement using your sql. Do this step once.
    2) For each query you want to batch.... set each of the parameters and call addBatch. Call all this on the prepared statement.
    3) Then call executeBatch on the prepared statement.
    You do not need the other vanilla statement for anything.
    One important thing to note. When you batch parameters for batch prepared statement execution you can only (hopefully obviously) batch for the same SQL query. You can't do one insert and another update in the same query. It has to be all the same query.. just different parameters. This won't effect what you are doing in the above but sometimes it confuses people and they get into trouble later so I thought I would mention it now.

  • How to execute dynamically created procedure with out parameter

    hi guys ,
    friend i have to execute a procedure whose name is going to change dynamically and this procedure is have 2 out parameter . I need to capture value of these 2 output parameter, here i m giving my code also ..
    declare
    v_emp_id int :=100013 ;
    p_reg_off varchar(5) := 'R' ;
    p_user_id int := 6 ;
    v_status varchar(200);
    v_message varchar (200);
    v_Formula varchar(100);
    v_number int := 1 ;
    begin
    v_Formula := 'Call testsp_'||v_number||'('||v_emp_id||','''||p_reg_off||''','|| p_user_id || ',v_status,v_message)' ;
    DBMS_OUTPUT.PUT_LINE( v_Formula);
    execute immediate v_Formula;
    end ;
    and my procedure structure is like this
    CREATE OR REPLACE PROCEDURE testsp_1
    p_emp_id INT,
    p_reg_off CHAR,
    p_user_id INT,
    p_status OUT NOCOPY INT,
    p_message OUT NOCOPY VARCHAR2
    AS
    begin
    end ;
    please help me .....

    The Complete Syntax for Execute Immediate is ::
    EXECUTE IMMEDIATE dynamic_sql_string
    [INTO {define_variable,... | INTO record_name}]
    [USING
    IN bind_argument,...]
    [RETURN[ING] INTO
    bind_argument,...];
    i think now it won't be a problem! ;)

  • Execute dynamic sql  statement

    Hi all
    CREATE TABLE  XX_OFFICE_USER_IMP
        ID              NUMBER,
        OFFICE          VARCHAR2(10 BYTE),
        USER_NAME       VARCHAR2(10 BYTE),
        BANK_ACCOUNT_ID NUMBER,
        TRANSFERED      NUMBER
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (421,'0000','F0000',10029,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (422,'0000','F0000',10031,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (423,'0000','F0000',10033,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (424,'0000','F0000',10036,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (425,'0000','F0000',10037,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (426,'0000','F0000',10039,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (427,'0000','F0000',10041,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (428,'0000','F0000',10046,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (429,'0000','F0000',10048,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (430,'0000','F0000',10067,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (431,'0000','F0000',10072,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (432,'0000','F0000',10087,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (433,'0000','F0000',10092,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (434,'0000','F0000',10008,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (435,'0000','F0000',10012,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (436,'0000','F0000',10013,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (437,'0000','F0000',10014,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (438,'0000','F0000',10017,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (439,'0000','F0000',10019,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (440,'0000','F0000',10024,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (441,'0000','F0000',10025,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (442,'0000','F0000',10001,null);
    Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (443,'0000','F0000',10002,null);
    CREATE TABLE XXBG_CASIER_CASH
        CASHIER         VARCHAR2(32 BYTE),
        BANK_ACCOUNT_ID NUMBER(38,0)
    declare
    v_exe_grant varchar2(32767 char);
    begin
    for i in (select * from xx_office_user_imp where office = '0000') loop
      insert into XXBG_CASIER_CASH values (i.user_name, i.bank_account_id);
      v_exe_grant :=
                     'create user '  || i.user_name || ' identified by ' || i.user_name || ';'
                  || 'GRANT create session to ' || i.user_name || ';'
                  || 'GRANT select on apps.XXBG_CE_STATEMENT_HEADERS_CASH to ' || i.user_name || ';'
                  || 'GRANT SELECT ON APPS.FND_USER TO ' || i.user_name || ';'
                  || 'GRANT SELECT ON APPS.dFND_DESCR_FLEX_COL_USAGE_TL TO ' || i.user_name || ';'
                  || 'GRANT select on apps.fnd_descr_flex_column_usages to ' || i.user_name || ';'
                  || 'GRANT select on apps.fnd_descriptive_flexs to ' || i.user_name || ';'
                  || 'GRANT select on apps.fnd_descriptive_flexs_tl to ' || i.user_name || ';'
                  || 'GRANT select on ce.ce_statement_headers to ' || i.user_name || ';'
                  || 'GRANT SELECT ON APPS.fnd_doc_sequence_assignments TO ' || i.user_name || ';'
                  || 'GRANT SELECT ON CE.CE_STATEMENT_HEADERS_S TO ' || i.user_name || ';'
                  || 'GRANT EXECUTE ON APPS.XXBG_GET_NEXTVAL TO ' || i.user_name || ';'
                  || 'GRANT SELECT ON CE.CE_STATEMENT_LINES TO ' || i.user_name || ';'
                  || 'GRANT SELECT ON APPS.XXBG_CE_STATEMENT_LINES TO ' || i.user_name || ';'
                  || 'GRANT select on apps.CE_BANK_ACCOUNTS to ' || i.user_name || ';'
                  || 'GRANT SELECT ON APPS.CE_BANK_BRANCHES_V TO ' || i.user_name || ';'
                  || 'GRANT SELECT ON CE.XXBG_CASIER_CASH TO ' || i.user_name || ';'
                  || 'GRANT EXECUTE ON APPS.XXBG_ST TO ' || i.user_name || ';'
                  || 'GRANT select on ce.xxbg_ce_statement_lines_detail to ' || i.user_name || ';'
                  || 'GRANT SELECT ON APPS.ce_transaction_codes TO ' || i.user_name || ';'
                  || 'GRANT select on ce.ce_statement_lines_s to ' || i.user_name || ';'
                  || 'GRANT SELECT ON CE.XXBG_CE_STATEMENT_LINES_DET_SQ TO ' || i.user_name || ';'
                  || 'GRANT select on apps.xx_pko_lines to ' || i.user_name || ';'
                  || 'GRANT SELECT ON apps.xx_rko_lines TO ' || i.user_name || ';'
                  || 'GRANT select on apps.XX_INVOICE_RELATIONS_CASH to ' || i.user_name || ';'
                  || 'GRANT select on APPS.PO_VENDOR_SITES_ALL to ' || i.user_name || ';'
                  || 'GRANT select on ap.AP_INVOICE_LINES_INTERFACE_S to ' || i.user_name || ';'
                  || 'GRANT select on ap.AP_INVOICE_LINES_INTERFACE to ' || i.user_name || ';'
                  || 'GRANT select on APPS.ap_distribution_set_lines_all to ' || i.user_name || ';'
                  || 'GRANT SELECT ON APPS.AP_INVOICES_INTERFACE_S TO ' || i.user_name || ';'
                  || 'GRANT SELECT ON APPS.AP_INVOICES_INTERFACE TO ' || i.user_name || ';'
                  || 'GRANT SELECT ON APPS.AP_DISTRIBUTION_SETS_ALL  TO ' || i.user_name || ';'
                  || 'GRANT select on apps.ce_lookups  to ' || i.user_name || ';'
                  || 'GRANT select on ar.HZ_CUST_SITE_USES_ALL to ' || i.user_name || ';'
                  || 'GRANT select on ar.HZ_LOCATIONS to ' || i.user_name || ';'
                  || 'GRANT select on ar.HZ_PARTIES to ' || i.user_name || ';'
                  || 'GRANT select on ar.HZ_PARTY_SITES to ' || i.user_name || ';'
                  || 'GRANT SELECT ON AR.HZ_CUST_ACCT_SITES_ALL TO ' || i.user_name || ';'
                  || 'GRANT SELECT ON AR.HZ_CUST_ACCOUNTS TO ' || i.user_name || ';'
                  || 'GRANT SELECT ON APPS.XXBG_CLAIMS_V TO ' || i.user_name || ';'
                  || 'GRANT select on apps.xxbg_insis_agents_v to ' || i.user_name || ';'
                  || 'GRANT select on ce.xxbg_cash_doc_types to ' || i.user_name || ';'
                  || 'GRANT select on AP.AP_BANK_ACCOUNTS_ALL to ' || i.user_name || ';'
                  || 'GRANT SELECT ON AP.AP_BANK_BRANCHES TO ' || i.user_name || ';'
                  || 'GRANT SELECT ON APPS.FND_DESCR_FLEX_CONTEXTS TO ' || i.user_name || ';'
                  || 'GRANT SELECT ON APPS.FND_DESCR_FLEX_CONTEXTS_TL TO ' || i.user_name || ';'
                  || 'GRANT SELECT ON APPS.AP_SUPPLIERS to ' || i.user_name || ';'
                  || 'GRANT SELECT ON APPS.per_employees_x TO ' || i.user_name || ';'
                  || 'GRANT SELECT ON APPS.fnd_doc_seq_categories_ap_v TO ' || i.user_name || ';'
                  || 'GRANT SELECT ON APPS.AP_LC_INVOICE_TYPES_V to ' || i.user_name || ';'
                  || 'GRANT SELECT ON ce.xxbg_ce_statement_lines_sq to ' || i.user_name || ';'
                  || 'GRANT SELECT ON APPS.XXBG_STATEMENT_HEADERS_CASH to ' || i.user_name || ';'
                  || 'GRANT SELECT ON APPS.XXBG_INSIS_POLICY_V TO ' || i.user_name || ';'
                  || 'GRANT insert  ON ce.ce_statement_lines to ' || i.user_name || ';'
                  || 'GRANT INSERT  ON CE.XXBG_CE_STATEMENT_LINES_DETAIL TO ' || i.user_name || ';'
                  || 'GRANT INSERT ON APPS.AP_INVOICES_INTERFACE TO ' || i.user_name || ';'
                  || 'GRANT INSERT ON APPS.AP_INVOICE_LINES_INTERFACE TO ' || i.user_name || ';'
                  || 'GRANT INSERT ON APPS.XX_RKO_LINES TO ' || i.user_name || ';'
                  || 'GRANT INSERT ON APPS.XX_PKO_LINES TO ' || i.user_name || ';'
                  || 'GRANT delete on ce.xxbg_ce_statement_lines_detail to ' || i.user_name || ';'
                  || 'GRANT update on ce.XXBG_CE_STATEMENT_LINES_DETAIL to ' || i.user_name || ';'
                  || 'GRANT DELETE ON CE.CE_STATEMENT_LINES TO ' || i.user_name || ';'
                  || 'GRANT INSERT ON CE.CE_STATEMENT_HEADERS TO ' || i.user_name || ';'
                  || 'GRANT update on CE.CE_STATEMENT_HEADERS to ' || i.user_name || ';'
                  || 'GRANT update on ce.CE_STATEMENT_LINES to ' || i.user_name || ';'
                  || 'GRANT select on apps.XX_AGENTS_NO_V to ' || i.user_name || ';' ;
      execute immediate v_exe_grant;
    update xx_office_user_imp
      set transfered = 1
      where id = i.id
    v_exe_grant := '';
    end loop;
    end;
    /After execute the PL/SQL block i receive the error:
    Error report:
    ORA-00911: invalid character
    ORA-06512: at line 79
    00911. 00000 -  "invalid character"
    *Cause:    identifiers may not start with any ASCII character other than
               letters and numbers.  $#_ are also allowed after the first
               character.  Identifiers enclosed by doublequotes may contain
               any character other than a doublequote.  Alternative quotes
               (q'#...#') cannot use spaces, tabs, or carriage returns as
               delimiters.  For all other contexts, consult the SQL Language
               Reference Manual.
    *Action:Any ideas? I think i call execute immediate correctly.
    DB Version: 11g
    Unfortunately i cannot provide you with the sql of the other tables to create them.... Maybe you should try without all the grants... :)
    Thanks in advance,
    Bahchevanov.
    Edited by: bahchevanov on Oct 11, 2012 6:14 AM

    bahchevanov wrote:
    Any ideas? Sure. EXECUTE IMMEDIATE executes a single statment while you are trying to execute whole bunch. So use:
    execute immediate 'create user '  || i.user_name || ' identified by ' || i.user_name;
    execute immediate 'GRANT create session to ' || i.user_name;
    execute immediate 'GRANT select on apps.XXBG_CE_STATEMENT_HEADERS_CASH to ' || i.user_name;
    .SY.

Maybe you are looking for

  • The iPod cannot be updated. The required disc cannot be found

    I am gettin an annoying message that "the required disc cannot be found" and am not sure how to resolve. The iPod shuffle seems to updat with songs successfully. I also tries restoring for factory settings to perhaps start from scratch. I also tunred

  • External Hard Drive not connecting

    I had a WD passport external hard drive which I had hooked up to Time Machine. It has been working fine for over a year now. Just today I noticed the desktop Time Machine icon was not showing up as usual. I went to Time Machine and it says it cannot

  • Best way to implement application level persistant objects?

    I'm designing a J2EE application and want to create some objects that represent lookup tables in the database. I would like these to be static objects that get created either at application startup or the first time they are called and remain in appl

  • I need to select an HD format other than AVCHD

    I had a custom built machine to run all CS4 programs including Premiere Pro CS4 and Adobe Media encoder CS4. The only catch is that I built it to run mainly SD video. In June, I made a plunge purchasing a used HF10 which records excellent video. Howe

  • Mac version of Adobe IX Pro

    I just purchased the Mac version of Adobe IX Pro and can't get it to open on my mac. Any advice? I see the icon on the upper right corner of my screen but I can't get it to open.