Need to execute SQL PLUS commands from C# code

Hello all,
This is my first question here and hopefully I will get my solution :)
Right now we are doing 3 tasks manually
1) Clearing everything from a DB.
We use sql plus and execute this :
RAMNIVAS_CI/RAMNIVAS_CI@orclwex3
set pages 0
set lines 80
spool c:\delete_objects_CI
select 'drop '||object_type||' '||object_name||';'
from user_objects;
spool off
start c:\delete_objects_CI.lst
purge recyclebin;
set pages 100
select count(*) from user_objects;
RAMNIVAS_CI/RAMNIVAS_CI@orclwex3 are the username and pwd which gets input when we paste entire thing in sql plus
2) Then we restore that DB again using sql plus to do it using the command:
imp file=CL.DMP log=CL.log buffer=1000000 fromuser=RAMNIVAS_CL touser=RAMNIVAS_CL statistics=none grants=n commit=y
3)Execute sql scripts on it using sql developer. (This is not hard I guess coz I know we can use oracle client)
4) Take backup using this command:
exp RAMNIVAS_CI/RAMNIVAS_CI@ORCLWEX3 file=CI.dmp log=CI.log direct=y compress=y buffer=1000000 grants=n statistics=none
Is there anything I cna do to execute SQL PLUS commands using c#?

Hi,
You can execute OS commands via the SHELL function provided in .NET. See the MSDN for more info.
Some of the things you can do directly from .NET via ODP and PLSQL, some not.
1) Dropping the user objects can be done via a plsql procedure where you open a cursor for "select 'drop '||object_type||' '||object_name||';' ..." and then use EXECUTE IMMEDIATE to execute the resulting commands. You can invoke the procedure via ODP.
2) IMP is an exe, not a sqlplus command, so you're not actually using sqlplus there. You can still use the SHELL command though to invoke that.
3) Executing SQL Scripts via ODP.NET is not something you can do very easily. If you search the threads here you should be able to find some solutions others have come up with to parse the file and execute the statements one by one, but there's nothing built in to ODP to execute a script file.
You may want to just shell out to sqlplus user/pwd@db @scriptfile.sql but you may have issues trying to track down errors if any occurred, as I'm not sure where they go in that case.
4) just as with IMP, EXP is an exe, so you could shell out to that.
Corrections/comments welcome.
Greg

