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.
Similar Messages
-
Execute all SQL code as individual Oracle user, not APEX_PUBLIC_USER
Is it possible to get APEX to execute SQL code as the user's existing Oracle database user instead of APEX_PUBLIC_USER?
Besides having all of the security already defined for each of the existing users at the database level, the existing application also handles generating audit trails with triggers that pull the username executing the SQL instead of accepting passed values. At the moment APEX_PUBLIC_USER is plastered everywhere as the user that generated the changes.rcy_evdriver wrote:
Is it possible to get APEX to execute SQL code as the user's existing Oracle database user instead of APEX_PUBLIC_USER? No. See:
{message:id=926724}
{message:id=1224601}
{message:id=1606515}
Application Express and parsing of SQL
Besides having all of the security already defined for each of the existing users at the database level, the existing application also handles generating audit trails with triggers that pull the username executing the SQL instead of accepting passed values. At the moment APEX_PUBLIC_USER is plastered everywhere as the user that generated the changes.Using DAD Credentials Verification will cause the database user to be returned by the <tt>USER</tt> pseudo-column. (However just because you can do this, it doesn't mean you should.)
{message:id=9680421}
Why are you asking this? +"At the moment APEX_PUBLIC_USER is plastered everywhere as the user that generated the changes"+ indicates that it might be a bit late to be making fundamental discoveries about APEX and database security? -
How to get the erroe message, if i run java program using .bat file
Hi,
I have a java file which accepts two inputs as command line argument. I want to make this pgm a tool. So have created a *.bat file which has the following command
java myprogram arg1 arg2
I'm gonna share this program with others. So i'll keep the class file and the .bat file in a commaon folder. All the users have to do is, edit the .bat file to give his/her args and run the .bat file. The pbm is, if the user input is not valid, I have put displays in the pgm to show it.
But if i run thru .bat, I'm not getting the error message or I don't know where it is getting displayed.
Can anyone help me with this ?
Thanks,
MaryWhen i run from the console, I can see the output.
But, when i double click on the .bat file from the
folder, it runs fine and i couldn't see the output.
nullThat's because the error message is printed, and then the console is closed. The message is there but you need to read really really fast :) -
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 -
How to execute .bat file within pl/sql block
Hi,
I want to execute a batch file (.bat) file withing a pl/sql procedure. Please guide me for it.
RegardsThere are several possible ways to make a call-out from a PL/SQL program to the OS on the database server (but not to the client computer).
You could use java or an external procedure (you'll need to code it in C) for example.
You might be able to make use of UTL_HTTP to talk HTTP to another server or UTL_TCP to talk TCP to another server.
What is it you are trying to do? -
Execute .Bat file from pl/sql code
Hi,
Can you please let me know that how can I execute the .Bat file from pl/sql procedure? Does anybody have a sample code??
Thanks.Hi
This may help you
http://www.dba-oracle.com/t_running_windows_bat_file_dbms_scheduler.htm
br,Jari -
Executing *.bat file from PL/SQL
Is there anyway for Executing *.bat file from PL/SQL ?
ThanksTry here:
asktom.oracle.com/pls/ask/f?p=4950:8:15427268967155079552::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:952229840241 -
Execute SSIS Package from JOB which contains Execute Process Task calling a .bat file
Hi All,
I have a EXCEL Macro needs to be called from SSIS. We could not use Script task because of some internal reason.
So we have taken an approach to call a .BAT file using Execute Process Task. This .BAT file will call a .VBS file which will execute the EXCEL Macro.
The SSIS Package is running good if I execute the package from BIDS.
But the real problem is with the scheduling this SSIS Package using SQL JOB.
If i execute this SSIS package from SQL Server Job, its executing the whole package successfully except the Execute Process Task.
So the overall issue is SQL Server Job is not executing properly if I call any .BAT file from the SSIS Package.
Please give me suggestion to get rid of the issue. Thanks in advance.Hi Sai.N,
If you run the SQL Server Agent job manually from SSMS, does the package execute properly? If the package executes properly when you run the job manually, the issue should occur due to permission issue. In this case, I suggest that you create a SQL Server
Agent proxy based on the current Windows account which you use to log onto the operating system, and run the job under the proxy account.
If it is not the issue, please enable logging in the package as Visakh mentioned and post the warning/error message for further analysis.
Regards,
Mike Yin
TechNet Community Support -
Calling .bat file from pl/sql
I'm running Oracle 11g R2 on win7 system, and I would like to execute .bat file from a pl/sql block.
I created a .bat file
I have granted privs to an account:
BEGIN
SYS.DBMS_JAVA.GRANT_PERMISSION(grantee => 'COMMON', permission_type => 'SYS:java.io.FilePermission', permission_name => '<<ALL FILES>>', permission_action => 'execute',key => KEYNUM);
END;
DECLARE
KEYNUM NUMBER;
BEGIN
SYS.DBMS_JAVA.GRANT_PERMISSION(grantee => 'COMMON',permission_type => 'SYS:java.lang.RuntimePermission',permission_name => 'writeFileDescriptor',permission_action => '*',key => KEYNUM);
END;
DECLARE
KEYNUM NUMBER;
BEGIN
SYS.DBMS_JAVA.GRANT_PERMISSION(grantee => 'COMMON',permission_type => 'SYS:java.lang.RuntimePermission',permission_name => 'readFileDescriptor',permission_action => '*' ,key => KEYNUM);
END;
DECLARE
KEYNUM NUMBER;
BEGIN
SYS.DBMS_JAVA.GRANT_PERMISSION(grantee => 'COMMON',permission_type => 'SYS:java.io.FilePermission',permission_name => 'C:\dokumentacija\rman_backup\*',permission_action => 'read,write',key => KEYNUM);
END;
DECLARE
KEYNUM NUMBER;
BEGIN
SYS.DBMS_JAVA.GRANT_PERMISSION(grantee => 'COMMON',permission_type => 'SYS:java.io.FilePermission',permission_name => 'C:\dokumentacija\rman_backup\*', permission_action => 'read',key => KEYNUM);
END;
DECLARE
KEYNUM NUMBER;
BEGIN
SYS.DBMS_JAVA.GRANT_PERMISSION(grantee => 'COMMON', permission_type => 'SYS:java.io.FilePermission', permission_name => 'C:\windows\system32\*',permission_action => 'read',key => KEYNUM);
END;
DECLARE
KEYNUM NUMBER;
BEGIN
SYS.DBMS_JAVA.GRANT_PERMISSION(grantee=> 'COMMON',permission_type => 'SYS:java.io.FilePermission',permission_name => 'C:\windows\system32\*',permission_action => 'execute',key => KEYNUM);
END;
/this is Java:
CREATE OR REPLACE PROCEDURE runoscommand(cmd IN VARCHAR2)
AS LANGUAGE JAVA
NAME 'Command.run(java.lang.String)';and this is how I call it:
declare
xx pls_integer;
v_errm varchar2(400);
begin
xx:=0;
xx:=archiver.fullBackup;
dbms_output.put_line(xx);
exception
when others then
v_errm:=substr(sqlerrm,1,400);
dbms_output.put_line(v_errm);
end;this is Java code:
DROP JAVA SOURCE COMMON.COMMAND;
CREATE OR REPLACE AND RESOLVE JAVA SOURCE NAMED COMMON.COMMAND as import java.io.*;
import java.util.*;
public class Command{
public static void run(String cmdText)
throws IOException, InterruptedException
int rtn;
Runtime rt = Runtime.getRuntime();
Process prcs = rt.exec(cmdText);
rtn = prcs.waitFor();
}I run this as a part of a package...
function fullBackup return pls_integer as
v_errm varchar2(200);
begin
runoscommand('C:\dokumentacija\rman_backup\bckp_level_0.bat');
return 0;
exception
when others then
v_errm:=substr(sqlerrm, 1,200);
dbms_output.put_line(v_errm);
return -1;
end fullBackup;but..
at the end, nothing happens..
what I've been missing?846417 wrote:
I changed my code in last xx minutes...OK, so you've removed all your exception handlers?
so, now I'm calling to an exe file wich should appear at a desktop or processes list... but no..
I gave all windows rights on that file, and also through dbms_java.grant_permission..
but, nothing happened... not exception raised, no app. started...And no output from any DBMS_OUTPUT statement? Have you tried stepping through the code in your debugger?
Justin -
Creating windows .bat file from within an oracle .prc or .sql file
I am currently converting a series of batch jobs on a windows server to use an Oracle db rather than a MS sql server db. In ms sql, I could call \mssql80\binn\isql and it allowed me to pass in .prc files and have a .bat file returned. the .bat file is then executed in the calling bat to set variable value returned in the sql call...
I am thinking I can spool a bat file, however, i do not know how to populate this file with the literals and query values needed to create the bat file which sets values used for further processing in the original calling bat file...
Does that make sense? any help is greatly appreciated.Hi,
There can be various ways to do this.
First and simple way is simply spooling out the batch file. Suppose you have a .sql file with all the queries, run the .sql from DOS prompt like this,
c:\> sqlplus -s username/password@tnsname @mysqlfile.sql
the contents of mysqlfile.sql can be,
rem ---------------------
set echo off feedback off head off
spool c:\batch_files\mybatch.bat
select 'start \w ' || win_app_name from mytable ;
spool off
rem ----------------------
exit
So, you can get the batch file created with desired name in desired directory. The '-s' mentioned in the sqlplus command is important.
There is another difficult/tedious way, but that can give you exact output. With UTL_FILE package you can write an operating system file from pl/sql code, stored procedure/package. Its look more like C-language code, but is usefull. So, write a sql or stored procedure and create the batch file. For that matter, you can write any type of file, just you can write whatever you want to a file.
Cheers -
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 -
Executing a .bat file from java code
Im writing a utility and i need to be able to create and execute a .bat file from my program. I can create the .bat file fine but when i try to execute it nothing happens. I tried to use the following line of code to try to execute the .bat file (called make.bat) :
try
String parameterString = "\"C:\\WINNT\\System32\\cmd.exe\" C:\\ITS_Test\\make.bat";
Runtime.getRuntime().exec(parameterString);
catch (Exception e)
System.out.println(e);
The Runtime.getRuntime()exec() method worked fine when trying to execute an excel file but for some reason it dosen't want to work for the DOS prompt. Any ideas?Thanks everyone for all the replies.
I have tried all the above with no luck. Im using netbeans, does anyone think that it could be a problem with the IDE.
I tired the following code :
String parameterString = "cmd.exe /C \"C:\\ITS_Test\\make.bat\"";
Process pr = Runtime.getRuntime().exec(parameterString);
pr.waitFor();
This code does not throw any exceptions but just hangs. I also tried:
String [] parameterString = {"cmd", "/c", "C:\\ITS_Test\\make.bat"};
Process pr = Runtime.getRuntime().exec(parameterString);
pr.waitFor();
and:
String parameterString = "\"C:\\WINNT\\System32\\cmd.exe\" \"C:\\ITS_Test\\make.bat\"";
Process pr = Runtime.getRuntime().exec(parameterString);
pr.waitFor();
with the same result. Does anyone know why it just hangs and nothing happens (no exceptions thrown)? -
How to run sql query in bat file in task schedular at every 10 seconds
This is my sql script :
DECLARE @countRows INT,
@currDate DATE,
@checkForTasks INT,
@created_by_id INT,
@gst_ID int;
SET @currDate = Getdate()
SET @countRows = (SELECT Count(*)
FROM [dbo].[sd_gst_effective_table]
WHERE isapplied = 0)
IF @countRows > 0
-- Check for those GST''s who are not applied yet : if they are greater than 0 then perform next task
BEGIN
SET @checkForTasks = (SELECT Count(*)
-- Check is current date equals to task date or not
FROM [dbo].[sd_gst_effective_table]
WHERE effect_date = @currDate AND isapplied = 0)
IF @checkForTasks > 0
-- If current date = task date then perform this task
BEGIN
SET @created_by_id = (SELECT TOP 1 createdby FROM [dbo].[sd_gst_effective_table] WHERE effect_date = @currDate AND isapplied = 0)
SET @gst_ID = (SELECT gst_id FROM [dbo].[sd_gst_effective_table] WHERE effect_date = @currDate AND isapplied = 0)
-- STEP 1 :: InActivate the existing GST according to createdbyID
UPDATE sd_gst_rate
SET isactive = 0,
inactivedate = Getdate()
WHERE isactive = 1
AND createdby = @created_by_id
-- STEP 2 :: Activate the New GST according to implementation date and gstID
UPDATE sd_gst_rate
SET isactive = 1,
activedate = Getdate()
WHERE id = @gst_ID
-- STEP 3 :: Inactivate the applied GST from sd_gst_effective_table
UPDATE [dbo].[sd_gst_effective_table] SET isApplied = 1 WHERE gst_id = @gst_ID
END
END
DECLARE @Text AS VARCHAR(100)
DECLARE @Cmd AS VARCHAR(100)
DECLARE @value nvarchar(1000);
SET @value = (SELECT CONVERT(TIME,GETDATE()) AS HourMinuteSeconds);
SET @Text = 'File Writed ' + @value
SET @Cmd ='echo ' + @Text + ' > E:\AppTextFile.txt'
EXECUTE Master.dbo.xp_CmdShell @Cmd
This is resided in videos folder of windows , i have created a task schedular in windows 8.1 to run daily at every 10 seconds , but it is not working ... Please tell me how to deal with it.
Please note : This sql query is running perfectly in sql server. Query have no errors. Please check whats wrong with my time schedular. I just want my schedular to run every 10 seconds regardless of date.Hi Emad,
Is your script in a ".sql" file? May I know how you configure the schedule task action?
Since you didn't mention how you configure the schedule task, can you confirm you have followed the below step correctly?
Save your script in a ".sql" file.
Create a ".bat" file and call the sql file above inside with
sqlcmd.exe, you can reference
here.
Configure a schedule task to run the ".bat" file in a certain interval.
Have you tried to run the script in you bat file in a standalone commandline window? Please post the script in your bat file, It can help to diagnose the issue.
If you have any question, feel free to let me know.
Eric Zhang
TechNet Community Support -
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. -
File.execute() not working for bat file
Dear all,
The purpose of my function copyToWinClipboard (text) is to get a string directly into the Windows Clipboard. The purpose is to allow the user of my project just to paste into the open-dialog of the application EndNote. I’m not certain whether the FM clipboard (supported by the copy/cut/paste methods for Doc) really fills into the Windows Clipboard also.
In the PhotoShop script forum I found the idea how to do this.
#target framemaker
// note the blank in the path
copyToWinClipboard ("E:\\_DDDprojects\\FM+EN escript\\FM-11-testfiles\\BibFM-collected.rtf");
function copyToWinClipboard (text) {
var theCmd, clipFile = new File(Folder.temp + "\\ClipBoardW.bat");
clipFile.open('w');
// theCmd = "echo \"" + text + "\" | clip"; // this doesn’t help either
theCmd = "echo " + text + " | clip";
clipFile.writeln (theCmd);
clipFile.close ();
clipFile.execute ();
Running this script provides a short flicker (the command prompt), but the clipboard does not contain the expected string. However, when double clicking on the generated I:\!_temp\ClipBoardW.bat the clipboard is filled correctly.
IMHO the execute method does not work correctly for bat files. In another area of my project-script i run an exe file with this method correctly.Hi Klaus,
sorry for my late response.
execute definitely works witch batch-files
Here's a "batch" - example you can test.
There are two methods to prevent window from closing:
"|more" - kind of pagebreak
"pause"
var oTemp = app.UserSettingsDir + "\\tmp";
var MyDosCommand = "ipconfig.exe /a|more";
var MyPath = new Folder (oTemp);
if (!oTemp.exists)
var MyPath = new Folder (oTemp);
var lFehler = MyPath.create();
oTemp = oTemp + "\\" +"nw.bat";
var MyFile = new File (oTemp);
MyFile.open ('w');
if (MyFile.error > "")
alert("ERROR");
MyFile.writeln(MyDosCommand);
MyFile.writeln("pause");
MyFile.close();
MyFile.execute();
Maybe you are looking for
-
PL/SQL vs C++ ?
I have developed an inventory control application in MS Access & VBA that has been instrumental in saving my company $6 million so far, with at least another 4 to 5 million over the next 18 months. We are a processing plant and part of a global group
-
ProRes files act crazy and transcoding to Animation codec gets ugly
So, allegedly, the Animation codec is lossless. However, when I take something encoded with Apple ProRes 422 HQ and transcode to Animation within the Quicktime Pro software, I see noticeable differences. Including: color change and increased aliasing
-
I have had this problem on two separate websites. I am using Fireworks-originated graphics and popup menu in a Dreamweaver template. On only one page on the website, my pop-up menu is appearing in the wrong place. Example (hover over "Teams & Schedul
-
New Challenge...
Dear All, I have a new challenge. I down loaded a 'simpler' interactive timeline. Populated it with pics and text. Opened .fla and published a .swf. and try to insert the .swf into CP4, but get this error... "The Adobe Flash File contains action
-
When starting FF4 RC1 maximized, tabs ("tabs on top" mode) are cut off on top. To restore their normal display, you restore and maximize the window again.