How to run multiple sql statements

Hi all

I wonder if I can run multiple sql statements in one shot with > >, immediate run

for example:

I set the variable as X: = sql statement
Y: = sql statement
z: = sql statement

can I execute immediate (X, Y, Z);

If yes how? and if not what other possible

Thank you

Beginning with the codes of Ganesh

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
   --<>
   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( <> );
     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( <> );
     END;
   END LOOP;
END;

But I agree with the comment that others have grown up is not really wise to create and drop a database like that link.

Justin

Tags: Database

Similar Questions

  • How to run grid sql statements

    Hello

    I would like to run some of the grid control sql statements as tablespace freespace check.

    Grid options could there be to execute the sql statement?

    If so, how to set up the output of the sql for E-mail

    Please I need your suggestion to proceed.

    Version of the grid: 10.2.0.5.0
    Platform: Sun

    Thank you.

    Hello

    no need to run the sql statement of the grid, instead of that you can configure the threshold values.

    for example, if your tablespace capacity 85% complete and then he will send you the email alert that you configured in notifications.

    you will find on the home page - bottom of the page - > manage settings...

    check http://download.oracle.com/docs/cd/B19306_01/server.102/b14196/montune001.htm#CACCIHAB

    http://download.Oracle.com/docs/CD/B19306_01/EM.102/b40002/notification.htm#sthref995

    Thank you

  • How to run a SQL statement to use a specific implementation plan

    Hi all

    I have a SQL that has recently been run badly. I tried the Advisor tuning SQL for the given SQL query and it gives the following information:

    GENERAL INFORMATION SECTION

    -------------------------------------------------------------------------------

    Name of the task of tuning: 2q94zb7djr2xn

    The owner task of tuning: LMDBPROD

    Type of work: single SQL statement

    County of execution: 2

    The current run: EXEC_8869

    Type of execution: TUNE SQL

    Scope: COMPLETE

    Time Limit (seconds): 60

    Status: COMPLETED

    Started on the: 03/02/2014-20:43:39

    To the: 03/02/2014 20:44:25

    -------------------------------------------------------------------------------

    Name of the schema: LMDBPROD

    SQL ID: 2q94zb7djr2xn

    SQL text: SELECT NPCOMMON. FGET_ACTION_CODE (ORDNUM) ACTIONCODE, STATUS,

    SUMA COUNT (*) FROM SORDER, WHERE HEADORDNUM IS NOT NULL AND

    NPCOMMON. FGET_PRODUCTOFFER4ORDER (ORDNUM) IN (SELECT ID FROM)

    PRODUCTOFFER WHERE PPSPECIFICATION_ID IN (SELECT ID FROM)

    PPSPECIFICATION WHERE PCLASS_CODE IN (SELECT PCLASS_CODE FROM)

    ARUSERGROUP WHERE CODE IN (SELECT ARUSERGROUP_CODE FROM)

    ARUSER_ARUSERGROUP WHERE ARUSER_USERNAME =: B1 AND STATUS = '1')

    AND STATUS = '1'))) GROUP BY NPCOMMON. FGET_ACTION_CODE (ORDNUM),

    STATUS

    -------------------------------------------------------------------------------

    RESULTS SECTION (1 result)

    -------------------------------------------------------------------------------

    1-alternative Plan conclusion

    ---------------------------

    Some implementation plans alternative for this statement was found by searching

    performance data in real-time and historical of the system.

    The following table lists these plans sorted by their average time.

    See "SECTION of ALTERNATIVE PLANS" section for detailed information on each

    plan.

    plan ID hash last visit elapsed note of origin (s)

    -- ---------- -------------------- ------------ --------------- ----------------

    1 617797893 2013-07-11/07: 45:20 9.555 no reproducible STS

    2 1311086720 2014-01-31/04: 00:44 19.569 AWR

    3 1226863820 2014-01-31/18: 00:24 AWR 21.158

    4 1359606848 2014-02-03/16: 00:34 21.492 AWR original plan

    The plan with hash 617797893 seems the most efficient one and is based on some specific SQL Tuning Set I ran on this time. But the note says that the plan is not reproducible. Is there anyway how can I force the SQL statement to execute the plan? The database version is Standard Edition 11.2.0.1.0

    Best regards

    Rodriguez

    Hello

    I think you can use this

    http://rnm1978.WordPress.com/2011/06/28/Oracle-11g-how-to-force-a-sql_id-to-use-a-plan_hash_value-using-SQL-baselines/

    before 11 g, we used to create an outline stored for this.

    concerning

  • How to run an SQL statement

    Dear friends,

    As I recently started working with SQL more, I realized that my opinion on this has changed.
    select first_name, last_name
    from personal_details
    and
    select first_name, last_name
    from personal_details, education_details
    and
    select first_name, last_name
    from personal_details a , education_details b
    where a.id =b.id
    and
    select first_name, last_name
    from personal_details a , education_details b
    where b.id =a.id
    is it different? or make the same result?

    Won't return the same result.

    Just started to wonder, how it actually works of in.

    Can anyone shine some light on this issue?

    Thank you.

    Benard

    >
    ...

    By default, I think that oracle starts executing the last where condition and so queries can take different time, depending on which is the primary key, or if any column index created on this subject.

    This statement is almost always wrong. Oracle evaluates what query condition is the best to run first. This is done by the optimizer cost based using statistical information about the tables, columns and the indexec on these columns. There had been questions back in the day Oracle 7 and the RBO (rule based optimizer) where the order in the clause from and where clause was important. But in general, do not care anymore to this topic.

  • How to run wfstatus.sql for i-expenses

    How to run wfstatus.sql i-expenses in EBS 11i.

    Select this check box, hope it helps.

    How to find and solve the reports on Internet expenditures within workflow [ID 185004.1]

    How wfstatus.sql to run on a statement of expenses Internet [134895.1 ID]

  • How to run a SQL string to a procedure of forms?

    Hello

    first the background. I have a Varchar2 column in a Table with a SQL string.
    Now I want to read this chain in forms and run the SQL statement - but I don't know how.

    This is the SQL string:
    Select the country from p_1 from countries where country_nr = p_2

    P_1 and p_2 are Variables in the procedure of forms.

    Most people forget that groups Records are excellent tools for dynamic queries like this. Search for Populate_group_with_query.

    Only you need to change your sql, it is not in the sentence, like this:

    Select the country as P_1
    country
    where country_nr = p_2
    and p_3 = p_3
    and p_4 = p_4

    Select name as P_1
    of the customer
    where customer_nr = p_2
    and country_nr = p_3
    and p_4 = p_4

    Your rec group would have a single column, P_1, where the data would be accessible after the query. Get_group_char_cell allows you to retrieve the value of P_1.  I don't know, but you should not "AS P_1" expression in the select, as long as you have created the record group initially with a specific column name.

    The only thing that is not clear, however, is your use of variables in the where clause. You can either hardcode the literal values in the SQL string, like this:

    'where country_nr = ''123'' and...'

    Note as you build your text string SQL, you use two apostrophes instead of one, given that pl/sql uses the apostrophe of beginning and end of the string.

    Or alternatively, you can use bind variables for your where the variables paragraph as follows:

    where customer_nr = :Parameter.var_2
    and country_nr = :Parameter.var_3

    Then, you can move a value in the: parameter values before completing the Group rec. You can use elements in a block of control rather than the settings, too.

    Here is an example of using dynamic query in a record group: Re: dynamic query

  • Excuting multiple sql statements

    Hi to everyone.



    I am quite new to Oracle, even though I have a great experience with SQL and MySQL commands. I am facing a problem that I guess it's really Basic.



    I got a dump of an Oracle database in a format .sql. I mean that the schema and data are built thanks to a large number of sql statements. In particular the schema is done by many 'create a table... '. «While the data are built through «insert into...» ». My need is to import these databases into a new Oracle Oracle 10 g XE database.



    I installed it on a Debian system, and I can properly run a single SQL command both through the web interface http://localhost: 8080/apex and logging as user oracle through the name of sqlplus user/passwd command.



    My problem is that the data is spread over approximately 12000 SQL «INSERT INTO...» "so all one by one run might be a bit boring :-)



    < u > so I ask if there is a way to tell Oracle to execute multiple SQL statements he read a file (like MySQL for example). < /u >



    I'm planning to write a script to do if there is no better way. I know there's no way to dump databases Oracle, but I can change the .sql format since it's the only one I had.

    in SQL * Plus you can run a SQL file with the start command or the abridged version: @

    SQL> start filename.sql
    
    or 
    
    SQL> @filename.sql
    
  • How to run multiple parallel sql scripts?

    I try to execute multiple sql scripts parallel to the short run of the process via sqlplus. Are there opportunities to do? LINUX ORACLE 5. XX

    I do it too via Scheduler, but now I need to do this via sqlplus or shell + sqlplus?

    How do I start using shell script several xterminals and ech session begins all the sql scripts?

    nohup./SQL1.sh &

    nohup./sql2.sh &

    nohup./SQL3.sh &

    The '&' causes the script1.sh to run in the background so that the command prompt is returned immediately.  This means that sql2.sh can start immediately and at the same time as sql1.sh.  It doesn't have to wait for sql1.sh.   This assumes that there are no dependencies between scripts!  This meets your need to run scripts in parallel.

    The nohup untie your shell script.  So, even if you disconnect, the script continues to run.  Without the nohup, if you were to close your session before the end of the scripts running, they would get fired.

    Hemant K Collette

  • How to execute a SQL statement that is stored within a SQL Table

    Hello

    If someone please help me with the following problem I would be eternally grateful

    I have a SQL statement that is stored inside a certain SQL table, I want to use this SQL statement inside my PL/SQL procedure.

    Thought a simple solution was to get the SQL statement in a table, and then run it, but how could I do so exactly with PL/SQL? I only started to play with PL/SQL in the last days.

    Thanks in advance!

    This is what it looks like more or less:

    Display result for:

    ---------------------

    SELECT TRIM (OBJ_VALU_TXT)

    OF OBJ_VALU_DOC

    WHERE TYPE_OBJET = 'FLD '.

    AND OBJECT_CODE = 15443

    AND OBJ_VALU_CD = 'CAB '.

    ORDER BYDOC_SEQ_NO

    00001

    ------------------------------------------------------------------

    SELECT

    VALUE (MAX (RECEIPT_NO) + 1,: OUT-COMP-FACTOR)

    THE FRONT DESK

    WHERE (RECEIPT_NO BETWEEN

    (: OUT-COMP-FACTOR AND: OUT TO A NUMBER) OR

    (RECEIPT_NO >: OUT-COMP-FACTOR AND)

    (: OUT-TO-NUMBER = 0)

    Here's a demo of your condition.

    create table t (col1 varchar2 (200));

    table created

    insert into values t ('select * from double ');

    1 row inserted

    declare
    v_col varchar2 (200);
    v_val varchar2 (200);
    Start

    Select col1 in t v_col;

    run immediately v_col in v_val;
    dbms_output.put_line (v_val);
    end;

    -----
    X

    Use in the clause, you can use as many variables as needed. But the basic approach remains the same.

    But storage in DB SQL is not an efficient design.

    Ishan

  • How to execute the sql statement in the file beats?

    I want to execute after the statement
    C:\ > sqlplus/nolog
    SQL > conn scott/tiger
    SQL > select * from tab;

    I know I can achieve it following test.bat and testdb.sql file
    test.bat is:
    sqlplus/nolog @testdb.sql

    TestDB.SQL is:
    Conn scott/tiger
    Select * from tab;

    Now I don't want to use the sql file, I want only use bat file, as follows:
    test.bat is:
    sqlplus/nolog
    Conn scott/tiger
    Select * from tab;

    When I run test.bat, I find only one sqlplus /nolog execute statement, do not execute other statements.
    (1) I want to know if there is a method to run the SQL file by fighting without a sql file? How to make it happen?
    (2) if I call the sql file, how to hide the password of user? Because I don't want other people to know scott password, if I use conn scott/tiger in testdb.sql, other person can see testdb.sql and the password. Is there a good way to avoid?

    Thank you!

    It works a bit different in Windows. Create a file is like this:

    (
      echo conn scott/tiger@orcl
      echo spool c:\temp\list.txt
      echo select sysdate from dual;
      echo spool off
      echo exit
    ) | sqlplus -s -l /nolog
    
  • Try to run a SQL statement through the window of OEM 12 c run SQL.  Statement fails

    All,

    I have a 11g database.  When it is initially installed, I installed it in $ORACLE_BASE = / orabin/app/oracle/product and $ORACLE_HOME = $ORACLE_BASE/11gDB_R2.  This is the version 11.2.0.1 to give birth to 11.2.0.3.

    Recently, I installed 11.2.0.4 in $ORACLE_BASE/11.2.0.4.  Then, I upgraded my database at 11.2.0.4.  Everything works fine.

    All my scripts on the linux host logon changed to point my environment at $ORACLE_BASE/11.2.0.4 House and my $PATH when I connect to the linux host is: /orabin/app/oracle/product/11.2.0.4/bin:/orabin/app/oracle/product/11.2.0.4/OPatch:/sbin:/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/oracle/bin

    On my OEM Console, the database appears as 11.2.0.4 and me can manage very well.

    However, when I try to use the window of the OEM Console to execute SQL to execute any type of SQL statement, it fails.

    The failure error is:

    Could not launch/orabin/app/oracle/product/11gDB_R2/bin/sqlplus-s/nolog: no such file or directory

    It would be a mistake since the 11gDB_R2 directory tree (the 11.2.0.3 software) has been removed from the host, now that the database is set to level and working as 11.2.0.4.

    I wonder if somewhere in the OEM software, there is always a pointer to the old ORACLE_HOME?  I can't find anything in the .bashrc or other shell scripts that are executed when a Shell session on the host computer which were still the reference to the old directory of 11gDB_R2 so I'm a bit puzzled.

    I have 8 guests, and all have been improved in the same way at 11.2.0.4.  For some databases, the OEM window run SQL is executing the SQL code.

    Someone has some ideas on this?

    Go to the Configuration of the analysis of the database (when you set the password) and update of the Oracle home.   Also do this for all targets listener on this host as well.

  • By running multiple SQL instructions.

    Hi I'm new to Oracle SQL. I'm doing which follows which implies the execution of several sql statements, but is there a way I can run all on go:

    Step 1 - create the Table BOXES_1 as (select... from x, y, z, conditions)
    Step 2 - create the BOXES_2 Table in (select [columns] of BOXES_1, [[other tables])
    Step 3 - Select [columns] of BOXES_2, [another table] - 'it's the final report, I need

    When I run the present for the second time, I would like to remove the BOXES_01 tables & BOXES_02 before re - create it again using the steps above.

    Could you please help, this will help me overcome a big hurdle. Thanks in advance.

    Naushad.

    Naushad Naleer wrote:
    Hi I'm new to Oracle SQL. I'm doing which follows which implies the execution of several sql statements, but is there a way I can run all on go:

    Step 1 - create the Table BOXES_1 as (select... from x, y, z, conditions)
    Step 2 - create the BOXES_2 Table in (select [columns] of BOXES_1, [[other tables])
    Step 3 - Select [columns] of BOXES_2, [another table] - 'it's the final report, I need

    When I run the present for the second time, I would like to remove the BOXES_01 tables & BOXES_02 before re - create it again using the steps above.

    Could you please help, this will help me overcome a big hurdle. Thanks in advance.

    Naushad.

    No no no no no... it is not what you want to do at all.

    Oracle is not like some other RDBMS, you do not need (or want) to create tables like this (process).

    Just write a single SQL query for all your tables join... no intermediary not paintings at all. The process as you have described it is enough to add exorbitant levels of overhead and completely erase your ability to create a scalable solution.

  • How to concatenate two sql statements?

    Hello

    How can I combine the following two sql statements so that the result of a line of the first statement appears before the lines of my second sql statement. The reason I need it is to order the lines correctly.

    Select the username, id
    some abusers
    where id = 0

    Select the username, id
    some abusers
    where id! = 0
    order by username

    Thank you
    j

    You should ask in the forum of the Apex:
    Oracle Application Express (APEX)

    Nicolas.

  • How to execute the SQL statement in the Application Module

    Hi people
    I´d would like to know how I can execute a SQL statement like "remove user" in the Module to request... prepareSession method...
    I m using Jdev 10 with ADF Faces
    Thank you

    This is possible, but you should think twice about it.
    If this can be done with an EO/VO do in this way.
    If you can't do it with an EO/VO you can yourself the DB operation (ApplicationModule.getDBTransaction ()) and use a call of createStatement (...) do what you want.

    Timo

  • How to run multiple copies of distilling on the same machine?

    What version of Adobe PDF Converter do I need to run multiple copies of distilling on the same machine?

    I see that Distiller Server is EOL so what should I use to accomplish the same task.

    Hi mmaraffi,

    You will not be able to run multiple copies of Distiller, because this is a violation of the EULA.

    Let me know the version of Acrobat is installed on your computer?

    Kind regards

    Nicos

Maybe you are looking for

  • TextSize ajust to let her enter a label

    Hello! I have a label, height 400px and width 600px and I want a text (random length Word) scale to fit exactly to the width of 600px. I want to avoid that the text gets blurred, but shorter words can be displayed words compared to adults. Any ideas?

  • Resolution max M6800?

    Hello I would like to know the maximum resolution supported by AMD over-pants m6100 Firegl V. I tried to find more information via google, but nothing. I have connected my M6800 of precision to a 4K monitor (ASUS PB287Q) and I can choose only 3840 x

  • How can I include jquery.js in my application

    Hello How can I include the JQuery.js (it is a local resource) in my application that I can use the appeal of $.ajax? I have to add something to my config.xml file or simply include it as usual in my .html files? Thank you

  • BlackBerry Smartphones Blackberry Curve 8900 flashing LED

    Hello I understand that a red LED means a new message, Voice Mail etc and I know as a yellow/green, low battery LED. I also understand that a green means that you have coverage. But I don't know if I should turn my green LED coverage indicator. Someo

  • Cannot access the DCUI

    HelloI'm having a problem. I recently bought a Dell PowerEdge T630 for my lab at home that came with a picture of Dell vSphere 5.5 U2 on SD cards. I booted up and had a keyboard and a USB mouse attached to him like the console of the iDRAC. As soon a