Run SQL cmd from PL/SQL block

Is it possible to run SQL command Eg. "ALTER SESSION SET PLSQL_DEBUG=TRUE"
within PL/SQL block in a form
thax
shabar

Dear shabar!
Yes, it is!
BEGIN
--Here as some PL/SQL-Commands
--And here is the SQL-Command
EXECUTE IMMEDIATE 'ALTER SESSION SET PLSQL_DEBUG=TRUE';
--And here are some more PL/SQL-Commands
END;I hope this will help you along!
Yours sincerely
Florian W.

Similar Messages

  • Running sqlldr command from PL/SQL Block

    DECLARE
    BEGIN
    END;

    In SQL * plus we can run DOS commands using the following command
    HOST DIR
    HOST DIR/P
    But When we can't run the HOST command in PL/SQL Block..
    I have to Run sqlldr command from PL/SQL Block..
    i tried as follows
    DECLARE
    BEGIN
    EXECUTE IMMEDIATE ' host sqlldr control= bad= ';
    END;
    By
    BalaNagaRaju

  • Calling sql script from pl/sql block

    Hi
    I want to call a sql script from pl/sql block.
    like
    CREATE OR REPLACE procedure DataBaseExport(user_name in varchar2, pwd in varchar2)
    as
    begin
    execute immediate  '@ C:\Documents and Settings\umesh\emp.sql';
    end DataBaseExport;
    /

    Try something like this -
    CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
    import java.io.*;
    public class Host
         public static void executeCommand(String command)
         try {
                String[] finalCommand;
                   if (isWindows())
                        finalCommand = new String[4];
                        // Use the appropriate path for your windows version.
                        finalCommand[0] = "C:\\windows\\system32\\cmd.exe"; // Windows XP/2003
                        //finalCommand[0] = "C:\\winnt\\system32\\cmd.exe"; // Windows NT/2000
                        finalCommand[1] = "/y";
                        finalCommand[2] = "/c";
                        finalCommand[3] = command;
                   else
                        finalCommand = new String[3];
                        finalCommand[0] = "/bin/sh";
                        finalCommand[1] = "-c";
                        finalCommand[2] = command;
              final Process pr = Runtime.getRuntime().exec(finalCommand);
             pr.waitFor();
             new Thread(new Runnable()
                public void run()
                      BufferedReader br_in = null;
                   try
                        br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
                        String buff = null;
                        while ((buff = br_in.readLine()) != null)
                                  System.out.println("Process out :" + buff);
                               try {Thread.sleep(100); } catch(Exception e) {}
                        br_in.close();
                   catch (IOException ioe)
                        System.out.println("Exception caught printing process output.");
                        ioe.printStackTrace();
                 finally
                     try {
                              br_in.close();
                          } catch (Exception ex) {}
         ).start();
         new Thread(new Runnable()
           public void run()
                BufferedReader br_err = null;
                try
                   br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
                   String buff = null;
                   while ((buff = br_err.readLine()) != null)
                        System.out.println("Process err :" + buff);
                        try
                           Thread.sleep(100);
                         } catch(Exception e) {}
                   br_err.close();
               catch (IOException ioe)
                   System.out.println("Exception caught printing process error.");
                   ioe.printStackTrace();
              finally
                  try
                          br_err.close();
                   catch (Exception ex) {}
          ).start();
         catch (Exception ex)
                  System.out.println(ex.getLocalizedMessage());
      public static boolean isWindows()
              if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1)
              return true;
              else
              return false;
    CREATE OR REPLACE PROCEDURE Host_Command (p_command IN VARCHAR2)
    AS LANGUAGE JAVA
    NAME 'Host.executeCommand (java.lang.String)';
    --- THE PERMISSIONS ---
    call dbms_java.grant_permission('SYSTEM', 'SYS:java.io.FilePermission', '<<ALL FILES>>', 'read ,write, execute, delete');
    call dbms_java.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
    call dbms_java.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');And, finally,
    create or replace procedure call_sql_file(usr  in varchar2,
                                              pwd  in varchar2,
                                              host_str in varchar2)
    is
    begin
       host('sqlplus -s usr/pwd@host_str C:\UAX_Auto_Count.sql');
    exception
      when others then
        dbms_output.put_line(sqlerrm);
    end;Now, you can pass all the argument in order to execute that file.
    N.B.: Not Tested...
    Regards.
    Satyaki De.

  • Run multiple reports from PL/SQL

    I am planning to run reports from a PL/SQL batch program. My requirement is i need to generate multiple(around 50) reports with only a difference in one numeric parameter which will go from 1 to 50. I am planning to invoke the report inside a loop which goes from 1..50. I heard that i need to use a utl_http package which i havent used till now. Does somone has a sample code for running a report from pl/sql. i need it ASAP. Thanks in advance

    hi rejesh,
    we have an pl/sql API in reports to do exactly what you want to do.
    The Reports Event Driven Publishing API
    find the documentation including examples in the reports getting
    started on technet.
    http://otn.oracle.com/products/reports/htdocs/getstart/docs/a92102_01.pdf
    Chapter 11
    regards,
    christian

  • Running sql script from pl/sql

    Is there any standard way to run an external sql script from pl/sql
    I really appreciate any assistance.

    If you want, I did start writing a function reading and executing statements out of sql script with utl_file.
    can I issue this command in PL/SQL: EXECUTE IMMEDIATE '@filename.sql';
    the function could be extended for DDL, session setting, etc...
    Regards
    Laurent

  • Error -While create a connection to Microsoft SQL Sever from Oracle SQL Dev

    Dear All,
    While I am trying to create a connection to Microsoft SQL Sever from Oracle SQL Developer. The following error: "Cannot connect to Microsoft SQL Server on localhost" has been occurred.
    Can anyone please guide me to solve this..
    Thanks in advance,
    Rider

    Hi,
    Issue not supported in sharepoint on-premise team.
    In addition, as this issue is related to Powerview, I suggest you create a new thread on for Powerview forum, more experts will assist you.
    https://social.technet.microsoft.com/Forums/en-US/home?forum=powerview
    Best Regards,
    Lisa Chen
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Copying SQL Script from Oracle SQL Developer into Excel with formatting

    I need to copy a SQL Script into Excel in order to develop some VBA code. Is there any nice way that I can copy SQL Script from Oracle SQL Developer into Excel and retain its formatting? I am a stickler for having legible, readable SQL and like to have all my columns lined up and aliases lined up. When we used to use SQL Navigator, the tab formatting seemed to copy and paste just fine. Now that we have migrated to Oracle SQL Developer, the formatting seems to get all messed up.
    And suggestions are greatly appreciated and Thanks in advance for your review and am hopeful for an answer.
    Thanks.
    PSULionRP

    I suppose you want a real tabulator instead of spaces. You can configure this in the preferences (SQL Formatter - Oracle). You have to apply it then to your existing code (e.g. CTRL-F7), but new code should get it right from the start.
    Hope that helps,
    K.

  • How to call one .sql file from other .sql

    I am trying to call no of .sql files from one .sql file.
    But it gives me error in SQL*PLUS that unable to open file.
    Suggest me solution.
    Thanks
    Chanda

    Are the sql files in the current directories where sqlplus has been started ?
    If not, did you give the full path name for the called sql files when calling them from sqlplus ?
    Could you give us the complete sqlplus command that you use to call your files and the physical location of the called files with the exact error message ?

  • Call HOST cmd from PL/SQL Block

    Hi ,
    I'm trying to call the HOST command from stored procedure
    declare
    cmd varchar2(100):='c:\file.bat';
    begin
    execute immediate 'host('c:\file.bat')';
    dbms_output.put_line('Executed');
    end;
    but,It gives an error msg on execute immediate stmt.
    Plz resolve this problem.
    Rgrds,
    Anand

    You are confusing SQL*Plus's command (a client) with that of PL/SQL.
    Just as you cannot code C# commands, or Perl commands, or PHP commands in PL/SQL, you cannot code SQL*Plus commands in PL/SQL.
    SQL*Plus runs on your client platform. It has a couple of commands.
    PL/SQL is a server side programming language. This runs inside the Oracle server process servicing the client.
    This server process does not know your client language commands. Nor can this server process hack across the network, break into your computer, and access your local file called c:\file.bat.
    Yes, you can execute server o/s commands and execute server programs from PL/SQL via a Java stored procedure or via the EXTPROC interface. Refer to the sample code in [url http://forums.oracle.com/forums/thread.jspa?messageID=1439836#1439836]this thread on how to call server o/s commands and server programs.

  • How to call SQL script from PL/SQL block

    Hi All,
    I have a pl/sql block from which i need to call a *.sql script file.
    Please tell me that how can i do this?
    Thanks and Regards.

    > Though just for knowledge sake, would you please tell if there is a way
    to call a sql script from a pl/sql block.
    This question stems usually from a confusion about client-server and which is which in Oracle.
    SQL*Plus is a client. PL/SQL is a server side language. SQL is a server side language.
    When entering either one of these two languages in SQL*Plus (or TOAD, SQL-Developer, etc), the content is shipped to an Oracle server process, is parsed there, and is executed there.
    The Oracle server process servicing the client can accept a single SQL statement or PL/SQL block at a time.
    It cannot accept a block of SQL statements delimited with a semicolon. That is a client concept where the client will read each delimited statement and send that, one after the other (in synchronous call mode) to the Oracle server for execution.
    The Oracle server does not have a "script parser". It understands SQL. It understands PL/SQL. And that is what it expects from the client.
    Whether the client supports the SET command, the HOST command, SPOOL command, ability to run scripts, and so... have no bearing on what the server itself is capable of doing. The server does not care what feature set the client has. It is tasked with servicing the client via SQL and PL/SQL.
    It is not tasked to support or emulate client features like running SQL scripts.
    Nor confuse PL/SQL with the very limited command set of SQL*Plus. The two has nothing in common. And just as PL/SQL cannot understand C# or Delphi commands, it cannot understand SQL*Plus commands.

  • Error run a procedure from select sql

    Hi,
    I want run a procedure from a easy sql select.
    I have write this code to run this procedure, but response with a oracle error:
    select [procedure_name](:data1, :data2) as test from dual
    the oracle error is this:
    ORA-00904: "procedurename": invalid identifier
    how to resolve this problem?
    thanks
    Edited by: user10943416 on 12-mag-2010 3.12

    select [procedure_name](:data1, :data2) as test from dualAside from the error Oracle already reported, you can't execute a procedure from a select statement.
    You need to do this:
    SQL> exec procedure_name(:data1, :data2);

  • How to run OS commands from PL/SQL???

    Hi
    Is there any way to run OS commands(Windows Platform) from within PL/SQL?
    Thanks

    APC,
    I am working on Discoverer, having lots of BAs & Workbooks created & stored in Database. Now if i want to move all the workbooks from one place to another (like from development to test or production) i can use Command line interface of Disco to do this. But i don't see any option there to export all the workbooks, so i thought of writing a pl/sql to get all the workbook names from the EUL then fire export Command for each record(although not a good practice but its a one time work). This is the place where i need to run OS command from within PL/SQL. Although it doesn't seem possible now(as you all said) without external procedure.
    Lastly, you are right that "Oracle make databases not operating systems" but my first impression/comment about oracle is:
    "Oracle is far Bigger, Powerful, Complex, Vast and Interesting System than any other..." so i believe it can do/capable doing anything :-)
    thx Ashutosh,
    Host is definitely an option but i can't run it from pl/sql(that i am looking for)..

  • Running sql commands from a .sql file

    Hello , I have this problem. How do i execute sql commands found in a .sql file with jdbc. My RDBMS is mysql.

    You will have to open and parse the .sql file, connect to the database, and execute the statements. You can't simply tell JDBC to run your .sql file.
    Depending on the complexity of your .sql file this is easy or hard. If its a bunch of e.g. updates or deletes or something you may be able to get away with running it as a block. In Oracle for example, you can put "begin" and "end;" around a bunch of statements and run it all together. In that case your program would open the SQL file, read the text, put it inside a "begin" and "end;", and run it as a single SQL statement.
    If its a bunch of statements that must be run independently then you'll have to programatically split them up to run one at a time. If its a select and you want to e.g. print results to the screen, well, then it gets tougher...
    - Jemiah

  • Run OS command from Pl/SQL

    Is there any way to execute an OS command from pl/sql other than using dbms_pipe & pro*C combo. I have done this way before but it seems there is built-in oracle package which can do this in 8/8i.
    Also HOST command in forms will execute the OS coomand from the clinet. Is there any way to execute the OS command on the server from the forms clinet?
    thanks,
    Ravi.
    null

    Ravi,
    Can you send me an example how one can
    execute a this command from a PL/SQL
    program 'sed 3q /etc/passwd'.
    Please write to me at
    [email protected]
    thanks
    Pramod

  • SQL Injection from PL/SQL function.

    WE have some issues with a third party application which has vulnerabilities to SQL Injection, we have delivered a proof of concept to the developers demonstrating that it is possible to return additional (unrestricted) results to the front end, we have also found the following function in the back end. Assuming that its possible to call this function (which it is) and we can pass in whatever we want and that the user has exp_full_database and imp_full_database roles granted is there anything destructive possible with the following function?
    FUNCTION row_count (tab_name VARCHAR2) RETURN INTEGER AS
    rows INTEGER;
    BEGIN
    EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ' || tab_name INTO rows;
    RETURN rows;
    END;
    version 11.2.0.3, linux x86

    Simple example.
    SQL> --// table to hack in production - we are going to nuke it
    SQL> create table production_table1(
      2          some_data       number
      3  );
    Table created.
    SQL> --// production code typically executes with production rights (authid definer)
    SQL> create or replace function RowCount( tabName varchar2 ) return integer authid definer is
      2  --// code executes with the privs of the owner of the code
      3          cnt     integer;
      4  begin
      5          execute immediate 'SELECT COUNT(*) FROM ' || tabName into cnt;
      6          return( cnt );
      7  end;
      8  /
    Function created.
    SQL> --// expected use of production code
    SQL> var i number
    SQL> exec :i := RowCount( 'EMP' );
    PL/SQL procedure successfully completed.
    SQL> print i
             I
            14
    SQL>
    SQL> --// create the following in any schema that I, as hacker, have access to and the
    SQL> --// right to create a procedure - and using "access/security escalation", I'm going
    SQL> --// to get production code to run my code with production rights
    SQL>
    SQL> create or replace function InjectCode return integer authid current_user is
      2  --// code executes with the privs of the caller of the code
      3          pragma autonomous_transaction;
      4  begin
      5          execute immediate 'drop table PRODUCTION_TABLE1 purge';
      6          return( 0 );
      7  end;
      8  /
    Function created.
    SQL>
    SQL> --// production table is there
    SQL> select object_type, object_name from user_objects where object_name = 'PRODUCTION_TABLE1';
    OBJECT_TYPE                    OBJECT_NAME
    TABLE                          PRODUCTION_TABLE1
    SQL>
    SQL> --// inject my code into production code
    SQL> exec :i := RowCount( 'EMP where InjectCode() = 0' );
    PL/SQL procedure successfully completed.
    SQL> print :i
             I
            14
    SQL> --// production table is nuked
    SQL> select object_type, object_name from user_objects where object_name = 'PRODUCTION_TABLE1';
    no rows selected
    SQL>

Maybe you are looking for

  • Problem in GUI status

    hi folks , i have created the GUI status for the program .. when i go on the out put screen i am not able to go back or cancel or exit , though i have created the GUI status and activated it as well . my program is designed to display the user action

  • Roaming Profile are not stored completely

    Hello NG In our environment we work with NWClient 2 SP1 IR9, ZCM11 SP1a and Roaming profile is activated by a ZCM policy. Now we have the problem, that when a user logout from the workstation, the roaming profile is not stored completely to the home

  • ECC - MQ - XI1 - XI2 - AS2 Connectivity

    Hi , We have a requirement of sending an XML file from ECC unix box to XI via MQ-JMS communication and then from XI to another XI system and finally to third party system via AS2 protocol. This is a simple file transfer interface from ECC to the thir

  • How do I get Finder to act like Explorer

    Hi there, I converted to Mac about 3 years ago and I have had this "thing" that frustrates me no end and I have done nothing about it. How can I get Finder to show me the Folder (Collapsed / Closed) and sorted by Folder / FileName alphabetically i.e.

  • Unit test for object types

    In the current version (2.1.0.63) I can perform only unit test for packages, function and procedures. But we use a lot of object types in the database and would like to test them. Is there any support for object types scheduled?