Toad for oracle - open automatically generated script - oracle

I have a script generator in .bat file. This .bat generates a sql script and saves it on disk.
Is there any option to open automatically this script in toad? Also if there is already toad application running to open this script in running toad instance?

You can pass the filename to Toad as a command line argument.
Example: >Toad.exe "C:\My Scripts\MyFile.sql"
On the Startup page in Toad's Options there is an option to only allow multiple instances of Toad. If that is unchecked the above call will reuse an open instance of Toad and open your script.

Related

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

How to source sql file in windows for Oracle DB

I want to source a sql file located in "C:\Users\Administrator\Desktop\malintha.sql" location. I used following command in sql plus
SQL> #C:\Users\Administrator\Desktop\malintha.sql
But it gives me
Unable to open file error.
How to do this correctly ?
You are doing it correctly but the file either isn't there or you have no permissions.
Double check the path
Ensure you are running the SQLPlus session in a command window with appropriate privs (perhaps Run As Administrator)
Try executing from a regular user directory instead of Administrator
I just tested a SQL file with:
SQL> #C:\users\msmith\desktop\test.sql

Windows Batch files and SQLite

When creating a batch file in Windows for SQLite, can the batch file run any commands after it has entered the SQLite shell? Or is it only possible to add command line options?
What I want to do is create a batch file that that starts SQLite and loads the database I want. Then it runs several SQLite commands and then quits.

SQLite in AppleScript?

I have a Windows app called via Shell from MS Word that reads and writes to Sqlite. I'm porting it to Mac. On windows I have a batch file:
SQLite3.exe pathtodb\databasename <sqlitecommands.txt
This batch calls the Sqlite command line program, attachs the database, and reads the command from sqlitecommands.txt. The sqlitecommands is dynamically modified(by Word VBA) to read (Select) Write (Update) to/from the database.
What is the format of an applescript to do the same thing in Mac OSX?
The following AppleScript creates a one-line shell script with sqlite syntax and executes it:
set sql to "sqlite3 ~/desktop/test.db 'insert into \"test\" values(\"hello world\",\"666\");'"
do shell script sql
You can use this example to create your own scripts dynamically.

Does SQLDeveloper support executing scripts?

I was trying to follow some instructions today, and it starts with the comment
REM In SQLPlus I manually copy in each line and execute it.
That's nice, I don't have SQLPlus, I have SQLDeveloper. The lines that were pasted in were of the type:
#\\server\dir\dir\dir\commandfile1.txt;
COMMIT;
...etc.
It didn't like it when I tried that in a SQL window. I opened up and pasted in the commands by hand, and it wasn't happy with that either. (Did I mention that I'm not so good with this application nor Oracle, but that everyone else was out today?) The files there started with code like:
rem
set echo on
rem
execute procedure_name ('parameter1', 'parameter2');
A co-worker did have SQLPlus, and together we got it resolved. But, is there a way for me to do this with SQLDeveloper, so I'm not stuck if he's out too?
To run scripts in SQL Developer:
#"\Path\Scriptname.sql"
(You only need the quotes if there are any spaces)
You can set a default Path: Tools menu > Preferences > Database > Worksheet > Select default path to look for scripts
I was looking through the help files and found how to do it in SQL Developer Concepts and Usage->Using the SQL Worksheet->Script Runner.
Basically, you have to precede the file name with an #. For example #C:\MyScript\Script.sql.
You can then run a batch of them this way. Note that the command doesn't seem to like spaces in the file path.
For each file you need to run, find it and drop it into SQLDeveloper. Run the script (F5) and then commit (F11). This will work for some scripts, but not all.
SQL Developer these days comes with another tool called sqlcl. This is a bit like SQLPlus but is actually using some bits from SQL Developer to give a compatible command line/scripting type interface.
You would be able to use it to execute sqlplus style commands without fighting the extras of the SQL Developer style GUI which can get confusing.
Look for it under wherever SQL Developer is sitting. If you don't have it there, you can download it and deploy it into your sqldeveloper folder.
you can do it using sqlcl in the same way how you would do it using SQL PLUS, from command line:
sqlcl user/password#host:port:sid #file.sql
file should be in the same directory where sqlcl is.
This solution is the best option if you are trying to execute a lot of instruction on sql file.
This would do it:
begin
procedure_name ('parameter1', 'parameter2');
end;
/

Resources