Execute  commands/statements in txt file supplied to plsql procedure

Hi,
I need to execute commands which are in txt file , this txt filepath is supplied to the procedure.
In the procedure i want to open the txt file and read the commands and run the commands.
Please help on this .
Edited by: 904032 on Jun 26, 2012 12:02 AM

The fact that you are supplying a file path (more correctly known as a directory) is going to be your first problem. Security within Oracle means that access to files on the file server require a directory object to be specified and these directory objects refer to a specific directory on the file server. If you're going to be passing different directories into your procedure then you're going to have to have different directory objects set up for all the possible directories that can be accessed (or issue dynamic DDL to redefine a known directory object each time).
Once you've done that you can use the UTL_FILE package (http://docs.oracle.com/cd/E11882_01/appdev.112/e25788/u_file.htm#ARPLS70906) to read the contents of the file as lines.
Then it depends what you mean by "commands" and "statements". Are you referring to operating system commands?... If so you will need to use something like the DBMS_SCHEDULER package to issue a job to run immediately with the appropriate command, as that is able to issue operating system commands, or you are going to have to write some Java code to issue commands for you (plenty of examples if you google). OR, perhaps you are referring to SQL statements? These could possibly be issued using the PL/SQL execute immediate statement, but you will be leaving your database open to SQL injection and major security issues, something that most companies would consider a serious flaw and not want.
how to read string which is delimited by ';'. or how read each charater in a file ..About time you read the documentation (http://tahiti.oracle.com/). There are functions: SUBSTR and INSTR which can search for things in strings and extract parts of strings, or you can use the more advanced regular expression versions of those REGEXP_SUBSTR and REGEXP_INSTR, or even REGEXP_REPLACE (which is also good for extracting parts of strings).
If you want a more concise answer, you need to ask a more concise question... {message:id=9360002}

Similar Messages

  • How to execute command(program) from external file in Oracle SQL developer

    Hi,
    Does anyone know, Oracle SQL developer version 1.0.0.14.67 got any function that can execute command from an external file?
    Example, i have 100 insert SQL inside a text file,
    and i want to use Oracle SQL developer to execute it. How do i read from my text file? Thanks a lots.

    If you're new to Oracle, do yourself and us a favour: read some tutorials and manuals. What sqldev's worth, better download the latest version (1.1.2), lots of fixes and enhancements...
    Now for the big popper: to run an external file: @file
    Best of luck,
    K.

  • How to export the result from executing sql statement to excel file ?

    HI all,
    Great with Oracle SQL Developer, but I have have a trouble as follwing :
    I want to export the result from executing sql statement to excel file . I do easily like that in TOAD ,
    anyone can help me to do that ? Thanks so much
    Sigmasvn

    Hello Sue,
    I just tried to export to excel with the esdev extension and got java.lang.NumberFormatException. I found the workaround at Re: Windows Multi-language env, - how do I set English for application lang?
    open the file sqldeveloper\jdev\bin\sqldeveloper.conf and add the following two lines:
    AddVMOption -Duser.language=en
    AddVMOption -Duser.country=USyet now my date formats in excel are 'american-style' instead of german. For example 01-DEC-01 so excel does not recognize it as date and therefore I can not simply change the format.
    When export to excel will be native to 1.1 perhaps someone can have a look at this 'feature'
    Regards
    Marcus

  • CREATE BANK STATEMENT UPLOAD TXT FILE SAPBYD

    Hi,
    I implemented bank statement upload TXT FILE and loading the file format MT940 UK, load the file with status CONFIRMED but does not perform any bank statement in the list of BANK STATEMENT just seems like INBOUND FILES with status FINISHED but not as financial status.
    Anyone have a UK model MT940, and knows that the next step has to be performed after loading INBOUND FILE
    Email: [email protected]
    PD: Attached my MT940 UK inbound file to review in case .
    Regards

    goto to the user exit where u will find import & export parameters...Now create a project and implement this enhancement...Inside the FM u will find Zprogram which needs to be created. Now write ur code in this by importing data and check routinues and export back to variables....When u run actual transaction, this user exit automatically triggers...

  • How to execute sql statement under bat file?

    I want to execute following statement
    C:\>sqlplus /nolog
    SQL> conn scott/tiger
    SQL> select * from tab;
    I know I can realize it as following test.bat and testdb.sql file
    test.bat is follows:
    sqlplus /nolog @testdb.sql
    testdb.sql is follows:
    conn scott/tiger
    select * from tab;
    Now I don't want to use sql file,I only want to use bat file,like follows:
    test.bat is follows:
    sqlplus /nolog
    conn scott/tiger
    select * from tab;
    when I run test.bat,I find only sqlplus /nolog statement execute,the other statements don't execute.
    1)I want to know whether there is a method to execute sql statement only by bat file without a sql file? How to realize it?
    2)If I call sql file,how to hide passord of user? Because I don't want to other persons know scott password,if I use conn scott/tiger in testdb.sql,other person can see testdb.sql and know the password. Is there a good method to avoid?
    Thanks!

    I'm running *NIX, but works the same on Windows
    bcm@bcm-laptop:~$ cat here.sh
    sqlplus dbadmin/admindb << EOF
    select count(*) from user_objects;
    exit
    EOF
    bcm@bcm-laptop:~$ sh here.sh
    SQL*Plus: Release 11.2.0.1.0 Production on Mon May 17 18:14:09 2010
    Copyright (c) 1982, 2009, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL>
      COUNT(*)
          9
    SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    bcm@bcm-laptop:~$ Edited by: sb92075 on May 17, 2010 6:15 PM

  • Security restrictions , how to read access a txt file supplied in a jar

    I had written a simple application which uses file handling to display random line from a file on a swing window
    but I do not know how to give my web application permission to access a file
    when I set security permission to all, then error says the application cannot load because the code require unrestricted acess to system resources and is unsigned, I don't know how to get that certificate and I am only doing it for learning purposes.
    when I remove security permissions then it says
    access denied java.io.FilePermissions geekjoskes.txt readPlease help
    I locally signed the jar file, and give my jnlp fiel all permissions, worked fine in my system but when I access same file from local lan it sho errors ,
    please help, I have my txt file stored in my jar file with main class
    the whole jnlp file is
    <?xml version="1.0" encoding="utf-8"?>
    <!-- JNLP File for geek jokes -->     
    <jnlp spec="1.0+"
           codebase="http://localhost/javasoft/webstart/"
          href="geekjokes.jnlp">
       <information>
          <title>Geek Jokes</title>
          <vendor>Vaibhav Mishra</vendor>
          <description>Geeky jokes</description>
          <homepage href="http://scjpbeginner.blogspot.com"/>
          <description kind="short">shows random jokes</description>
          <offline-allowed/>
       </information>
       <resources>    
            <jar href="GeekJokes0.1.jar"/>  
         <j2se version="1.6+"
               href="http://java.sun.com/products/autodl/j2se"/>
         <icon href="geekjokes.gif"/>
       <icon kind="splash" href = "geekjokes.gif"/>
       </resources>
       <security>
          <all-permissions/>
       </security>
       <offline-allowed/>  
       <application-desc main-class="GeekJokes"/>
    </jnlp>Edited by: 76jsr on Aug 7, 2008 3:45 PM
    Edited by: 76jsr on Aug 7, 2008 3:49 PM

    >
    I am extremely thankful to you and finally my first little app is working thanks to you,
    here is it's link
    [http://profile.iiita.ac.in/IIT2006117/javasoft/webstart/geekjokes/geekjokes.jnlp|http://profile.iiita.ac.in/IIT2006117/javasoft/webstart/geekjokes/geekjokes.jnlp] >
    I am glad you got it working! But that launch file is still slightly invalid.
    Here is a corrected, and slightly optimized (you can leave the prefix off the href, if it is the same as the codebase), version of it.
    <?xml version="1.0" encoding="utf-8"?>
    <!-- JNLP File for GeekJokes 0.3 app -->
    <jnlp spec="1.0+"
          codebase="http://profile.iiita.ac.in/IIT2006117/javasoft/webstart/geekjokes"
          href="geekjokes.jnlp">
       <information>
          <title>GeekJokes App</title>
          <vendor>Vaibhav Mishra</vendor>
          <homepage href="http://scjpbeginner.blogspot.com"/>
          <description>Geeky Jokes</description>
          <description kind="short">Cshows random jokes</description>
          <offline-allowed/>
       </information>
       <resources>
           <j2se version="1.6+"
               href="http://java.sun.com/products/autodl/j2se"/>
           <jar href="GeekJokes0.3.jar"/>
       </resources>
       <application-desc main-class="Process"/>
    </jnlp>Very 'Geeky', BTW. ;-)
    Another few things I noted when I looked at it.
    1) There is a stray thread going after the JOptionPane is dismissed. The VM does not end, and the console (if you have it configured to pop-up for JWS apps.) stays on-screen.
    2) If all the jokes are prefixed by '* ' I would recommend removing it from every line of the source file and either re-adding it at runtime, or (preferably) not adding it at all (since it is redundant).
    3) Reconfigure the app. into a loop, and offer the user a JOptionPane with "Another Joke"/"End" instead of "OK".
    4) You can always remove that debugging line I inserted in the code to show the path to the Jar - it was just intended as a 'sanity check' during testing.
    5) Why is it Java 1.6+? JOptionPane was introduced in Java 1.2 with the first Swing implementations, and the I/O is compatible with Java 1.1.
    >
    Thanks again!!!!>Thanks are best expressed (to me) in the notation of a helpful/correct answer (which you have done), and the assignation of (the remaining) dukes*. ;-)
    * After all - checks the title - we have gotten entirely around those 'security restrictions' in a sandboxed application. The reason being that File objects are rarely the correct choice, for applets or JWS apps.

  • Executing commands read from text file

    I'm trying to execute full command lines that I am reading in from a text file. For example, each line in the file contains a full call to a method that I have already written, including arguments. I have opened the text file, can read in line by line and store in an array, but how do I go about executing the commands?
    For example, if the first slot in my array contains the string "myMethod(50, 100);" how can I effectively get that to execute, followed by the next comand, etc.?
    I think I'm overshooting this, because it really shouldn't be difficult.
    Help would be reciprocated with undying gratitude and perhaps the sacrifice of a pot nellied pig in your name.
    D.

    this article seems like it might be helpful to you.
    http://www.javaworld.com/javaworld/jw-03-2005/jw-0314-
    scripting.htmlSlappy would be proud!
    But before i am scolded, i will promise not to bring it up
    again.
    w

  • System (Runtime) execute command for copying the file

    Can any one tell me what is wrong with this - it throws an IOException
    String sourcepath = "C:"+File.separator+"pbx"+File.separator+"mantra"+File.separator+"vvvvv.mp3";
    String destinationpath = "C:"+File.separator+"rrr"+File.separator+"mantra"+File.separator+"mantra.mp3";
    Runtime rt=Runtime.getRuntime();
    try{
    String command="C:"+File.separator+"windows"+File.separator+"command /c copy "+sourcepath+" "+destinationpath;
    System.out.println(command);
    rt.exec(command);
    }catch(IOException ex){System.out.println("exception "+ex); ex.printStackTrace();}
    output:-
    C:\windows\command /c copy C:\pbx\mantra\vvvvv.mp3 C:\rrr\mantra\mantra.mp3
    exception java.io.IOException: CreateProcess: C:\windows\command /c copy C:\pbx\mantra\vvvvv.mp3 C:\
    rrr\mantra\mantra.mp3 error=2
    java.io.IOException: CreateProcess: C:\windows\command /c copy C:\pbx\mantra\vvvvv.mp3 C:\rrr\mantra
    \mantra.mp3 error=2
    at java.lang.Win32Process.create(Native Method)
    at java.lang.Win32Process.<init>(Win32Process.java:66)
    at java.lang.Runtime.execInternal(Native Method)
    at java.lang.Runtime.exec(Runtime.java:566)
    at java.lang.Runtime.exec(Runtime.java:428)
    at java.lang.Runtime.exec(Runtime.java:364)
    at java.lang.Runtime.exec(Runtime.java:326)
    at Test.main(Test.java:82)

    this is clear one...
    String sourcepath = "C:"+File.separator+"pbx"+File.separator+"mantra"+File.separator+"vvvvv.mp3";
    String destinationpath = "C:"+File.separator+"rrr"+File.separator+"mantra"+File.separator+"mantra.mp3";
    Runtime rt=Runtime.getRuntime();
    try{
    String command="C:"+File.separator+"windows"+File.separator+"cmd /c copy "+sourcepath+" "+destinationpath;
    // String command="copy "+sourcepath+" "+destinationpath;
    System.out.println(command);
    rt.exec(command);
    }catch(IOException ex){System.out.println("exception "+ex);
                ex.printStackTrace();}

  • Executing consub statement via a file.

    I've produced a file with a CONSUB Statement. And this file was produced using Spool using dbms_output.put_line statements.
    The Consub statement is a valid concurrent request (if i copied the statement into unix it will run), however, it says that i am giving the wrong number of parameters if i run the statement by execulting the file.
    I am think it is because the dbms_output automatically beaks the consub statement into a new line after a set number of charaters and unix doesn't like the carrage return.

    1) 255 bytes per line
    http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96612/d_outpu2.htm#1000446
    2) Create a directory object where you specify the path (on the database server)
    To test wether a file exists, try to open the file in read mode.
    http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96612/u_file.htm#ARPLS069

  • Email text files through plsql procedures

    Hi,
    I have written a procedure that selects table data and writes a .txt file in delimitted format. After the file is created on the C drive of the server I want to attach the file in a email and send it to the recepients.
    I have used the built in package and can send emails...but it goes with out the attachment...
    Can anyone tell me how can i attach the .txt file in the plsql procedure that sends the email.??

    user8958533 wrote:
    Hi,
    I have written a procedure that selects table data and writes a .txt file in delimitted format. After the file is created on the C drive of the server I want to attach the file in a email and send it to the recepients. Don't - why write data externally and then have to read that data again to use it internally?
    An attachment in an e-mail is not a separate file - the file contents is part and parcel of the e-mail message body. It is a single block of data. There is no requirement for the so-call attachment to be a physical file at all. All that is needed is correctly formatting the main body (as per MIME specs).
    So rather write data to a CLOB and when done, create the e-mail body and append the CLOB contents to the e-mail.
    This topic has been discussed numerous times. See {message:id=3963129} and {message:id=3913513} for starters.. and consider using the search function before asking a question.

  • Run sql statement from batch file

    How can we execute SQL Statement using Batch file???
    I did a test.
    create batch file test.bat
    sqlplus "username@db /pass" @\script.sql
    script.sql file has following statement
    select sysdate from dual;
    exit
    it is working but I want to call sql statement in the same batch file instead of calling .sql script file. how can I do that any idea..

    This is very easy in unix shell scripting, but AFAIK, not available with Windows. It's a function of how the shell/command processor handles input redirection.

  • Executing commands from Oracle

    Hi,
    I want to execute commands from Oracle where files are stored in Server. For eg. (sample.dat) contains some insert scripts which is stored in UNIX Server, that scripts should be executed from oracle using some methods!! Hope everyone got it. If not, pls let me know i'll elaborate it later.
    Thanks
    Rajaram

    If you are using oracle 10g then you can use dbms_scheduler to execute o/s commands, scripts.
    BEGIN
    -- Job defined entirely by the CREATE JOB procedure.
    DBMS_SCHEDULER.create_job (
    job_name => 'test_full_job_definition',
    job_type => 'EXECUTABLE',
    job_action => '/scripts/myscript.sh',
    start_date => SYSTIMESTAMP,
    repeat_interval => 'freq=hourly; byminute=0',
    end_date => NULL,
    enabled => TRUE,
    comments => 'Job defined entirely by the CREATE JOB procedure.');
    END;
    For earlier versions than 10g
    http://www.dba-oracle.com/t_execute_operating_system_os_command_oracle.htm

  • .ttx file in UNIX/PLSQL

    Hi All,
    Is it possible to generate .ttx file through shellscript/plsql procedure?
    Please help me in this.
    Thanks,
    Bopty
    Edited by: Bopty on Aug 29, 2012 3:36 PM

    hmm, been a while since I worked with crytal report but any of those reporting tools usually interpret XML in which case youre back to same thing, raw data with tags as you wish.
    Oracle can export as XML so then you have a job to convert. However, Im not sure this is the most efficient way of doing that, any reporting tool Ive worked with (crystal/business objects, SQR, disco) all have DB reporting functionality built in, so you would engineer your report to pull out from crystal reports directly.
    Or for a remote crystal installation with no db access, pull the data out to raw data (csv even) and design a report in crystal on the raw data.

  • Accessing txt file in executable vi

    Hi,
    I have built a user interface for a project im working on. The data entered by the user on the interface is saved in a text file upon closing of the program. This is currently working fine but when I create an executable of my code, data is not written to the txt file upon closing. Is there some special way to build these types of VIs,
    The code for writing to the file is in a sub VI and i use the "Write to spreadsheet file" function, i pass in the reference of "C:\Documents and Settings\asha264\Desktop\Single Line\Single Line (9.0)\Data.txt".
    Thanking You,
    Adnan Sharief
    Solved!
    Go to Solution.

    Make sure that your means for signalling the other vi's to exit doesn't have an inadvertent race condition. Remember that LabVIEW is data flow language, that to make sure that certain events occur in a certain order that there is a signal dependecy to force the order of execution. I got bit by that recently when we used a functional global to signal all of the various programmatic loops in the various vi's when it was time to shut down. There was at least one place where, under certain conditions, the loop stop terminal was getting the signal before the "stuff" in the loop had executed. Putting an error in/out on the FG, then puting it in the error line after the functions (actually file writing) guaranteed that the file writes would occur before the "exit" condition was evaluated.
    Putnam
    Certified LabVIEW Developer
    Senior Test Engineer
    Currently using LV 6.1-LabVIEW 2012, RT8.5
    LabVIEW Champion

  • How to Open the FailedFilesLog.txt File (statement), and How to Increase the 100 File Limit (question)

    It took us a while to figure this out, so I'm posting this in case it's helpful for someone out there. Plus, I have a question...
    DPM gave the following error for one of our file servers:
    Description: The replica of Volume D:\ on <servername> is inconsistent with the protected data source. Number of files skipped for synchronization due to errors has exceeded the maximum allowed limit of 100 files on this data
    source (ID 32538 Details: Internal error code: 0x809909FE)
    Recommended action: Review the failure errors for individual files from the log file
    \\?\Volume{8492c150-f195-11de-a186-001cc4ef89a0}\B1E9D373-2C03-464E-A472-99BC93DB1E2A\FailedFilesLog.txt and take appropriate action. If some files fail consistently, you can exclude the folders containing these files by modifying the protection group or
    moving the files to another location.
    So, how do you actually open the FailedFilesLog.txt file shown in this DPM alert? What is this path referring to? Well, this is the mount point for the protected server's replica volume on the DPM server, which is mounted under \Program
    Files\Microsoft DPM\DPM\Volumes\Replica\servername\File System. Here you'll see the mount points for all of the server's protected volumes. However, if you try to open one of these mounted volumes
    in Windows Explorer, you'll get Access Denied, even if you have administrator rights. (If someone knows of a way around this, please let me know). As a workaround, you can access this mounted volume in an elevated
    command prompt. Steps:
    Open an Administrator Command Prompt
    Type mountvol <AnyAvailableDriveLetter>: \\?\Volume{VolumeGUID}
    Example:  mountvol m: \\?\Volume{8492c150-f195-11de-a186-001cc4ef89a0}   Note that we're only using the first part of the path to the FailedFilesLog.txt
    file given in the DPM alert, starting from \\? and ending after the
    } character.
    Next, type m: to change to the newly mounted m: drive.
    Then type cd B1E9D373-2C03-464E-A472-99BC93DB1E2A   This is actually a folder name so we're just going into this folder.
    Finally type dir and you should see the FailedFilesLog.txt file. This file can be copied to another location where it's easier to use (i.e. in Windows Explorer).
    Be sure to unmount this volume when you're done by typing mountvol m: /d in the command prompt. (Mountvol reference:
    http://technet.microsoft.com/en-us/library/cc772586(WS.10).aspx.)
    What a pain, eh? But at least by reviewing the FailedFilesLog.txt file you can determine which files or folders caused the sync to fail and thus take action accordingly.
    Now, here's my question: Where is that registry key that lets me adjust the limit of 100 files that DPM allows to be skipped before it fails the replica? Hopefully someone out there will tell me. I know this can be done because Kapil Malhotra
    said so in this post:
    http://groups.google.com/group/microsoft.public.dataprotectionmanager/browse_thread/thread/a179fa30fb50c9b0/e9a348f2a9386063?lnk=raot.
    Also, does anyone know what the internal error code 0x809909FE means in this alert? Knowing this my help us determine what caused these files to fail. Interestingly, in the FailedFilesLog.txt file, it gave a different error code next to each failed file:
    0x80070002.
    -Taylorbox

    Thanks for responding, Fahd. So, just to be sure...
    Do I add this registry key to the DPM server or to the protected servers (or both)?
    In either case, the ContinueOnFailure key does not currently exist. So, I must create this key and the MaxFailedFiles DWORD value
    manually, right?
    Does the server in which I create this regkey have to be restarted for it to take affect?
    Can the DPM alert for the 0x809909FE error event (for exceeding the limit of 100 failures) please be adjusted to provide a path to the FailedFilesLog.txt file
    that actually works if you click on it?
    Any ideas on why the 0x80070002 "File not found" error happened? The files on the server were simply created and then deleted. Why would such file activity lead to this error?
    Thanks,
    -Taylorbox

Maybe you are looking for

  • Freesat & smart tv connection

    Hi. I have a new Panasonic Viera smart tv and a Humax 1000s, both linked to my BT home hub 3 via Ethernet cables. They both operate fine via the internet and I can see their mac addresses on the router info when I interrogate it - all ticketyboo. I t

  • Implementation of file log

    I have a problem. I want to implement a file log, but I am not sure exactly how. The file log should be placed in a scrollpane and be updateable. If the program detects a new file, the file should appear in the log window. Each file shold be logged w

  • Updating to 1.1.3

    When I try to update my software to 1.1.3 I get a message stating 'iTunes could not contact the iPhone software update server because you are not connected to the internet' but I am connected to the net via a wireless BT connection. The iTunes store

  • Download  trial version of Photoshop elements 11 seems to  downloading elements 10

    I am trying to download the trial version of Photoshop elements 11 but it seems to be downloading elements 10?  help please?

  • More Logic Express 7.2 questions

    I've used Cubase for some years (and Cakewalk before that) so I consider myself pretty au fait with DAWs, but I have a few basic questions about Logic (I would RTFM from cover to cover if it was paper, but online is not an acceptable substitute in a