Can anyone please tell me the exact meaning/significance of #forecast2.sql in below query , the given query is a part of one shell script. Also how can I find the exact sql query executed by #forecast2.sql
Below is the code:
sqlplus -s / #forecast2.sql $SCHED_ID > /tmp/BR_forecast
I need to find the sql query that's been executed here.
This means that sqlplus will execute script called forecast2.sql.
You could locate it:
> env | grep SQLPATH
-- path where scripts are located
Related
I have several PL/SQL scripts that are transforming data accoriding to specification day by day. I would like to run them in the loop for each day of the year. Is this possible to handle somehow in Toad?
I have found that I can run some other scripts by calling them via #name_of_script , but it doesn't work for me in Toad.
I just need something like:
BEGIN
FOR i IN day1 TO dayx
EXECUTE SQL1;
EXECUTE SQL2;
EXECUTE SQL3;
END LOOP;
END
Is there any way how to run these scripts somehow "managed" except to change them to procedures? Thank you for answer.
# is an SQLPlus command
But toad partially supports it too: there are 2 common options:
Use SQL Editor - it should execute scripts in case of # command as in SQL*Plus
Use "Execute as script" --> "Execute via SQL plus": it should start SQL*plus connected to your database, there you can run your scripts.
I have been able to run an SQL script script.sql from within SQL Plus as follows:
SQL>#script.sql
I did that after starting SQL Plus and logging from within Powershell in as follows:
C:\projects\temp> sqlplus myuser/mypassword#my.tns.address
Now what I'd like to do is run the script above directly from Powershell. It is my understanding that I should be able to do that like this:
C:\projects\temp> sqlplus myuser/mypassword#my.tns.address script.sql
I expected this to work fine, especially considering I'm using the same user and password, the same TNS, and calling the same script.
Instead of running the script however, all this command does is output the Help-text for SQL Plus, i.e. the same text that is shown when running sqlplus -H.
I'm assuming there is some syntax error, or something else wrong with the command above, but the problem is finding out what that error is.
Is there something obviously wrong with the last command above? Or is there some way for me to turn up the verbosity, so that I can get a hint about what could be wrong?
The "#" is missing to invoke the script. Try this instead
C:\projects\temp> sqlplus myuser/mypassword#my.tns.address #script.sql
Suppose I want to display the result of a simple SQL query, say SELECT * FROM dual; that is executed in SQL developer and get the result in unix server using a simple command. I do not want to use scripts to get the result. Hoping to use a single line command. I already tried using the isql command, but that is not working.
echo "select * from dual" | isql -v dbname userid hostname
Please help me.
I have the following problem, I need to put in a script that is going to run before the new version is rolled the SQL code that enables the pgAgent in PostgreSQL. However, this code should be run on the maintenance database (postgres) and the database where we run the script file is another one.
I remember that in SQL Server there is a command "use " so you could do something like:
use foo
-- some code
use bar
-- more code
is there something similar in PostgreSQL?
You can put in your file something like:
\c first_db_name
select * from t; --- your sql
\c second_db_name
select * from t; --- your sql
...
Are you piping these commands through the psql command? If so, \c databasename is what you want.
psql documentation
You can't switch databases in Postgres in this way. You actually have to reconnect to the other database.
PostgreSQL doesn't have the USE command. You would most likely use psql with the --dbname option to accomplish this, --dbname takes the database name as a parameter. See this link for details on the other options you can pass in you will also want to check out the --file option as well. http://www.postgresql.org/docs/9.0/interactive/app-psql.html
well after looking on the web for some time I found this which was what I need it
http://www.postgresonline.com/journal/archives/44-Using-DbLink-to-access-other-PostgreSQL-Databases-and-Servers.html
I have an oracle script that I am trying to convert to valid db2 syntax. Within this sql file I have various calls to other sql files passing in a parameter using the '#' syntax.
e.g.
#script1 param1
#script2 param2
Can anyone help me with valid db2 equivalent statements? Is there an equivalent run command in db2? is it possible to pass parameters to a sql script in db2?
thanks,
smauel
The thing you are after is the DB2 Command Line Processor (CLP).
If you want to execute a script, you would execute in the CLP:
db2 -vtf script1
-f tells the CLP to run command input from the given file.
Here's the full list of options.
Unfortunately db2 doesn't support passing parameters to a script. You would have to combine your db2 -vtf commands with other scripting commands (such as sed) to generate the scripts for you, as in this example.
1) place the filename.sql file in SQLLIB/BIN
2) run db2cmd
3) execute this to connect to the required db
db2 connect to *dbname* user *userid* using *password*
4) excute this command
db2 -vtf *filename.sql*
This should execute the sql statements in the file one by one. The sql statements must be ending with a semicolon
There is an easier way for passing in parameters, that works fine for us (it might not work with (complex) multiline sql statements).
Convert your sql-script into a shell script by adding 'db2 ' at the beginning of each line. Than you can use the standard variable replacement syntax from your shell in your scripts.
so instead of
insert ...
update ...
you will have
db2 insert ...
db2 update ...
Place file in one directory.
Open db2cmd.exe as administrator
Navigate to directory where you have place the script
type db2 -vtf `