Can I issue this command in PL/SQL: EXECUTE IMMEDIATE '@filename.sql';

can I issue this command in PL/SQL: EXECUTE IMMEDIATE '@filename.sql';

Hi,
Rather the opening a new process (sqlplus), a new connection (need password) etc... I would rather read and execute the file in pl/sql.
I do not know if someone wrote it already, but here is a quick and dirty code for doing that with UTL_FILE.GET_LINE
Here, I am only processing some DML statements and no SELECT statements. Correct it as you like !
CREATE OR REPLACE PROCEDURE run_script ( dir_name IN VARCHAR2,file_name IN VARCHAR2)
IS
vSFile UTL_FILE.FILE_TYPE;
vCmd VARCHAR2(200);
vNewLine VARCHAR2(200);
BEGIN
    vSFile := UTL_FILE.FOPEN(dir_name, file_name,'r');
    vCmd := NULL;
    IF UTL_FILE.IS_OPEN(vSFile) THEN
    LOOP
        BEGIN
            UTL_FILE.GET_LINE(vSFile, vNewLine);
            if (vCmd is null) THEN
                if (upper(vNewLine) like 'INSERT%' or upper(vNewLine) like 'UPDATE%' or upper(vNewLine) like 'DELETE%') THEN
                    if (vNewLine like '%;') THEN
                        /* we have a single line command, execute it now */
                        dbms_output.put_line(substr(vNewLine,1, length(vNewLine)-1));
                        execute immediate substr(vNewLine,1, length(vNewLine)-1);
                    else
                        /* we have a command over multiple line, set vCmd */
                        vCmd := vNewLine;
                    end if;
                else
                    /* ignore the rest like spool, prompt, accept, errors, host, @, ... */
                    null;
                end if;
            else
                if (vNewLine like '%;') THEN
                    /* we have a the last line of the command, execute it now */
                    vCmd := vCmd || ' ' || substr(vNewLine,1, length(vNewLine)-1);
                    dbms_output.put_line(vCmd);
                    execute immediate vCmd;
                    vCmd := null;
                else
                    /* keep concatenating to vCmd */
                    vCmd := vCmd ||' '|| vNewLine;
                end if;
            end if;
        EXCEPTION
            WHEN NO_DATA_FOUND THEN
                EXIT;
            END;
    END LOOP;
    COMMIT;
    END IF;
    UTL_FILE.FCLOSE(vSFile);
EXCEPTION
    WHEN utl_file.invalid_path THEN
        RAISE_APPLICATION_ERROR (-20052, 'Invalid File Location');
    WHEN utl_file.read_error THEN
        RAISE_APPLICATION_ERROR (-20055, 'Read Error');
    WHEN others THEN
        RAISE_APPLICATION_ERROR (-20099, 'Unknown Error');
END run_script;
set serverout on
create directory scriptdir as '/home/oracle';
grant read,write on directory to scott;
exec run_script('SCRIPTDIR', 'test.sql')

