Execute delete queries using batch file? - oracle

I am using Oracle11g. I have below two sql queries.
Delete from TableA;
Delete from TableB;
Delete from TableC;
Delete from TableD;
Delete from TableE;
Now how can i create a batch file to run this script By passing the credentials to connect to DB and delete using above queries?
Thanks!

Add the statements to a file, say "delete.sql".
To execute the statements in the file, type:
sqlplus username/password#tns_name_of_your_db #delete.sql
...or simply add that into a .BAT file.
PS. Remember to add a COMMIT; statement.
PS2. Make sure the last line of "delete.sql" is empty (blank line).

Related

merge multiple sql files into single sql file with new line in Windows

I want to merge multiple sql files into single sql file.
In windows terminal I am using below type command which is working fine. But during merge i need to add new line space after every file but dont know how to do it. Is there any option in type command or do i need to use any other command ?
type *.sql > TRT.sql

Is there a way to execute robocopy cmd from a Stored Procedure in PL/SQL?

I have to move certain files from a local directory(which is fixed) into another server. I can use robocopy from Windows cmd line to do the same. Is there a way in which i can create a job which executes this specific windows cmd for me in ORacle Pl/SQL? Also, can i include this in a stored procedure?
try to use DBMS_FILE_TRANSFER
https://docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_ftran.htm#CACFJEBH

How to execute oracle query that was saved in a .txt file

I have too long oracle query that I saved in .txt file. and I am using Toad to execute that..
some it is too difficult to open such large code file and execute the code..
Is there any query that I can execute and give path to file that execute the code placed in that file.
For example something like that:
Execute code C:/My Code/code1.txt;
If you have a TOAD locally installed, you can use
#C:/My Code/code1.txt
This works from an editor tab in Toad 12.10.0.30 with the slashes going either direction and pressing F5 or "execute as script". The file can end in .txt or .sql but it is better to use .sql extension as it represents what the file contains.
It also works when using other programs such as sqlplus or sqlDeveloper

run multiple queries with spool in sqlplus

I know I can run multiple queries saved in file with GO statement between them and save the result into file with spool command
but this will save the whole result into a single file
how can I export each query result into a dedicated file ?
use multiple spool statements between each SELECT
eg, spool c:\filenme.txt

Make sqlcmd work with batch separators

Background information:
I am trying to set up a batch job for syncing stored procedures between different sql servers. I did export all stored procedures into seperate .sql files into my folder. Whenever I want to create a new stored procedure or change it for those multiple servers, I test it on 1 server until I got it the way i want it. After that I export it into my folder. To then deploy it to the other servers, I simply execute a batch - that's it.
I've almost figured out my batch the way i want. The only problematic thing is, that sqlcmd seems not to like the standard batch separator 'GO' ('Incorrect syntax near 'GO'.'). So i've changed my default batch separator to 'RUN', replaced each 'GO' command with 'RUN' in my .sql files and added -c RUN to my sqlcmd command.
However it then tells me 'Incorrect syntax near 'RUN'.'.
For testing purposes I just tried it out with 1 shrinked sql file, looking like this:
USE [MyDatabase]
GO
Even that did not work. How can I make it work?
Try leaving out GO or RUN from these scripts. You can change database context without them.
You should be fine to do something like this:
USE MyDatabase;
--First query
USE MyOtherDatabase;
--Second query

Resources