Trouble calling .sql script
I have looked on the forum for about a half an hour and can't find the exact answer I'm searching for, so here goes.
I'm trying to update about a 100 records or so through use of an .sql script.
I put the following in my sql script file
UPDATE TABLE1 SET COL_NAME1 = 'some val.', COL_NUM_VAL = 12345, BOOL_VAL_COL = -1
WHERE AUTOID = 9554 OR AUTOID = 1082
OR AUTOID = 1305 OR AUTOID = 133
OR AUTOID = 9124
OR AUTOID = 8712
OR AUTOID = 55 OR AUTOID = 6741 OR AUTOID = 9881
OR AUTOID = 1012 OR AUTOID = 9158 OR AUTOID = 9378
OR AUTOID = 9101 OR AUTOID = 8351 OR AUTOID = 7110 OR AUTOID = 922 OR AUTOID = 732
OR AUTOID = 7253 OR AUTOID = 7825 OR AUTOID = 6772 OR AUTOID = 9854;
commit;however, I get some kind of message back in the SQL Plus prompt showing.
8 OR AUTOID = 9101 OR AUTOID = 8351 OR AUTOID = 7110 OR AUTOID = 922 OR AUTOID = 732
9 OR AUTOID = 7253 OR AUTOID = 7825 OR AUTOID = 6772 OR AUTOID = 9854
10* commit;
11 /I can't really discern from this output stmt what happened or what is wrong,
and needless to say, the update query doesn't execute. Any ideas as to what I need to put in there? And can't I just open it up in SQL Plus after I've created the sql file?Or is there more to it than that?
I welcome any feedback.
Thanks!
Message was edited by:
user515689
Hi,
If you have a file called foo.sql that contains just the 10 lines of code that you posted, then you can run it from SQL*Plus by saying "@foo" (depending on where foo.sql is stored. You may actually have give the full path name: e.g.
SQL> @c:\my_folder\sub_folder\fooWhat are you doing to run the script?
By the way, instead of all those ORs you can use the IN operator:
UPDATE TABLE1 SET COL_NAME1 = 'some val.', COL_NUM_VAL = 12345, BOOL_VAL_COL = -1
WHERE AUTOID IN (9554, 1082, 1305, ..., 9854);
Similar Messages
-
How to call SQL Script in DBMS_SCHEDULER
How to call SQL Scripts in DBMS_SCHEDULER?
Things I got working
1) Successfully created and tested a PL/SQL that was created under SQL Workshop->SQL Scripts (I named it 'TEST'). I was able to run this no problem.
2) Successfully created a DBMS_SCHEDULER that runs every minutes. (See below)
begin
dbms_scheduler.create_job(
job_name => 'myjob',
job_type => 'plsql_block',
job_action => 'null;',
start_date => '19-JUL-11 03.10.00 PM', /* Remember to use the DB time, not your local time if not specifying a timezone */
repeat_interval => 'freq=minutely',
enabled => true);
end;The problem i am having is to make the PL/SQL script (named 'TEST') runs every minute. Its probably very easy to do that but i dont seems like finding any examples online.
I tried replacing the job_action attribute to " job_action => 'begin TEST; END;', " However, that did not work.
I am stuck here for couple hours already, any clues would be great :)
Thanks in advance
John
Application Express 4.1.0.00.32
Edited by: John Lau on Aug 14, 2012 12:47 PM
Edited by: John Lau on Aug 14, 2012 12:48 PMThe PL/SQL is pretty long, I would like to call it from a different location rather then putting the whole coding as part of the argument. Sounds like I should be looking into procedure package in database?
I will do some more research on procedure package, how to create one and how to call from it.
Thanks
John -
Shell script to call sql script
Hi All,
I have a application server and want to make a shell script to call sql script.
Please let me know how to do the same.
Regards
KumarWhat is the platform you are using and you can give the path of the sql script in your shell script as follows
1.)first create .sql file...let it is table.sql and has the contents ...
create table test(x1 varchar2(20),x2 number(4),x3 date)
exit;
(2.) write a shell script...like table.sh in vi editor
Here login is scott/tiger@sid, or apps/apps@sid or whatever you know valid schema
echo enter the login
read login
sqlplus -s $login @table
(3.)run the script
$ sh table.sh
it will create the table in your particular schema -
Calling sql script in a folder
Hi All,
I'm calling a SQL script from a root SQL script which is present in a sub folder.
root.sql
Prompt Loading FULL_RECOMPILE.SQL
SET DEFINE OFF
@@Utils\FULL_RECOMPILE.SQL
SET DEFINE ON
Show errors
commit;When I run the script I'm getting the following error.
SP2-0310: unable to open file "UtilsFULL_RECOMPILE.SQL".
I tried using forward / (@@Utils/FULL_RECOMPILE.SQL) and the script executed succesfully.
Is there anyway I can execute the above script by using a backward slash?
BANNER
Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
Thanks,
guru
Edited by: guru on 30-Jun-2010 05:54Your requirement seems to be executing the script present in the path:
*./Utils/FULL_RECOMPILE.SQL*
Is there anyway I can execute the above script by using a backward slash?Whats the need for using a backslash? Unix paths are separated by forward slash in contrast to windows. -
Calling sql script from pl/sql block
Hi
I want to call a sql script from pl/sql block.
like
CREATE OR REPLACE procedure DataBaseExport(user_name in varchar2, pwd in varchar2)
as
begin
execute immediate '@ C:\Documents and Settings\umesh\emp.sql';
end DataBaseExport;
/Try something like this -
CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
import java.io.*;
public class Host
public static void executeCommand(String command)
try {
String[] finalCommand;
if (isWindows())
finalCommand = new String[4];
// Use the appropriate path for your windows version.
finalCommand[0] = "C:\\windows\\system32\\cmd.exe"; // Windows XP/2003
//finalCommand[0] = "C:\\winnt\\system32\\cmd.exe"; // Windows NT/2000
finalCommand[1] = "/y";
finalCommand[2] = "/c";
finalCommand[3] = command;
else
finalCommand = new String[3];
finalCommand[0] = "/bin/sh";
finalCommand[1] = "-c";
finalCommand[2] = command;
final Process pr = Runtime.getRuntime().exec(finalCommand);
pr.waitFor();
new Thread(new Runnable()
public void run()
BufferedReader br_in = null;
try
br_in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String buff = null;
while ((buff = br_in.readLine()) != null)
System.out.println("Process out :" + buff);
try {Thread.sleep(100); } catch(Exception e) {}
br_in.close();
catch (IOException ioe)
System.out.println("Exception caught printing process output.");
ioe.printStackTrace();
finally
try {
br_in.close();
} catch (Exception ex) {}
).start();
new Thread(new Runnable()
public void run()
BufferedReader br_err = null;
try
br_err = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
String buff = null;
while ((buff = br_err.readLine()) != null)
System.out.println("Process err :" + buff);
try
Thread.sleep(100);
} catch(Exception e) {}
br_err.close();
catch (IOException ioe)
System.out.println("Exception caught printing process error.");
ioe.printStackTrace();
finally
try
br_err.close();
catch (Exception ex) {}
).start();
catch (Exception ex)
System.out.println(ex.getLocalizedMessage());
public static boolean isWindows()
if (System.getProperty("os.name").toLowerCase().indexOf("windows") != -1)
return true;
else
return false;
CREATE OR REPLACE PROCEDURE Host_Command (p_command IN VARCHAR2)
AS LANGUAGE JAVA
NAME 'Host.executeCommand (java.lang.String)';
--- THE PERMISSIONS ---
call dbms_java.grant_permission('SYSTEM', 'SYS:java.io.FilePermission', '<<ALL FILES>>', 'read ,write, execute, delete');
call dbms_java.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
call dbms_java.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');And, finally,
create or replace procedure call_sql_file(usr in varchar2,
pwd in varchar2,
host_str in varchar2)
is
begin
host('sqlplus -s usr/pwd@host_str C:\UAX_Auto_Count.sql');
exception
when others then
dbms_output.put_line(sqlerrm);
end;Now, you can pass all the argument in order to execute that file.
N.B.: Not Tested...
Regards.
Satyaki De. -
Calling sql script from shell script
Hi,
I know this question has been asked many time in various forums, but I tried many combinations and not able to figure out what I'm missing.
Basically - I'm trying to call a sql script from a shell script.
This is my sql script (plsql.sql) -
DELCARE
v_empno NUMBER := '&empno';
BEGIN
select ename,sal from emp where empno = v_empno;
dbms_output.put_line('Inside the plsql file');
END;
This is my unix shell script - I'm caling the plsql.sql file with the parameter passed(97882). I don't get any output. at least I should be able to view the dbms output if not for the sql query inside the sql script.
#!/usr/bin/ksh
sqlplus -s sam/olo01 << HERE
@plsql.sql 97882;
HERE
What is it I am missing ?Using your scripts (and having to create and populate a table myself, that would have what your select statement implies),
oracle:oklacity$ cat plsql.sql
DELCARE
v_empno NUMBER := '&empno';
BEGIN
select ename,sal from emp where empno = v_empno;
dbms_output.put_line('Inside the plsql file');
END;
oracle:oklacity$ cat doit.sh
#!/usr/bin/ksh
sqlplus -s sam/olo01 << HERE
@plsql.sql 97882;
HERE
oracle:oklacity$ ./doit.sh
SP2-0042: unknown command "DELCARE" - rest of line ignored.
SP2-0734: unknown command beginning "v_empno NU..." - rest of line ignored.
oracle:oklacity$
This is the kind of information you should have put in your opening post. -
Not able to call sql script from shell program
Hi Gurus,
I am facing issue while calling sqlplus script from my shell program. Please find below my shell script. This program I've written and registered as for one of concurrent program
in oracle applications.
p_userid_passwd=$1
p_appl_login=$2
p_user_name=$3
p_request_id=$4
v_conc_request_id=${5}
p_to_role=${6}
p_from_role=${7}
p_subject=${8}
p_body=${9}
p_dist_list=${10}
v_request=${11}
v_file_path_name=/u01/oraspt/REQUEST
cd $APPLCSF/$APPLOUT
echo "v_conc_request_id" $v_conc_request_id
echo "p_to_role" $p_to_role
echo "p_from_role" $p_from_role
echo "p_subject" $p_subject
echo "p_body" $p_body
echo "p_dist_list" $p_dist_list
echo "v_request" $v_request
ls -l $v_request
if [ $? -ne 0 ]
then
echo "No output request generated"
else
echo "Output request generated"
fi
echo "connecting to ftp for placing out file to DB server"
echo FTP to 99.60.17.11
echo username: "oraspt"
echo pw:
ftp -i -n 99.60.17.11 << EOF2
user "oraspt" orakdk
cd $v_file_path_name
put $v_request
bye
EOF2
output=`sqlplus -s /nolog <<EOT
whenever sqlerror exit failure;
connect apps/apps
set verify off;
set serveroutput on size 120000;
DECLARE
l_errbuf varchar2(300);
l_retcode varchar2(300);
BEGIN
XXFND_SEND_MAIL.SEND_NOTIFICATIONS( errbuf => l_errbuf
, retcode => l_retcode
, p_request_id => $v_conc_request_id
, p_to_role => $p_to_role
, p_from_role => $p_from_role
, p_subject => $p_subject
, p_body => $p_body
, p_dist_list => $p_dist_list);
EXCEPTION
when others then
dbms_output.put_line('Error encountered :'||SQLERRM);
END;
EOT
`
echo "connecting to ftp for deleting output file"
echo FTP to 99.60.17.11
echo username: "oraspt"
echo pw:
ftp -i -n 99.60.17.11 << EOF2
user "oraspt" orakdk
cd $v_file_path_name
delete $v_request
bye
EOF2
echo "Deleted successfully"Output for script is as below
v_conc_request_id 451906
p_to_role DC.DKHOO
p_from_role DC.DKHOO
p_subject Receivable audit report10
p_body Please find Audit Report Attachment.
p_dist_list
v_request o451906.out
-rw-r--r-- 1 applspt dba 2368 Dec 28 15:06 o451906.out
Output request generated
connecting to ftp for placing out file to DB server
FTP to 10.60.17.11
username: oraspt
pw:
connecting to ftp for deleting output file
FTP to 10.60.17.11
username: oraspt
pw:
Deleted successfullyPlease let me know how to trigger pl/sql script.
Thanks in advance for your help.
Regards
Nagendra
Edited by: 838961 on Dec 27, 2011 11:25 PMPlease find output as suggested, I've placed set -x in script.
+ p_userid_passwd=APPS/APPS
+ p_appl_login=1110
+ p_user_name=DC.DKHOO
+ p_request_id=451949
+ v_conc_request_id=451945
+ p_to_role=DC.DKHOO
+ p_from_role=DC.DKHOO
+ p_subject=Receivabless
+ p_body=report
+ p_dist_list=
+ v_request=o451945.out
+ v_file_path_name=/u01/oraspt/REQUEST
+ cd /u01/applspt/inst/apps/SPT_nfs-stg-app1/logs/appl/conc/out
+ echo v_conc_request_id 451945
v_conc_request_id 451945
+ echo p_to_role DC.DKHOO
p_to_role DC.DKHOO
+ echo p_from_role DC.DKHOO
p_from_role DC.DKHOO
+ echo p_subject Receivabless
p_subject Receivabless
+ echo p_body report
p_body report
+ echo p_dist_list
p_dist_list
+ echo v_request o451945.out
v_request o451945.out
+ ls -l o451945.out
-rw-r--r-- 1 applspt dba 2368 Dec 28 15:54 o451945.out
+ '[' 0 -ne 0 ']'
+ echo 'Output request generated'
Output request generated
+ echo 'connecting to ftp for placing out file to DB server'
connecting to ftp for placing out file to DB server
+ echo FTP to 10.60.17.11
FTP to 10.60.17.11
+ echo username: oraspt
username: oraspt
+ echo pw:
pw:
+ ftp -i -n 10.60.17.11
++ sqlplus -s /nolog
+ output=Connected.
+ echo 'connecting to ftp for deleting output file'
connecting to ftp for deleting output file
+ echo FTP to 10.60.17.11
FTP to 10.60.17.11
+ echo username: oraspt
username: oraspt
+ echo pw:
pw:
+ ftp -i -n 10.60.17.11
+ echo 'Deleted successfully'
Deleted successfully -
Calling sql script from anonymous block
Hi
how to call an script from an anonymous block, like
declare
v_reccord_account number :=0;
begin
SELECT xx.cc INTO v_reccord_account FROM
(select count(1) cc
from accounts
group by account_id
having count(account_id) > 1
)xx
where ROWNUM=1;
if v_reccord_account <1
then
dbms_output.put_line('no duplicates');
ELSE
< here i have to call this script -- @e:/test44.SQL >
end if;
end;Hi
thanks for replying, i'm having some sql statements, i have to spool the results of those statements .. below is the content of the file i'm calling.
=================================================
whenever sqlerror exit sql.sqlcode
set serveroutput on
column fn new_value filename
select 'remove_duplicates_'||to_char(sysdate, 'yyyymmddhh24miss')||'.log' as fn from dual;
spool E:/&filename
prompt 'Checking for duplicates'
--select account_id, count(1)
--from accounts
--group by account_id
--having count(1) > 1;
prompt 'Records to be deleted'
select *
from accounts
where decode ( substr(account_id,1,3),'COG',1,0)=1
group by account_id
having count(1) > 1;
prompt ' Deleting duplicates'
delete
from accounts
where account_id in (
select account_id
from accounts
where decode ( substr(account_id,1,3),'COG',1,0)=1
group by account_id
having count(1) > 1
commit;
========================================== -
How to call SQL script from PL/SQL block
Hi All,
I have a pl/sql block from which i need to call a *.sql script file.
Please tell me that how can i do this?
Thanks and Regards.> Though just for knowledge sake, would you please tell if there is a way
to call a sql script from a pl/sql block.
This question stems usually from a confusion about client-server and which is which in Oracle.
SQL*Plus is a client. PL/SQL is a server side language. SQL is a server side language.
When entering either one of these two languages in SQL*Plus (or TOAD, SQL-Developer, etc), the content is shipped to an Oracle server process, is parsed there, and is executed there.
The Oracle server process servicing the client can accept a single SQL statement or PL/SQL block at a time.
It cannot accept a block of SQL statements delimited with a semicolon. That is a client concept where the client will read each delimited statement and send that, one after the other (in synchronous call mode) to the Oracle server for execution.
The Oracle server does not have a "script parser". It understands SQL. It understands PL/SQL. And that is what it expects from the client.
Whether the client supports the SET command, the HOST command, SPOOL command, ability to run scripts, and so... have no bearing on what the server itself is capable of doing. The server does not care what feature set the client has. It is tasked with servicing the client via SQL and PL/SQL.
It is not tasked to support or emulate client features like running SQL scripts.
Nor confuse PL/SQL with the very limited command set of SQL*Plus. The two has nothing in common. And just as PL/SQL cannot understand C# or Delphi commands, it cannot understand SQL*Plus commands. -
Calling SQL scripts from subdirectories using SQL*Plus 9.2.0.1
Is it possible to run an SQL script that in turn calls other SQL scripts from subdirectories? This seemed to work fine using SQL*Plus 8.1.7
Did it break in 9.2.0.1?
Any fixes available?Ryan,
What exactly is your problem? Can you tell me any errors you are seeing? Platform?
Alison -
Calling sql script in plsql procedure
Hello,
I have a sql script named mytest.sql and i want to execute this from a stored procedure.
following is the contents of this script
spool d:\mytestsql.txt
select * from tab;
spool off
Actually i want my sql script to run daily to export some tables data.
I can execute this script from a sql prompt but i want to run it from enterprise manager.
I am using oracle 10gR2 on windows2000 system.
Any idea about scheduling the sql script to run automatically??
How to execute this sql script from a plsql procedure??
ThanksHi all,
Thanks for all the replies. I have found the solution with external procedures.
Following is the complete step by step guide.
1. Create the OSCommand Java Class using the following statement:
connect as any user:
create or replace and compile java source named oscommand as
import java.io.*;
public class OSCommand{
public static String Run(String Command){
try{
Runtime.getRuntime().exec(Command);
return("0");
catch (Exception e){
System.out.println("Error running command: " + Command +
"\n" + e.getMessage());
return(e.getMessage());
2. Create the following Wrapper Function using the following statement:
CREATE or REPLACE FUNCTION OSCommand_Run(Command IN STRING)
RETURN VARCHAR2 IS
LANGUAGE JAVA
NAME 'OSCommand.Run(java.lang.String) return int';
3. connect as sys
Execute dbms_java.grant_permission( 'FKHALID','SYS:java.io.FilePermission', '<<ALL FILES>>','execute');
execute dbms_java.grant_permission( 'FKHALID','SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '*' );
execute dbms_java.grant_permission( 'FKHALID','SYS:java.lang.RuntimePermission', 'readFileDescriptor', '*' );
commit;
note: here fkhalid is the oracle user.
connect as fkhalid user:
Declare
expdp_cmd Varchar2(2000);
Begin
expdp_cmd := OSCommand_Run('cmd /c sqlplus fkhalid@mtcedwt/pwd @d:\ORA_DUMPS\mydbexp.sql');
DBMS_OUTPUT.Put_Line(expdp_cmd);
End;
In Unix
Set Serverout On
Declare
x Varchar2(2000);
Begin
x := OSCommand_Run('/home/test/myoscommand.sh')
DBMS_OUTPUT.Put_Line(x);
End;
I will check the dbms_scheduler also and will let you know the results.
Thanks -
I just installed Oracle 10g Express on my laptop running Vista home premium.
I can not open the accompanying sql scripts, nor can I access the users table if I type the sql commands in the SQL editor on the home page, I get object does not exist. But I can pull up the users using the administration icon.
any ideas as to the issue?What do you mean by "opening the scripts"? Can you log in using sqlplus? Eg.
sqlplus / as sysdba
Try viewing the alert log to see if the database is started normally. -
Calling sql script through shell script
Hi All
I am trying to run one shell script it will execute the sql file which is in UNIX box. Problem here i am facing is
when i submit the program through front end it taking time to execute and the status in running even for hours and hours. Manually i am terminating the concurrent program.
But when same shell script when i tried to execute in putty it generating the output with in seconds
Can you help what may be the error? I used the syntax like this
Can you help what may be the error? need to change any syntax
Thanks
Prem Raj Dasari
Edited by: Sravprem on Sep 20, 2012 12:43 AMPl post details of OS, database and EBS versions. In your shell script, insert this line as the first line
set -xthen run the concurrent program and paste the contents of the log of the concurrent program here
HTH
Srini -
How to double dereference in sql scripts
hi all,
I wanted to call a sql file(sql2) from within an another sql file(sql1). The call to sql2 from sql1 contains some parameters( in form of integer and some variables). It is possible to access integer values in sql2 but i am unable to access the value stored in the variables in file2.
How to access the parameter's(which is itself is a variable) value in the called sql script.
Thanks,
ShyamDepending on your environment and if these are administrative (DBA) scritps or production batch then here are some ideas:
For DBA
Run the scripts via cron in a DBA privileged account
sqlplus /nolog <<EOF
connect / as sysdba
start script
exit
EOF
The above requires no password,
For production batch assuming that all production runs under one OS ID that access to is restricted then potentially you can use OS authentication so the Oracle username has no password: create user bob identified externally.
sqlplus / @script
will then do the job
HTH -- Mark D Powell -- -
How to run sql scripts using batch file for a web dynpro data dictionary
Hi,
I want to develop a sql script to be executed on the server alongwith the installation of a product to pre-populate web dynpro data dictionary tables required for the application.
I further require to make the scripts independent of the database name,so that it can be run at any client environment.
Your help will be appreciated and rewarded.See shoblock's answer
call sql script from unix
masterfile.sql:
@file1 &1
@file2 &2
@file3 &3
@file4 &4
then just call the master script:
sqlplus userid/password @masterfile <p1> <p2> <p3> <p4>
Maybe you are looking for
-
How to implement the Transfer Function in Real Time VIs?
Hi all, I'm relatively new to Labview Real Time modoule and want to implement one Controller(not PID one) in Deterministic Loop! I have already designed discrete Transfer Function and searching for the way to build one Controller with it! Is it right
-
IPod/Music App in iOS5 not sorting artist list alphabetically
Hello. I've got what it seems to be an annoying bug from the new Music App/iPod in iOS5. It simply sorts my artists out of alphabetical order on the artist dashboard. I tried to use the option "group by album artist" on and off and it seems to have n
-
Bug: Menu option "Build project" is disabled
I have "Build automatically" disabled due to the poor compiling performance of FB (my project has hundreds of classes), and have instead attached a key binding to "Build project" to trigger a build manually. Unfortunately this option is very often no
-
What is the secret to installing iTunes 10.5 on a Windows XP Pro machine?
While attempting to update iTunes 10.4.1.10 to version 10.5 on a Windows XP Pro machine (ver 2002, SP3), I get a recurrent error in the midst of the install: "There is a problem with this Windows Installer Package. A program run as part of the setup
-
Correct version for windows server 2008 Standard 64 bit
Hi could you help me to download the right version to install adobe reader in a machine running Windows server 2008 with 64 bit, since this machine doesn't have internet access I would need the offline installer but I don't know where to get it. Than