Similar Messages

  • How to issue a SQL*Plus command from PL/SQL program?

    Thanks.

    You can't issue a SQL*PLus command from a PL/SQL program. If you can tell us more about what you are trying to do, perhaps we can offer a substitute.

  • Executing Sql* plus commands

    Hi
    Can we execute SQL *plus commands using JDBC OCI Driver. If so What is the procedure to execute and Which parameters to be set
    With Regards
    Vara Prasad

    AFAIK: no, you can't. SQL*plus is kind of a shell (the worst one I've seen so far), so via JDBC (both OCI and thin), you lack the interpreter.

  • Running a SQL*Plus command from Java

    I have a requirement to run SQL* Plus commands from Java. The results as they would appear in SQL*Plus window or spool file should be captured and stored in a table.
    For example,
    SQL> select * from dual;
    D
    X
    1 row selected;
    SQL>
    All the lines above should be stored for later use.
    Could any one give pointers?
    Thanks,
    Ravi

    <p>
    Hi,
    </p>
    <p>
    <strong><font face="Courier New">
    public class RuntimeExecApp {
     public static void main(String args[]) throws IOException
      Runtime r = Runtime.getRuntime();
      r.exec(&quot;C:\\Oracle\\sqlplus.exe&quot;);
    }</font></strong>
    </p>
    <p>
    Kuba 
    </p>
    Message was edited by:
    KUBA

  • Execute SQL*PLUS script from VB6?

    I'm using VB6 to connect to oracle 10 with oracle client 8i, I can establish the connection without any problems.
    If I run a SQL statement from VB it works prefect, but when I try to run a SQL Plus script from VB I get error ORA-00900, "invalid SQL statement". Everything works fine in oracle SQLPLUS.
    Is there anything I have missed about running SQL*PLUS script from VB6? Is'nt it the same as a SQL statement?

    Thanks for you answer Justin,
    This is a short variant of SQL*Plus I wanna execute from VB and transfer the result into a listview in VB.
    If this is possible from VB, can you show me how I should do?
    COLUMN customer_1 NEW_VALUE customer_1 NOPRINT
    COLUMN customer_2 NEW_VALUE customer_2 NOPRINT
    SELECT customer customer_1
      FROM (
            SELECT customer,
                   ROW_NUMBER() OVER(PARTITION BY customer ORDER BY CustomerTotalSales DESC) CustomerTotalSalesRank
              FROM (
                    SELECT  customer,
                            SUM(SalesQty) OVER(PARTITION BY customer) CustomerTotalSales
                      FROM  CustTable
                      WHERE year_month BETWEEN 200709 AND 200801
    WHERE CustomerTotalSalesRank = 1
      AND ROWNUM = 1
    SELECT customer customer_2
      FROM (
            SELECT customer,
                   ROW_NUMBER() OVER(PARTITION BY customer ORDER BY CustomerTotalSales DESC) CustomerTotalSalesRank
              FROM (
                    SELECT  customer,
                            SUM(SalesQty) OVER(PARTITION BY customer) CustomerTotalSales
                      FROM  CustTable
                      WHERE year_month BETWEEN 200709 AND 200801
    WHERE CustomerTotalSalesRank = 2
      AND ROWNUM = 1
    SET VERIFY OFF
    SELECT  year_month,
            SUM(
                CASE CustomerTotalSalesRank
                  WHEN 1
                    THEN
                      SalesQty
                    ELSE
                      NULL;
                END
               ) "&customer_1",
            SUM(
                CASE CustomerTotalSalesRank
                  WHEN 2
                    THEN
                      SalesQty
                    ELSE
                      NULL;
                END
               ) "&customer_2"
    FROM  (
             SELECT  year_month,
                     SalesQty,
                     ROW_NUMBER() OVER(PARTITION BY customer ORDER BY CustomerTotalSales DESC) CustomerTotalSalesRank
               FROM  (
                      SELECT  customer,
                              year_month,
                              SalesQty,
                              SUM(SalesQty) OVER(PARTITION BY customer) CustomerTotalSales
                        FROM  CustTable
                        WHERE year_month BETWEEN 200709 AND 200801
      WHERE CustomerTotalSalesRank <= 10
      GROUP BY year_month
      ORDER BY year_month
      /

  • Executing sqlplus / sqlldr command from java code

    hi,
    I have my application on one server(tomcat) and oracle server is installed on other server. i.e. Both are on different machine.
    Now i want to run sqlplus / sqlldr command on oracle server from my java code.
    Again my script for lodder command is in temp of tomcat.
    How to do that?
    Thanks,

    Hi,
    I am using JDBC to executed queries...but i need to run sqlplus command to run script if some condition is satisfied and same for sqllodder to load large record like 500000. This code is in the thread and is working fine for same machine. Need to execute it on another machine where oracle is installed.
    From command prompt i am able to run sqlplus on Oracle server. Same command I am not able to run from the code. I have shared bin direcotry of Oracle from server.
    Let me know if any query
    Regards,
    Edited by: Sun_Nut on Dec 16, 2007 9:53 PM

  • .......Embedding  SQL PLUS commands inside PL/SQL.....

    hai every body,
    I have a doubt regarding sql plus commands and PL/SQL..I am using Oracle 10g..I have created 1 procedure for deletion/updation of transactions..and the number of effected rows I just displayed with using " *dbms_output.put_line* (SQL%ROWCOUNT)"..hence before executing the procedure the sqlPlus command "*SET SERVEROUTPUT ON*" should turn on..at most times it is forget to turn on and output becomes vague..
    hence my question is "*Is there any package or any thing to execute sql plus commands(here it is SET SERVER OUTPUT ON) through PL/SQL statements???*"
    with thanks,
    jp@valapad

    jp@valapad wrote:
    I have a doubt regarding sql plus commands and PL/SQL..
    Easy PL/SQL supports PL/SQL commands and embedded SQL, which are found in the PL/SQL and SQL reference manuals.
    http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/toc.htm
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/toc.htm
    It does not support the commands of other applications or languages such as SQL*Plus, Unix or COBOL for example.
    I am using Oracle 10g..I have created 1 procedure for deletion/updation of transactions..and the number of effected rows I just displayed with using " *dbms_output.put_line* (SQL%ROWCOUNT)"..hence before executing the procedure the sqlPlus command "*SET SERVEROUTPUT ON*" should turn on..at most times it is forget to turn on and output becomes vague..You can set serveroutput on in your log in script for SQL*Plus if you keep forgetting.
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10823/ch_two.htm#sthref94
    hence my question is "*Is there any package or any thing to execute sql plus commands(here it is SET SERVER OUTPUT ON) through PL/SQL statements???*"No.

  • How to: execute operating system commands from PL/SQL

    System: IBM pSeries AIX
    Oracle: 11g Enterprise
    Is there a quick way to execute operating system commands from PL/SQL?
    Without creating a JAVA class....
    I need to execute a Loader script.
    I want to do this from within PL/SQL.
    I need to to do 4 things.
    Three require SQL scripts.
    The fourth is SQL*Loader.
    The usual way is with a UNIX script calling 3 SQL scripts and one Loader control file.
    Is there way to do all this from within ONE PL/SQL SCRIPT ??
    Just let me know.

    Is there a quick way to execute operating system commands from PL/SQL?
    NO
    Without creating a JAVA class....
    I need to execute a Loader script.
    I want to do this from within PL/SQL.
    WHY ON EARTH, such action will create a new connection and become a resource hog?
    I need to to do 4 things.
    Three require SQL scripts.
    The fourth is SQL*Loader.
    The usual way is with a UNIX script calling 3 SQL scripts and one Loader control file.
    Which is perfect for the purpose.
    Is there way to do all this from within ONE PL/SQL SCRIPT ??
    Just let me know.
    NO, there is NOT. Nor should there be. Why create unstable ineffcient Mickey Mouse systems, glued together by hacking?
    Sybrand Bakker
    Senior Oracle DBA

  • Fire OMB Plus commands from PL/SQL

    Hi all,
    does anyone know if it is possible to fire OMB Plus commands from PL/SQL procedures?
    I can imagine that there might be a PL/SQL package in the repository owner schema that accepts OMB Plus commands as strings...or something similar...
    Thanks,
    Elio

    Hi Elio
    I don't know about any existing package that could do that.
    What I'd suggest is to build a stored procedure/function/package that could do that. Or even, execute OMB Scripts in the host from a pl/sql program.
    Good luck.
    Regards,
    Marcos

  • How to find GUI SQL*Plus command tool in Oracle 8i (version 8.1.7)

    I had installed Oracel 8i Enterprise Edition (version 8.1.7) on my server machine (Windows NT 4.0), I'd like to use Oracle Navigator (GUI SQL*PLUS command tool), but I can not find it from the menu. I know Oracle Navigator is available in Oracle 7. Can anyone tell me where and how to use GUI SQL*PLUS command tool in Oracle 8i Enterprise Edition (version 8.1.7) ?
    thanks a lot.
    David Zhu

    Hi
    Oracle Navigator is part of Personal Oracle7 and Oracle Lite. I don't know is it available in 8i Personal Edition but I am sure that it is not part of Standard and Enterprise Edition.
    Regards
    null

  • Execute Unix Mail Command from Store Procedure

    Hi Colleagues!
    I designed a store procedure that Monitoring some Critical tables in my Oracle 8.0.6.1.0 Database But I need to send some Emails from the Store Procedures to Information System Staff when the amount of rows increase too much. I read about UTL_SMTP but my database version is too old to run this package. Also I have the option of Maildemo8i that execute MS Oulook from a Client System But I looking to Send it from my Database(OS HPUX). So please take a look of this issue and I will appreciate any help.
    Your Friend.
    Emmanuel Carrillo Trejos.
    LNB, Republic of Panama(Central America).
    P.D. You can email to: [email protected]

    Do you mean that you want to execute mail or mailx unix commands to send mails.If i am right then probably you are looking for a way to execute operating system commands from your procedure.
    You can refer this link if you want to do that. You need java support in your Oracle database and i believe that Oracle 8 does have jvm running in the instance.
    http://asktom.oracle.com/pls/ask/f?p=4950:8:5079825575573830264::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:952229840241
    Thank you!

  • Executing windows batch commands from linux

    Hi,
    Kindly shed some light on executing the MSwindows batch commands from linux machine.
    Thanks
    RKA

    hi RKA
    What about using a virtual windows machine ? Or use a DOSemu (DOS Emulator) is a program that lets you run many of your favorite DOS applications under Linux.
    Why do you need to execute MSwindows batch commands ?
    Please explain.
    Edited by: Hub on Nov 12, 2008 1:56 PM

  • Executing a DOS Command from JSP

    How do i execute a Dos command from within JSP. I would like to execute a sql Loader command .
    Thanks

    You use Runtime.execute().
    Take a look here for a few of the tricks involved in it:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • SQL Plus command to print a report in Landscape format

    Hi,
    what is the SQL Plus command to print a report in Landscape format?

    841731 wrote:
    Hi,
    what is the SQL Plus command to print a report in Landscape format?SQLPlus doesn't print, and it doesn't know about 'landscape' vs. 'portrait' any more than it knows about fonts. the only 'formatting' it knows is line size, page size. And all it does with line size is know where to insert a CR/LF pair (windows) or a CR (*nix). The only thing it knows to do with page size is repeat column headers.
    The rest is up to whatever application you use to open the pure asciii text spool file.

  • How to execute a Command Prompt command from J2SE code executing on Windows

    How to execute a Command Prompt command from J2SE code executing on Windows??
    Please help me

    [http://java.sun.com/docs/books/tutorial/getStarted/]
    ~

Maybe you are looking for

  • TableView - IC WebClient

    Hi,   I have a tableview to display records in a view.   When I click to next page and select a row. The Tableview is refresh and go back to first page.   Is there any method to hold that page? So that whenever I select what ever row, it refresh but

  • How can I do a buffered digital acquisition on a single line?

    I am using a NI PCI 6110 DAQ and I need to do a continuous buffered data acquisition (sample rate near or above 5 kS/s). The thing is, the acquisition must be done on a single digital line. Some other lines of the digital port are used for something

  • Error: No SWF Data

    I am attempting to port an application designed for the web onto the Brew SDK 3.1 I have successfully managed to run various Hello World apps. which I have put together but when I publish the more complex application and try to start it in the simula

  • HTTP Error 400 with BC adapter

    Hi, does anyone have experience with the BC (business connector) adapter in XI. We have a sender BC compatible system that sends IDocs over HTTPS to our BC today. BC forwards these IDocs to our R/3 backend. Now we want to migrate from BC to XI. There

  • Need help using LR with a 2nd Computer/Laptop

    I just installed LR on to my laptop last night. I currently have all my photos saved to my desktop in e:\photos. I belived the sidecars are in that same folder, and the other stuff is in the default c:\docandsettings (or whatever it is). The laptop i