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
I have a .bat file in which I insert data from csv to oracle using sqlldr but when I double click .bat file nothing happen.
But when I copy that in cmd and run it executes the data.
I don't know what happen any path mistake or anything.
Batch file
P:\Users\ashique.sheikh\VMI>sqlldr upi/upi DATA=P:\Users\ashique.sheikh\VMI\test.csv CONTROL=Insert.ctl LOG=Insert.log.
CTL File
OPTIONs(SKIP=1)
LOAD DATA
INFILE "P:\Users\ashique.sheikh\VMI\test.csv"
INSERT into table DETAIL
REPLACE
fields terminated by ','
(ID,NAME,ADDRESS,CITY,MOBILE)
try to use this line in the bat file:
start "" cmd.exe /c sqlldr upi/upi DATA=P:\Users\ashique.sheikh\VMI\test.csv CONTROL=Insert.ctl LOG=Insert.log
Some WinodwsXP has a problem as different SET variables when you run cmd.exe and another when you run .bat file. It was antivirus sandbox or something etc.
Try adding the path to the ctl parameter too. I'm afraid windows searches the path for insert.ctl and it doesn't find it.
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
Microsoft Sql Server has a command line tool called sqlcmd.exe.
You can use it to deploy .sql scripts.
I have googled and binged and found many Oracle command line tools, but I have yet to find one that will deploy a sql package.
Here is a simple example:
sqlcmd.exe -i .\MySqlScript.sql -S "MySqlServerMachine\MyInstancenName" -E -o ".\MyOutputLogFileName.txt"
The command line will run the file "MySqlScript.sql" against a Sql Server (Instance) named "MySqlServerMachine\MyInstancenName" using integrated security ("-E") and output the results to a file named "MyOutputLogFileName.txt".
Is there a Oracle version of this tool?
I found oradim, but it is unclea if it runs a .sql script.
Based on parado's response, I found the below URL:
http://docs.oracle.com/cd/B25329_01/doc/appdev.102/b25108/xedev_sqlplus.htm#CJAGIECA
Yes, there is a Sql*Plus:
sqlplus user/pass#connect #scriptname
If you want output file, add to your script:
spool log.out
How does one change the current directory in SQL Plus under windows.
I am trying to write a script with several "# filename" commands.
I know that one can open a script with the File --> Open command, which will change the current directory, but I am looking for a way to do this automatically unattended.
Resolution
Based on Plasmer's response, I set the SQLPATH environment variable in Windows, and got something that's good enough for me. I did not try to set it with the HOST command (I doubt that it will work).
Pourquoi Litytestdata's answer is a good one, but will not work for me (the directories are too far apart). And of course Guy's answer that it cannot be done is also correct. I will vote these two up, and accept Plasmer's answer.
Here is what I do.
Define a variable to help you out:
define dir=C:\MySYSTEM\PTR190\Tests\Test1
#&dir\myTest1.sql
You can't cd in SQL*Plus (you can cd using the host command, but since it is a child process, the setting won't persist in your parent process).
I don't think that you can change the directory in SQL*Plus.
Instead of changing directory, you can use ##filename, which reads in another script whose location is relative to the directory the current script is running in. For example, if you have two scripts
C:\Foo\Bar\script1.sql
C:\Foo\Bar\Baz\script2.sql
then script1.sql can run script2.sql if it contains the line
##Baz\script2.sql
See this for more info about ##.
Could you use the SQLPATH environment variable to tell sqlplus where to look for the scripts you are trying to run? I believe you could use HOST to set SQLPATH in the script too.
There could potentially be problems if two scripts have the same name and both directories are in the SQLPATH.
I don't think you can!
/home/export/user1 $ sqlplus /
> #script1.sql
> HOST CD /home/export/user2
> #script2.sql
script2.sql has to be in /home/export/user1.
You either use the full path, or exit the script and start sqlplus again from the right directory.
#!/bin/bash
oraenv .
cd /home/export/user1
sqlplus / #script1.sql
cd /home/export/user2
sqlplus / #script2.sql
(something like that - doing this from memory!)
With Oracle's new SQLcl there is a cd command now and accompanying pwd.
SQLcl can be downloaded here: http://www.oracle.com/technetwork/developer-tools/sqlcl/overview/index.html
Here's a quick example:
SQL>pwd
/Users/klrice/
NOT_SAFE>!ls *.sql
db_awr.sql emp.sql img.sql jeff.sql orclcode.sql test.sql
db_info.sql fn.sql iot.sql login.sql rmoug.sql
SQL>cd sql
SQL>!ls *.sql
003.sql demo_worksheet_name.sql poll_so_stats.sql
1.sql dual.sql print_updates.sql
SQL>
Have you tried creating a windows shortcut for sql plus and set the working directory?
I think that the SQLPATH environment variable is the best way for this - if you have multiple paths, enter them separated by semi-colons (;). Keep in mind that if there are script files named the same in among the directories, the first one encountered (by order the paths are entered) will be executed, the second one will be ignored.
Years later i had the same problem. My solution is the creation of a temporary batchfile and another instance of sqlplus:
In first SQL-Script:
:
set echo off
spool sqlsub_tmp.bat
prompt cd /D D:\some\dir
prompt sqlplus user/passwd#tnsname #second_script.sql
spool off
host sqlsub_tmp.bat
host del sqlsub_tmp.bat
:
Note that "second_script.sql" needs an "exit" statement at end if you want to return to the first one..
for me shelling-out does the job because it gives you possibility to run [a|any] command on the shell:
http://www.dba-oracle.com/t_display_current_directory_sqlplus.htm
in short see the current directory:
!pwd
change it
!cd /path/you/want