Executing multipule .sql files in Sequence
Hi ,
I am new to oracle world . I need to execute 150 .sql files from my local machine . I am trying do something like this ...
but facing many errors ... I am using oracle 10 g
Please advice me .
CREATE OR REPLACE PROCEDURE MYPROC AS
BEGIN
DECLARE
CNT NUMBER :=0;
@c:\sql\1.sql;
CNT:=CNT+1;
@c:\sql\2.sql;
CNT:=CNT+1;
commit;
EXCEPTION
BEGIN
ROLLBACK;
DBMS_OUTPUT.PUT_LINE('TRANSACTION ROLLEDBACK')
DBMS_OUTPUT.PUT_LINE('Failed at Executing' CNT-1)
CNT:=0;
END;
END;
END MYPROC
user11791474 wrote:
i need to create pl sql because if any of these files are errored then i need to terminate my execution . I guess just executing 15o sql files in one wrapper sql will keep executing next sql files.
do you have any idea about how to call sql files in pl sql then ?No you can't call an sql*plus file in Pl/sql.
What you can do in SQl*plus is someting like this:
untested
-- set an exit condition
WHENEVER SQLERROR EXIT ROLLBACK
spool logscripts.log
prompt "running script 1"
@script1.sql
prompt "running script 2"
@script2.sql
prompt "running script 3"
@script3.sql
prompt "running script 5"
@script4.sql
prompt "running script 6"
@script5.sql
spool off
Similar Messages
-
Error while executing the .sql file
Hello,
Every time when i execute the below plsql it's keep throwing the error message as show in below output, this happens even when i manually create the trigger before executing the .sql file of all the below statements, can you please correct me what i am doing wrong here. Thank you.
DROP TABLE FCSDWH.REF_DATA_MASTER;
CREATE TABLE FCSDWH.REF_DATA_MASTER
REF_DATA_MASTER_ID NUMBER PRIMARY KEY,
DESCRIPTION VARCHAR2(255 CHAR),
CREATE_ID VARCHAR2(10 CHAR),
CREATE_DT DATE,
LST_UPD_ID VARCHAR2(10 CHAR),
LST_UPD_DT DATE,
ACT_STRT_DT DATE,
ACT_END_DT DATE
TABLESPACE FCSDWH
STORAGE(INITIAL 50K);
DROP SEQUENCE FCSDWH.REF_DATA_MASTER_SEQ;
CREATE SEQUENCE FCSDWH.REF_DATA_MASTER_SEQ START WITH 1 INCREMENT BY 1;
DROP TRIGGER "FCSDWH.REF_DATA_MASTER_TRG";
CREATE OR REPLACE TRIGGER FCSDWH.REF_DATA_MASTER_TRG
BEFORE INSERT ON FCSDWH.REF_DATA_MASTER
FOR EACH ROW
BEGIN
SELECT FCSDWH.REF_DATA_MASTER_SEQ.NEXTVAL INTO :NEW.REF_DATA_MASTER_ID FROM DUAL;
END;
/Output:
SQL> @/home/smadala/REF_DATA_MASTER.SQL
Table dropped.
Table created.
Sequence dropped.
Sequence created.
DROP TRIGGER "FCSDWH.REF_DATA_MASTER_TRG"
ERROR at line 1:
ORA-04080: trigger 'FCSDWH.REF_DATA_MASTER_TRG' does not exist
Trigger created.
SQL>The trigger is "attached" to the table so when you drop the table the trigger goes as well.
John -
Importing and executing a .sql file into Oracle 10g
Hi
I am looking to import and execute a .sql file(create scripts created of a databse designed in MS SQL Server 2005). The file was imported into Oracle APEX 3.10 but we are unable to execute the script. Please suggest alternatives as to how we can import these files.
Thanks in advance.You likely need to migrate the database (objects and data). This is not so easy and you should have a look to migration tools: http://www.oracle.com/technology/oramag/oracle/07-sep/o57sql.html.
-
How to execute a .sql file from a batch file
Hi all
I've to take backup of a database weekly twice on every wednesday & Friday @ 5pm IST. I've written a hot backup script, which works every well.
now i want to automate the script. ie i want this script to run on wednesday & friday @ 5pm without any human interfearance ie with out actually any1 executing this script.
i created a batch file prod.bak with the following lines
@echo off
set oracle_sid=testdb
set oracle_home=d:\oracle\ora92
sqlplus /nolog
connect sys as sysdba/oracletest@testdb
this batch file when eexecuted connects me to sql prompt.
Now i want to execute my backup script bkp.sql automatically when it is connected to sql prompt.
(i tried with these lines in the above batch file...
call bkp.sql---it just opens the bkp.sql file in notepad & displays the script
start bkp.sql---same as call
connect / as sysdba/pwd@[email protected] --- does not work simply remains a the sql prompt.
At 17:00 /Every:w,f "d:\bkp.sql"---does not work simply remains at the sql promt.)
Can any1 let me know what should i write in the batch file that will execute the bkp.sql file automatically after it gets connected to sql prompt. M using oracle 9i.
I'll manage he time through windows utility of scheduling task.. Let me know how to execute the .sql file from a batch file.
Thanks
TriptiTry
sqlplus "sys/oracletest as sysdba" @bpk.sql
Working locally, and having set the ORACLE_SID, you don't need to specify the SqlNet alias (@testdb).
Remember to put an exit at the end of the bpk.sql script. -
Bat file execute all *.sql files in a folder
Hi all,
How to write a *.bat file to execute all *.sql files in a folder?
Because have about 20 *.sql file in a folder. There are used to fix data in my database. The number of *.sql file increases day by day. So I want to write a *.bat file to execute all *.sql file in the folder. Since I just run this *.bat file.
Mai Thanh Hải.user545846 wrote:
Hi
I have done this many times. can guide you. :)And did it fail to work all the times you tried it?
c:\>type test1.sql
select 1 from dual;
exit
c:\>type test2.sql
select 2 from dual;
exit
c:\>sqlplus scott/tiger@testdb @c:\test*.sql
SQL*Plus: Release 10.2.0.3.0 - Production on Thu Aug 6 12:37:04 2009
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SP2-0556: Invalid file name.
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining optionsWildcards in SQL*Plus filenames don't work. So why do you suggest that?
Better is to use the DOS command FOR...
c:\>for %i in (test*.sql) do sqlplus scott/tiger@testdb @%i
c:\>sqlplus scott/tiger@testdb @test1.sql
SQL*Plus: Release 10.2.0.3.0 - Production on Thu Aug 6 12:38:06 2009
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
1
1
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
c:\>sqlplus scott/tiger@testdb @test2.sql
SQL*Plus: Release 10.2.0.3.0 - Production on Thu Aug 6 12:38:06 2009
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
2
2
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
c:\>... although even better would be to proceduralise the SQL into packages/procedures on the database and have just a single procedure call do all the work. -
Need help, executing a SQL file from Forms
Hi everyone,
I don't know if this can be done. I want to execute a SQL file from a When-Button-Pressed trigger. I checked a couple of place but havent found anything yet on how to do this. If someone know of a way, please help.
Thanks
Ericprocedure p_call_sqlplus is
l_filename varchar2 (1000) := 'C:\abc\def\test.sql' ;
begin
host ('sqlplus /NOLOG @' || l_filename ) ;
end ;
rem ======== test.sql ========
connect scott/tiger
spool 'C:\abc\def\test'
select * from emp ;
spool off
exit
rem ======================working on the machine where forms is running -
hi all
i want to execute a sql file from Pl/sql block.
plz help me...
thanx
AshishThis is one way
-- Program Name: EXTcmd.sql
-- This sql will create a java class.
-- Parameters: &1 = OS command string
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED "EXTcmd" AS
import java.lang.Runtime;
public class EXTcmd
public static void execute (String command)
try
Runtime rt = java.lang.Runtime.getRuntime();
rt.exec(command);
catch(Exception e)
System.out.println(e.getMessage());
return;
-- Program Name: EXT_execute_cmd.sql
-- This sql will create a stored procedure to using java class to execute the command.
-- Parameters: &1 = OS command string
create or replace procedure EXT_execute_cmd (cmd IN VARCHAR2) as
language java name 'EXTcmd.execute( java.lang.String)';
-- Program Name: EXT_job_execute.sql
-- Called by: Oracle job
-- Call : EXT_execute_cmd
create or replace procedure EXT_job_execute
(P_EXEC_CMD IN VARCHAR2) is
cmd_string varchar2(200);
begin
cmd_string := 'PUT YOUR SCRIPT HERE';
EXT_execute_cmd(cmd_string);
end EXT_job_execute;
null -
How to execute a sql file inside a plsql file?
It's easy to exec a plsql inside a sql. Simply
start my_proc.plsql
exec my_proc;
But how to execute a sql file inside a plsql file?
declare ...
begin
start my_sql.sql?
end;
Thanks.
- ZacDoesn't work. Even though @ is different from start in this case but it just doesn't like the way sql and plsql are mixed. For example:
DECLARE n NUMBER := 0;
BEGIN
select COUNT(*) INTO n from user_tab_partitions;
DBMS_OUTPUT.put_line('Number of partitioned tables = ' || to_char(n));
if n = 0 then
DBMS_OUTPUT.put_line('createViewsProcs.sql');
@createViewsProcs.sql
else
DBMS_OUTPUT.put_line('createPartitionViewsProcs.sql');
@createPartitionViewsProcs.sql
end of;
END;
SQL> @postimp.sql
SQL> DECLARE n NUMBER := 0;
2 BEGIN
3 select COUNT(*) INTO n from user_tab_partitions;
4
5 DBMS_OUTPUT.put_line('Number of partitioned tables = ' || to_char(n));
6
7 if n = 0 then
8 DBMS_OUTPUT.put_line('createViewsProcs.sql');
9 @createViewsProcs.sql
9 SET SERVEROUTPUT ON SIZE UNLIMITED;
10 SET TERM ON;
11 SET ECHO ON;
12 EXEC DBMS_OUTPUT.put_line('STARTING VIEWS, PROCS, ETC, THIS MAY TAKE A FEW MINUTES');
13 EXEC DBMS_OUTPUT.put_line(SYSTIMESTAMP());
14
15
16 CREATE OR REPLACE PACKAGE db_convert AS
17 FUNCTION ......
32 END;
33 /
SET SERVEROUTPUT ON SIZE UNLIMITED;
ERROR at line 9:
ORA-06550: line 9, column 5:
PL/SQL: ORA-00922: missing or invalid option
... -
Any ideas how to execute a .sql file on database server from java?
Any ideas how to execute a xyz.sql file (which is fisically on
database server) from java?
thanksTry
sqlplus "sys/oracletest as sysdba" @bpk.sql
Working locally, and having set the ORACLE_SID, you don't need to specify the SqlNet alias (@testdb).
Remember to put an exit at the end of the bpk.sql script. -
Dynamically open/execute a .sql file
Is it possible to dynamically open a .sql file?
Specifically, if the user's input will determine which file to open, how can I open the corresponding file?
For example, if the user's options are 1, 2, 3, 4, 5 and their selection will determine whether to open file1.sql, file2.sql, file3.sql, file4.sql, or file5.sql, how do I open the correct file?
Let me know if additional information is needed.
Thanks!Can you take a step back and explain exactly what you're trying to accomplish here?
Are you trying to give users some sort of menu-based system in SQL*Plus that will execute scripts? Will those scripts be on the user's machine? Or on the server?
If this is your goal, you are generally better served using a shell script on a central server to present the menu, process the choice, and invoke SQL*Plus or putting some sort of thin web-based GUI on top of the scripts.
Justin -
How to execute PL/SQL file (*.sql) ?
In SQL*plus, I use edit command to input a sample PL/SQL program into a foo.sql, but now I don't know how to execute this PL/SQL file in SQL*plus. Who can help me ?
In sql plus, issue the following command (for purposes of this example, I am assuming that foo.sql is in the c:\temp directory.
@c:\temp\foo.sql
The "@" can also be written as
start c:\temp\foo.sql -
Error after executing dbowner.sql file
I'm installing People Soft and I'm on the step for executing sql files
I'm trying to execute dbowner.sql that is content of it
set echo on
spool dbowner.log
GRANT DBA TO PS IDENTIFIED BY PS;
CONNECT PS/PS;
CREATE TABLE PSDBOWNER (DBNAME VARCHAR2(8) NOT NULL, OWNERID VARCHAR2(8) NOT NULL ) TABLESPACE PSDEFAULT;
CREATE UNIQUE INDEX PS_PSDBOWNER ON PSDBOWNER (DBNAME) TABLESPACE PSDEFAULT;
CREATE PUBLIC SYNONYM PSDBOWNER FOR PSDBOWNER;
CONNECT system/manager;
REVOKE DBA FROM PS;
ALTER USER PS QUOTA UNLIMITED ON PSDEFAULT;
spool off
after execution i received this
SQL>
SQL> GRANT DBA TO PS IDENTIFIED BY PS;
Grant succeeded.
SQL> CONNECT PS/PS;
Error accessing PRODUCT_USER_PROFILE
Warning: Product user profile information not loaded!
You may need to run PUPBLD.SQL as SYSTEM
Connected.
SQL> CREATE TABLE PSDBOWNER (DBNAME VARCHAR2(8) NOT NULL, OWNERID VARCHAR2(8) NOT NULL ) TABLESPACE PSDEFAULT;
Table created.
SQL> CREATE UNIQUE INDEX PS_PSDBOWNER ON PSDBOWNER (DBNAME) TABLESPACE PSDEFAULT;
Index created.
SQL> CREATE PUBLIC SYNONYM PSDBOWNER FOR PSDBOWNER;
Synonym created.
SQL> CONNECT system/manager;
Connected.
SQL> REVOKE DBA FROM PS;
Revoke succeeded.
SQL> ALTER USER PS QUOTA UNLIMITED ON PSDEFAULT;
User altered.
SQL>
SQL> spool off
could you help me?
If you need more info write me>
SQL> CONNECT PS/PS;
Error accessing PRODUCT_USER_PROFILE
Warning: Product user profile information not loaded!
You may need to run PUPBLD.SQL as SYSTEM
>
script PUPBLD.SQL runs from psadmin.sql, but this is run after the dbowner.sql
+@%ORACLE_HOME%\sqlplus\admin\pupbld+
You can try running this script (PUPBLD.SQL) manually, but I never saw this going wrong. Something has gone wrong, which will most likely give more errors later on.
Did you run the scripts in the correct order with the correct user:
createdb10.sql - as sysdba
utlspace.sql - as sysdba
dbowner.sql - as sysdba
XXddl.sql - as sysdba
psroles.sql - as system
psadmin.sql - as system
connect.sql - as system
Regards,
Hakan
Added psroles.sql thanks to bandar
Edited by: Hakan Biroglu on Aug 21, 2012 8:26 AM -
How to execute one sql file in unix
Hi,
I need to run the follwing script in a file in unix , then run the corresponding spooled file again
SET echo OFF;
SET sqlblanklines ON;
SET feedback OFF;
SET linesize 1500;
SET trimspool ON;
SET termout OFF;
SET pagesize 0;
spool updatedfix.sql;
SELECT ' <update stmt>
spool OFF;
SET termout ON;
SET echo ON;
SET feedback ON;
How can the above script in a file be executed in unix
like
ed script
@ script
then
@ updatedfix.sql;
plz help
thanksI haven't got unix to hand but the principle is the same in windows batch files..
c:\temp>type gen_update.sql
set echo off
set sqlblanklines on
set feedback off
set linesize 1500
set trimspool on
set termout off
set pagesize 0
spool updatedfix.sql
select 'update emp set comm = -1 where comm is null;' from dual;
select 'exit' from dual;
spool off;
set termout on
set echo on
set feedback on
exit
c:\temp>sqlplus user/pass@db @gen_update.sql
SQL*Plus: Release 10.2.0.3.0 - Production on Wed May 6 12:25:10 2009
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> set feedback on
SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
c:\temp>sqlplus user/pass@db @updatedfix.sql
SQL*Plus: Release 10.2.0.3.0 - Production on Wed May 6 12:25:37 2009
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
10 rows updated.
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
c:\temp>Just run one after the other in the script file. -
How to execute a script(.sql) file from a PL\SQL procedure
I would like to know how to execute a .sql file from a stored procedure and the result of it should update a table. My .sql file contains select statements.
Hi!
just go through the following piece of code -
SQL> ed
Wrote file afiedt.buf
1 declare
2 str varchar2(200);
3 begin
4 str := '@C:\RND\Oracle\Misc\b.sql';
5 execute immediate(str);
6* end;
SQL> /
declare
ERROR at line 1:
ORA-00900: invalid SQL statement
ORA-06512: at line 5ORA-00900: invalid SQL statement
Cause: The statement is not recognized as a valid SQL statement. This error can occur if the Procedural Option is not installed and a SQL statement is issued that requires this option (for example, a CREATE PROCEDURE statement). You can determine if the Procedural Option is installed by starting SQL*Plus. If the PL/SQL banner is not displayed, then the option is not installed.
Action: Correct the syntax or install the Procedural Option.
Regards.
Satyaki De. -
Executing .sql file in oracle using php
Hello friends
I am converting the oracle form into web application.
My requirement is to execute a .sql file when i click on a button in the html form.
What i need to do is when the user click on the button then the sql+ window shoudl open up and a file located on the server should get executed.
Please note i have to do this in php. If any other alternative is there for this requirement then that also is welcomed.
Any help would be appreciated.
Thanks
VinodThe thing is i am using
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
I am connecting to the DATABASE using
the below php code
=========================
<?php
if (!ini_get('display_errors')) {
ini_set('display_errors', 1);
PutEnv("ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/server/");
PutEnv("LD_LIBRARY_PATH=-Wl,-rpath,/usr/lib/oracle/xe/app/oracle/product/10.2.0/server//lib -L/usr/lib/oracle/xe/app/oracle/product/10.2.0/server//lib -lclntsh");
$dbstr ="(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = XXX.XXX.XXX.XXX)(PORT = XXXX))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XE)
if(!@($conn = oci_connect('SYSTEM','passwordString',$dbstr)))
print_r(ocierror());
else
echo "connected succesfully";
exit;
?>
========================
I am able to connect the database and ececute query and fetch the results.
Now one file will be present in some directory on the server let say abc.sql
Now i need to execute that file and display the output to the user by means of php code.
So please provide me the detailed step on how to get this done.
Thanks
Maybe you are looking for
-
Intercompany FI customer/vendor invoice clearing F-32
Hello, In ECC 6.0, we created Customer (DR) and Vendor (KR) invoices using FI transaction. When we clear Customer/Vendor using F-32, the invoices get cleared, but the process produces intercompany document (AB) as a open item on both Customer and Ve
-
Working on my next project for the tech blog Techmozilla I am trying to make php to work with Apache. . i surfed for the procedures and finally i was asked to do the below mentioned operation .. but i am unable to understand it can anyone please help
-
can n e 1 tell me where i am going wrong i am trying to use sql in a jsp to try to take out specific tuples from a table in my db but it is not working. i have been looking at the code for ages and can't figure out where i'm going wrong. please help!
-
Gamers Unlocked still not active after a month.
I purchased this membership in mid May 2015. I went to the store after receiving the card to get it activated. I was promised that was activated. I waited a couple days and noticed that it still wasn't active so I went directly to the retail store an
-
Value intervals for PO release
Hi Can we put value intervals for the characterestic in the PO release classsification? Regards