Similar Messages

  • When I issue the 'Force group Settings' command what effect will this have on existing flows? Do I need to disable WCCP prior to issuing this command on the affected WAE's?

    Hi WAAS Experts,
    I have a query, when I issue the 'Force group Settings' command what effect will this have on existing flows? Do I need to disable WCCP prior to issuing this command on the affected WAE's?
    Thanks,
    Shankar K

    Hi Shankar,
    A change of classifier/policy on the WAE is not affecting the existing flows so you shouldn't need to disable WCCP if you want to force group settings there.
    Regards,
    Nicolas

  • What happend if we issue this command.

    what happend if we issue this command.
    ALTER SYSTEM ARCHIVE LOG CURRENT

    It would enforce archiving of the current redo log.

  • Where should I issue this command

    Hi all,
    I'm configuring a logical standby database (Oracle 10g R2 on Linux 4.5). In the steps, I should convert to a Logical Standby Database and thus the following command should be issued:
    ALTER DATABASE RECOVER TO LOGICAL STANDBY db_name;My question is: if I have db1 as the primary database and db2 as the standby one, on which database should I issue the command? what would be the value of db_name?
    Thanks in advance.

    I can sort of see why this section of the manual (http://download.oracle.com/docs/cd/B19306_01/server.102/b14239/create_ls.htm#i92346) where it says:
    This section describes how to prepare the physical standby database to transition to a logical standby database. It contains the following topics:
    and
    The redo logs contain the information necessary to convert your physical standby database to a logical standby database. To continue applying redo data to the physical standby database until it is ready to convert to a logical standby database, issue the following SQL statement:
    was not clear enough to state definitely that you do the command on the Physical Standby.
    The preceding section header says: 4.2.3 Prepare the Primary Database to Support a Logical Standby Database
    And then it goes to: 4.2.4 Transition to a Logical Standby Database
    I can see where it might look like we're still on the Primary database. I checked the 11.2 manual and it is pretty much the same so I'll file a doc bug to try and clean this up.
    Thanks.
    Larry

  • I can't get this command line code to work in JBuilder...

    Dear Experts,
    I built a simple JAVA program, in JBuilder, that displays a GUI with a label. It works when I am in JBuilder clicking on the Run button. But when I try to run
    "-classpath /[home]/ jbProject/ProjectNameRob/RobClasses ProjectNameRob.RobClsJav" from the command line I get this message:
    "Could not create Java Virtual Machine."
    I am in the jdk/bin directory and I still can't figure out how this thing works. Could the experts come forth and help me with this problem?
    Thank you,
    Robert L. Perkins

    Well, this won't be an exact answer for you because I'm not sure which run of "java -cp ...." did it for me, but I was able to get a run of a class in JBuilder 3.0 from the command line.
    I created a project called test_1.jpr. It has the following 3 files:
    Controller.java // contains a main( ) method
    test_1.html
    Test1.java // extends from JFrame
    On my system, the directory structure is:
    C:\JBuilder3\myclasses\test_1
    Tried:
    C:\JBuilder3\myclasses\test_1>java Controller // no good
    C:\JBuilder3\myclasses>java test1.Controller // no good
    C:\JBuilder3\myclasses>java -cp %CLASSPATH%;C:\JBuilder3\myclasses Controller // no good
    C:\JBuilder3\myclasses>java -cp %CLASSPATH%;c:\JBuilder3\myclasses\test_1 Controller // no good
    C:\JBuilder3\myclasses>java -cp %CLASSPATH%;C:\jbuild~1\myclas~1\test_1\Controller
    That resulted in the "usage" output to appear for the "java" .exe. But right after that, I did:
    C:\JBuilder3\myclasses>java test_1.Controller
    and wham, the application ran fine. I'm running Windows 98 SE, if that helps. Probably won't help you much, but I just kept messing around with it and then it worked. Voodoo.
    HTH
    Jeff

  • How can I use this command?

    Why can't I use the command fdisk on Fedora8?
    [root@localhost SCOTT]# fdisk -l
    bash: fdisk: command not found

    [root@fedora ~]# ls /sbin/fdisk -l
    -rwxr-xr-x 1 root root 94924 2007-10-16 16:48 /sbin/fdisk
    [root@fedora ~]# /sbin/fdisk
    Usage: fdisk [-l] [-b SSZ] [-u] device
    E.g.: fdisk /dev/hda (for the first IDE disk)
    or: fdisk /dev/sdc (for the third SCSI disk)
    or: fdisk /dev/eda (for the first PS/2 ESDI drive)
    or: fdisk /dev/rd/c0d0 or: fdisk /dev/ida/c0d0 (for RAID devices)
    [root@fedora ~]# rpm -qa | grep util-linux
    util-linux-ng-2.13-3.fc8
    [root@fedora ~]#

  • TS1702 Using Numbers app, can't copy excel spreadsheet into Numbers via an attached email document on gmail.  Apple instructions state that an "open in" tab should be available. Can't locate this command. Only "open in Safari" appears.  Using app on iPad.

    USing Numbers app but can't copy excel spreadsheet attached to a gmail email into Numbers. Apple instruction state that you click on opened document and choose option to open in Numbers. Don't have this option, only an option to open in Safari. I need very complete instructions, I'm pretty new to IPad apps. Thanks!

    THanks, but no go.
    when I open spreadsheet attachment, only option is in lower right hand corner-- a box with arrow. When I touch this icon it gives me a choice to open in Safari or Cancel. No white dots.
    PLs be really basic with your response to me. I thought I am pretty computer literate but this has be baffled.
    THanks. I'm sure there is something "simple" that I'm missing.

  • How can i achive this result by writing SQL Query ?

    Dear Exparts,
    Here is my banner
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    "CORE     10.2.0.3.0     Production"
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - ProductionI have two table with relation. Here is the scripts of create table and insert data.
    TABLE
    CREATE TABLE TAB1
      T1_ID NUMBER(5)
    , T1_NAME VARCHAR2(100)
    ALTER TABLE TAB1 
    MODIFY (T1_ID NOT NULL);
    ALTER TABLE TAB1
    ADD CONSTRAINT TAB1_PK PRIMARY KEY
      T1_ID
    ENABLE;
    CREATE TABLE TAB2
      T2_ID NUMBER(5) NOT NULL
    , T2_T1_ID NUMBER(5)
    , T2_RV_NO VARCHAR2(20)
    , T2_RV_DATE DATE
    , T2_F1 VARCHAR2(20)
    , T2_F2 VARCHAR2(20)
    , T2_F3 VARCHAR2(20)
    , CONSTRAINT TAB2_PK PRIMARY KEY
        T2_ID
      ENABLE
    ALTER TABLE TAB2
    ADD CONSTRAINT TAB2_TAB1_FK1 FOREIGN KEY
      T2_T1_ID
    REFERENCES TAB1
      T1_ID
    ENABLE;INSERT DATA
    Insert into TAB1 (T1_ID,T1_NAME) values (1,'Test 1');
    Insert into TAB1 (T1_ID,T1_NAME) values (2,'Test 2');
    Insert into TAB2 (T2_ID,T2_T1_ID,T2_RV_NO,T2_RV_DATE,T2_F1,T2_F2,T2_F3) values (1,1,'00',to_date('01-OCT-2012','DD-MON-RRRR'),'Probation','05','Yes');
    Insert into TAB2 (T2_ID,T2_T1_ID,T2_RV_NO,T2_RV_DATE,T2_F1,T2_F2,T2_F3) values (2,1,'01',to_date('06-OCT-2012','DD-MON-RRRR'),'Confirm','06','Yes');
    Insert into TAB2 (T2_ID,T2_T1_ID,T2_RV_NO,T2_RV_DATE,T2_F1,T2_F2,T2_F3) values (3,2,'00',to_date('02-OCT-2012','DD-MON-RRRR'),'Probation','07','No');
    Insert into TAB2 (T2_ID,T2_T1_ID,T2_RV_NO,T2_RV_DATE,T2_F1,T2_F2,T2_F3) values (4,2,'01',to_date('09-OCT-2012','DD-MON-RRRR'),'Probation','07','Yes');
    Insert into TAB2 (T2_ID,T2_T1_ID,T2_RV_NO,T2_RV_DATE,T2_F1,T2_F2,T2_F3) values (5,1,'02',to_date('10-OCT-2012','DD-MON-RRRR'),'Confirm','06','No');Now i want to produce the following reports..
    Period:      06-OCT-2012 to 09-OCT-2012
    T2_RV_DATE     T1_NAME          T2_RV_NO     Revised_Column     Previous_Value     Revised_value
    06-OCT-2012     Test 1          01          T2_F1          Probation     Confirm
                                  T2_F2          05          06
    09-OCT-2012     Test 2          01          T2_F3          No          YesI just achieve Revised_Column     Previous_Value     Revised_value for a particular name.
    Here is my code
    SELECT T2_RV_NO,T2_RV_DATE,T1_NAME,'T2_F1' Revised_Column,PREVIOUS_VALUE,REVISED_VALUE
    FROM(
    SELECT T2_RV_NO,T2_RV_DATE,T1_NAME,'T2_F1',
    LAG(T2_F1) OVER (ORDER BY T2_RV_DATE) PREVIOUS_VALUE ,T2_F1 REVISED_VALUE
    FROM TAB2,TAB1
    WHERE TAB1.T1_ID=TAB2.T2_T1_ID
    AND TAB1.T1_ID=:EMP_ID)
    WHERE NVL(PREVIOUS_VALUE,'null')<>NVL(REVISED_VALUE,'null')
    AND T2_RV_DATE BETWEEN :BEGIN_DATE AND :END_DATE
    AND T2_RV_NO<>'00'
    UNION ALL
    SELECT T2_RV_NO,T2_RV_DATE,T1_NAME,'T2_F2' Revised_Column,PREVIOUS_VALUE,REVISED_VALUE
    FROM(
    SELECT T2_RV_NO,T2_RV_DATE,T1_NAME,'T2_F2',
    LAG(T2_F2) OVER (ORDER BY T2_RV_DATE) PREVIOUS_VALUE ,T2_F2 REVISED_VALUE
    FROM TAB2,TAB1
    WHERE TAB1.T1_ID=TAB2.T2_T1_ID
    AND TAB1.T1_ID=:EMP_ID)
    WHERE NVL(PREVIOUS_VALUE,'null')<>NVL(REVISED_VALUE,'null')
    AND T2_RV_DATE BETWEEN :BEGIN_DATE AND :END_DATE
    AND T2_RV_NO<>'00'
    UNION ALL
    SELECT T2_RV_NO,T2_RV_DATE,T1_NAME,'T2_F3' Revised_Column,PREVIOUS_VALUE,REVISED_VALUE
    FROM(
    SELECT T2_RV_NO,T2_RV_DATE,T1_NAME,'T2_F3',
    LAG(T2_F3) OVER (ORDER BY T2_RV_DATE) PREVIOUS_VALUE ,T2_F3 REVISED_VALUE
    FROM TAB2,TAB1
    WHERE TAB1.T1_ID=TAB2.T2_T1_ID
    AND TAB1.T1_ID=:EMP_ID)
    WHERE NVL(PREVIOUS_VALUE,'null')<>NVL(REVISED_VALUE,'null')
    AND T2_RV_DATE BETWEEN :BEGIN_DATE AND :END_DATE
    AND T2_RV_NO<>'00'but it's not work for multiple employee id
    Thanks in advance
    Edited by: Asked to Learn on Oct 6, 2012 9:18 PM

    Asked to Learn wrote:
    thanks members. i get a solution of my own for my reporting purpos. Thanks..Well why don't you post your solution? Why not be helpful to others like yourself who might search the forum looking for answers? Don't just take, give back.
    Cheers, APC

  • Copy Command in Pl/Sql block

    Can I use Copy command in Pl/Sql.For example :-
    Declare
    cursor c1 is select table_name from all_tables
    where owner = 'LSP' and rownum = 1;
    v1 varchar2(2000);
    Begin
    for c2 in c1 loop
    v1:='copy from lsp/lsp123479@dvlaq to scott/[email protected] create '|| c2.table_name ||' using select * from '||c2.table_name;
    execute immediate v1;
    end loop;
    end;
    Its not running properly giving an error as invalid Sql statement .
    Is it bcoz Copy command cannot be used in a Pl/Sql Block.

    Is there any other way to move the Table & data to another Data Base .Database link is the obvious one. And the SQL statement would look something like this (on the target database):
    SQL> create table FOO nologging as select * from FOO@sourcedb;
    However, the first question I always ask if why? What one may think is the solution to a problem is not always the best solution. So one need to identify the problem first, and then see what solutions there are and which one is the best fit.
    Other options are replication (using materialised views for example), Data Pump (available with 10G) - even could be Data Guard, a standby database, or a Real Application Cluster... depending on just what the problem and actual requirements are.
    Also important to note that SQL*Plus has its own set of commands. Do not confuse these commands (like EXEC, COPY, CONNECT, HOST etc) with the SQL and PL/SQL Languages. Not only are they executed by different software products, SQL*Plus commands are executed on the client and SQL (and PL/SQL) runs inside the Oracle database instance.

  • Can i use this view in discoverer

    Hello
    I have a view like below in R12.
    GL_CODE_COMBINATIONS_KFV
    In etrm there is a warning:
    Oracle Corporation does not support access to Oracle
    applications data using this object, except from standard Oracle Applications programs.
    Can any one you please let me know if i can still use this for a custom sql report.
    thx
    kp

    You can use the KFV for a custom report - just be aware that the definition of the KFV can change (via a patch) without warning, and the Support will not help if you have issues with using the KFV.
    Srini

  • Com.sap.aii.adapter.file.ftp.FTPEx: 550 You are not allowed to issue this

    hi All,
    We are getting below error while connecting to an FTP location through File Adapter:
    Message processing failed. Cause: com.sap.engine.interfaces.messaging.api.exception.MessagingException: An error occurred while connecting to the FTP server XYZ. The FTP server returned the following error message: 'com.sap.aii.adapter.file.ftp.FTPEx: 550 You are not allowed to issue this command'. For details, contact your FTP server vendor.
    Also when we tried to connect to this FTP location through PI server we able to connect, but when we connect to it through channel we are getting above error.
    Please Help!
    Thanks,
    Mayank

    hi All,
    The usedid we are using to connect to FTP location has appropriate access to write(we have an receiver file adapter) the files, when we connected to FTP location from PI server using same useid(as used in channel) we are able to connect to FTP location and also able to write the file there.
    Now error soming is:
    An error occurred while connecting to the FTP server XYZ. The FTP server returned the following error message: 'com.sap.aii.adapter.file.ftp.FTPEx: 550 Operation is not supported under Connect:Enterprise FTP server.'. For details, contact your FTP server vendor.
    Thanks,
    Mayank

  • I have Adobe Acrobat XI (ver 11.0.07).  Adobe Help instructs me to find the document comparison command at "View Compare Documents," however, this command does exist on my screen. My View drop-down list does not include a command for Compare Documents.

    I have Adobe Acrobat XI (ver 11.0.07).  Adobe Help instructs me to find the document comparison command at "View > Compare Documents," however, this command does exist on my screen. My View drop-down list does not include a command for Compare Documents.  Where else can I find this command?

    What version of Acrobat do you have? This feature is only available in the Pro version, not in the Standard version.

  • Dos Command fron PL/SQL

    Hi All,
    Can we run DOS Command from PL/SQL Program.
    Thanks

    you can execute os commands using DBMS_PIPE package. Write a program that reads an Oracle pipe (using C or java) and send messages to pipe in PL/SQL Your C program should read pipe and execute statement in it by using system() command.

  • Can i store and retrieve image using sql command?

    hi
    the following is what i enter to store image in table using sql*plus
    however i encounter some errors as shown below.
    i wondered if i actually can use sql to store image and retreive image
    or i need other developer beside sql to do.
    create table img_storage
    (id     number primary key,
    image     ORDSYS.ORDImage);
    CREATE or REPLACE procedure ADD_image (tmp_id number, file_name varchar2)
    as
         obj ORDSYS.ORDImage;
         ctx raw(4000) := null;
    begin
         INSERT INTO img_classifier (id, image) VALUES (tmp_id,
         ORDSYS.ORDImage (ORDSYS.ORDSOURCE(EMPTY_BLOB(),
         NULL,NULL,NULL,SYSDATE,NULL),
         NULL,NULL,NULL,NULL,NULL,NULL,NULL));
         COMMIT;
         SELECT image into obj FROM img_storage
         where id = tmp_id FOR UPDATE;
         obj.importFrom(ctx,'FILE','IMGDIR',file_name);
         obj.setproperties();
         UPDATE img_storage
         SET image = obj where id = tmp_id;
         COMMIT;
    end;
    show errors;
    create or replace directory imgdir as 'c:\image\';
    exec add_image(1,'argvseng.jpg');
    BEGIN add_image(1,'argvseng.jpg'); END;
    ERROR at line 1:
    ORA-00001: unique constraint (SYS.SYS_C002717) violated
    ORA-06512: at "SYS.ADD_IMAGE", line 7
    ORA-06512: at line 1
    how to reslove the error as shown above.
    or sql does not support ordsys.ordimage such command.
    hmm very confused ....
    what is the difference bet using blob for image and ordsys.ordimage?

    This has nothing to do with intereMedia.
    This is a basic SQL issue.
    A primary key cannot have duplicate entries in a table as the error message suggests.
    Before you call your peocedure you can delete the row with 1 as the primary key, or call the insert peocedure using a primary key that is not being used.

  • Why can I not attach a document to an email? Every time I want to send an email with a document attached to it, an error notice pops out. It tell me that the file is being used even when  it is not. How can I fix this issue?

    Why can I not attach a document to an email? Every time I want to send an email with a document attached to it, an error notice pops out. It tells me that the file is being used even when  iall other programs are closed. How can I fix this issue?

    Thanks Jeff, I was not aware that a template could be multi-page.  (All the existing templates were 1 page)
    But it worked, saving me some steps.  When I was finished I renamed the document, and locked it.
    Then tried to save it but  could not because it was locked.  I closed it, went to my Spread Sheet Folder ,
    to find it, it was not there.  The Finder could not find it either.
    So I start over again.
    I opened up Numbers and it showed my personal Numbers template folder, it contained both my new 
    original 4 page template and the vanished saved document!
    I tried to delete the template containing these document data and could not - I had to go to the Library/Application Support/Numbers to physically remove it from this folder. Then I started over again.  I Finally found out how to make it work: I can now "save as", and then lock, and it will go to place where I want it to be saved and locked.
    The secret is: Click on the document title in the menu bar, and it opens up  "Save as...", which works the same as in OS 10.4.11, and you can pick the place you want for saving.  Once done that, you can then lock the document in the same pull down menu, and then close it.
    I also found later that I can delete a template from its folder, by letting Numbers open the templates,
    clicking on the one I want to remove, then go to the "Numbers Menu/File/Move to...", select "Desktop"
    and from there the selected template can then be thrown into the Trash from there.
    It appears now that the real fault of the Numbers software is that the "Save as" command is not available in the "Edit" or "File" pull-down menus, but hidden behind the title of the document.

Maybe you are looking for

  • Premiere Pro CC Keeps Crashing Upon Launch

    I just became a CC member recently and I installed Premiere Pro but every time I launch it, it crashes shortly after opening. I've tried uninstalling and reinstalling but the problem continues. All my other Adobe Apps work fine. Any suggestions?

  • Bill of lading via printer with trays

    Dear gurus, We print our bill of lading with a laser printer with trays. in tray three there are the predifined papers for the bill of lading. that is 4 papers in different colors which are exactly the same. If I do not have to many items on my bill

  • Releasing Anchored objects

    I saw a couple of earlier posts with code for releasing an anchored object ( http://forums.adobe.com/click.jspa?searchID=2331267&objectType=2&objectID=1109584 and http://forums.adobe.com/click.jspa?searchID=2331267&objectType=2&objectID=2062943 ) but

  • Display php page ok vs ko because of oracle client or cache or buffer size?

    Hello everybody, Excuse me for my english, I searched every where but ... linux ubuntu php 4.4.6 apache 2.2.4 oracle client XE VS win xp php 4.4.6 apache 2.2.4 oracle client 9i same database 9i a sql query : - select statement cost 25 - execution tim

  • Why do videos continue to stop and start on my MacBook Air?

    When I try to watch videos, like on You Tube, the videos will only play small sections at a time.  It won't play continuosly.