Sql script in UNIX
When I run a sql script in unix using sqlplus command, the process halts at some point. No matter how long I wait, it does not finish (it does not bring the command prompt back). There are no problems in SQL*PLUS. This process usually takes about 30 mins when I run from SQL * PLUS. Any ideas why it hangs in UNIX?
sqlplus -s userid @script
Thanks
Are you specifying a password ?
Have you set the ORACLE_SID ?
Similar Messages
-
Running sql script from unix using
Hello!
When i run the following sql, it doesn't executes any statement after the 1st SQL.
anyone know the reason?
#!/bin/bash
set -x
echo test
sqlplus /nolog << EOF
set serveroutput on size 1000000
conn userid/pwd@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=10.92.xxx.xxx)(Port=1521))(CONNECT_DATA=(SID=oradbid)))
select '1st sql output' from dual;
exit
EOF.
sqlplus /nolog << EOF
set serveroutput on size 1000000
conn userid/pwd@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=10.92.xxx.xxx)(Port=1521))(CONNECT_DATA=(SID=oradbid)))
select '2nd sqloutput' from dual;
exit
EOF
--------------------------------You have to remove . (dot) after first EOF.
Best regards
Maxim -
Passing UNIX command in SQL Script
Hi,
I am writing a sql-script in unix.
The logic is as below:
SELECT flag FROM dummy_table;
If flag = Y Then
cp ./abc.txt $HOME/abc.txt
Else
SELECT id, roll FROM employees;
Please help me out.
Thanks and Regards,
TonyI did that way:
Under SYS create the following procedure:
CREATE OR REPLACE PROCEDURE SYS.LINUX_RUN (PATH IN VARCHAR2,
result OUT VARCHAR2)
IS
script_file VARCHAR2 (40) := 'my-temp-script.sh';
script_data VARCHAR2 (4000);
MyFile UTL_FILE.file_type;
d VARCHAR2 (4000);
dump_file VARCHAR2 (40) := '/tmp/my-temp-file.dat';
dump_type UTL_FILE.file_type;
BEGIN
pms.post_calls;
-- Open file
MyFile := UTL_FILE.fopen ('TMP', script_file, 'w');
-- Write data to file
script_data := PATH || ' > ' || dump_file;
UTL_FILE.put_line (MyFile, script_data, FALSE);
-- Close file
UTL_FILE.fflush (MyFile);
UTL_FILE.fclose (MyFile);
-- Purge old logs, no fun anyway
DBMS_SCHEDULER.purge_log (JOB_NAME => 'TEST');
-- Execute script
-- The job is created as disabled as
-- we execute it manually and will
-- drop itself once executed.
DBMS_SCHEDULER.create_job (job_name => 'TEST',
job_type => 'EXECUTABLE',
job_action => '/bin/sh',
number_of_arguments => 1,
start_date => SYSTIMESTAMP,
enabled => FALSE);
DBMS_SCHEDULER.set_job_argument_value ('TEST', 1, '/tmp/' || script_file);
DBMS_SCHEDULER.enable ('TEST');
-- Wait for the job to be executed
-- usually done within 1 second but
-- I set it to 2 just in case.
DBMS_LOCK.sleep (2);
-- Open the output file and
-- print the result.
dump_type := UTL_FILE.fopen ('TMP', dump_file, 'r');
UTL_FILE.get_line (dump_type, d);
result := d;
LOOP
BEGIN
UTL_FILE.get_line (dump_type, d);
DBMS_OUTPUT.put_line (d);
EXCEPTION
WHEN OTHERS
THEN
EXIT;
END;
END LOOP;
UTL_FILE.fclose (dump_type);
-- Clean up our temp files
UTL_FILE.fremove ('TMP', script_file);
UTL_FILE.fremove ('TMP', dump_file);
END;
/And grant execute on this procedure to end user.
Then under granted user you can use this procedure in your PL/SQL code.
It works just fine for me :)
Good luck. -
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> -
Please add exit to the last line of the sql script
Hi,
I am executing a sql script from UNIX shell. When I execute it at the command prompt the script executes successfully, but when I schedule the script on cron, the script is throwing an error with the above message
"Please add exit to the last line of the sql script"
Any idea what is happening? Thanks in advance for any help
thedbaIt works check this out..
<< script a.sh >>
logfile=/home/oracle/sri/x.log
sqlplus -s /nolog <<DOC >> ${logfile}
whenever sqlerror exit sql.sqlcode
connect scott/tiger
@a.sql a.log
DOC
<< script a.sql >>
set feedback off
set echo off
spool &1
select * from tab where tname like 'A%';
spool off
exit;
<< a.log >>
TNAME TABTYPE CLUSTERID
AQ$DEF$_AQCALL VIEW
AQ$DEF$_AQERROR VIEW
AQ$_DEF$_AQCALL_F VIEW
AQ$_DEF$_AQERROR_F VIEW
AQ$_INTERNET_AGENTS TABLE
AQ$_INTERNET_AGENT_PRIVS TABLE
AQ$_QUEUES TABLE
AQ$_QUEUE_TABLES TABLE
AQ$_SCHEDULES TABLE
<< x.log >>
TNAME TABTYPE CLUSTERID
AQ$DEF$_AQCALL VIEW
AQ$DEF$_AQERROR VIEW
AQ$_DEF$_AQCALL_F VIEW
AQ$_DEF$_AQERROR_F VIEW
AQ$_INTERNET_AGENTS TABLE
AQ$_INTERNET_AGENT_PRIVS TABLE
AQ$_QUEUES TABLE
AQ$_QUEUE_TABLES TABLE
AQ$_SCHEDULES TABLE-Sri -
Unix command into a pl/sql script
Could you tell me how to run a unix command (cp, rm, mkdir....)
into a pl/sql script ?sigh this is an old chestnut. it can only be done using a java stored procedure. the instructions for doing this can be found in old postings on this forum - use the Search facility. alternatively try the AskTom site, and Metalink posted a solution as well.
rgds, APC -
Spool Russian Characters from a unix(AIX) sql script
Hi All,
I have a problem selecting and spooling a column whose characters are in russian to a flat file. If I use oracle sql developer, the data comes out right, e.g
Р-Н ТАШКЕНТ
However is i try to run the same select from a unix sql script and spool the results, I get some gibberish like:
ò-î ôáûëåîô or a chain of question marks ?????????
select * from nls_database_parameters gives:
NLS_LANGUAGE=AMERICAN
NLS_TERRITORY=AMERICA
NLS_CHARACTERSET=UTF8
NLS_NCHAR_CHARACTERSET=AL16UTF16
I have tried exporting the environment variable using these various options individially to no avail:
export NLS_LANG=RUSSIAN_CIS.CL8MSWIN1251
RUSSIAN_RUSSIA.RU8PC866
RUSSIAN_RUSSIA.CL8KOI8R
RUSSIAN_RUSSIA.CL8MACCYRILLICS
RUSSIAN_RUSSIA.RU8PC855
RUSSIAN_RUSSIA.RU8BESTA
RUSSIAN_RUSSIA.CL8ISO8859P5
Please help.
Thanks,
Edited by: HouseofHunger on Apr 12, 2012 4:02 PMOs version: AIX 6.1.0.0
Database version: Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bit
with the default values for NLS_LANG, I run sqlplus
sqlplus user/password@oracle_sid
select column_name from table_name;
and the output is:
column_name
I exit and export NLS_LANG=RUSSIAN_CIS.CL8ISO8859P5
go back into sqlplus and run the same query as above, and the output is
column_name
À-½ °Ⱥµ½Â
À-¾½ ÃÀ°ǸÀǸºÁº¸¹
°Ⱥµ½Â
°Ⱥµ½Â
¾»Â¸½¾¹ À-¾½
³ ±µº°±°´
ΠǸÀǸºÁº¸¹ À-½ ÷±µº¸ÁÂ
Ä°À³¾½°
Ϻº°Á°À°¹Áº¸¹
°Ⱥµ½Â
Á°¼°Àº°½´
So it seems the output I get is somehow influenced by the value of environment variable NLS_LANG, so it may be that either I need the correct value for this environment variable or I need some config on the OS level.....?
Also the command locale -a gives following output - I am not very good on locales, so it maybe that the russian local isn't installed...?
$ locale -a
C
POSIX
en_US.8859-15
en_US.ISO8859-1
en_US
Thanks -
SQL script runs under SQL Devoper, will not run under UNIX, SQLPlus
I have a sql program I developed under the SQL Developer tool and it runs fine. I have ftp'd the sql to the Unix server and I am trying to run the same program under SQL Plus in unix. The program echo's back the line number that is the last line number in the code before the 'Exception' code in the program and it goes out into never never land.
I can't figure out why this runs under SQL Developer but will not run under SQLPlus in Unix. Any ideas would be appreciated!!!!Assuming that the ftp process did not append any invisible characters(which it usually does) at the end of each line,
did you put the '/' symbol at the end of your program before running in sql*plus
something like
begin
end;
/ -
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 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 -
SQL script based on hostname and database name?
I am trying to write a script that I can run on several unix servers and databases that will do different sql statements based on which server and database it is being run in.
Something like:
if hostname = 'A' and database name = 'D' then do this
else if hostname = 'B' and database name = 'F' then do that
I have tried many diifferent combinations of shell scripts and sql scripts but can't seem to get anything that works.
Can someone help me out? Thanks.Since you are already able to get he db and host info, you are well on your way to branching based on that information. All you need is the basic framework:
declare
db VARCHAR2(30);
host VARCHAR2(30);
sqlcmd VARCHAR2(4000);
begin
select sys_context('userenv','host') host
, sys_context('userenv','db_name') db_name
into host
, db
from dual;
case
when db = 'XE' and host = 'mypc' then
sqlcmd := q'[local_package.do_something('parm1', :db, :host)]';
execute IMMEDIATE sqlcmd USING db, host;
when db = 'DEV' and host in ('serv1','serv2') then
sqlcmd := q'[different_packge.do_something('parm1', :db, :host)]';
execute IMMEDIATE sqlcmd USING db, host;
else
dbms_output.put_line('unrecognized db/host combination: '||db||', '||host);
end case;
end;
/In this example I've used dynamic SQL since not all instances are guaranteed to have any or all of the package procedures referenced in the dynamic sql. With out the dynamic sql, you would get errors and be unable to run the script on any instance lacking one or more of the reference package procedures.. -
SQL Script working differently with 8i and 9i
Hi
I am facing strange problem with my simple SQL script called from a shell script. It bahaves differently with ORACLE 8.1.7.4 and 9.2.0.1. The machine is same.
sqlplus -s / @Tech.sql WKC625 11 11 '11 22' ""
This is working with 9i but it does't work with ORACLE 8.
Actually what happens is that the argument in single quotes (') is taken as 2 separate argument.
The Tech.sql is :
spool add
insert into TECH values ('&1','&2','&3','&4','&5','');
commit;
quit
I tried putting double quotes also. Is something got changes between ORACLE 8 and 9i.
Please help
SurendraAre you sure it works in 9?
If you are using UNIX, then the O/S will strip the quotes while processing the arguments. You need to use 2 single quotes around 11 22, just as you have around the empty string at the end.
I believe that Windows does the same, but I do not use windows.
John -
Execute SQL scripts in Oracle DB
Hi ,
Can someone give stepbystep flow to execute sql scripts(patches) in oracle db on unix server.SQL scripts and patches are generally two completely different things.
Assuming you are referring to patches that you download from My Oracle Support (MOS), each patch and patchset comes with a README. That README has specific instructions for installing that particular patch in whatever version of Oracle you have running on whatever operating system you have with whatever database options you have in use. It wouldn't make sense to try to summarize that document here-- we would undoubtedly leave something out that may be important to you and there may be patch-specific instructions.
Justin -
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. -
Running the same sql script in multiple databases
Hello,
What is the method to run the same sql script in multiple databases? I want to write a unix script that would select from different databases and run a sql/plsql script in those different databases. What are the ways to write such a unix script? Thank you in advance.Just have a parameter which takes in the oracle connection parameters and use it in your sqlplus script with your shell script.
Your sqlplus script can have a procedure/function call or an anonymous block;
Then have a wrapper script to call the original script with different connection parameters. Hope this helps.
Maybe you are looking for
-
How do I get Adobe to respect my privacy?
I know for a fact I have repatedly told Adobe to stop harassing me with promos, news, sales, etc. Adobe engages in the practice of assuming that communication with them and/or the download of their trial software constitutes re-acceptance to being a
-
My Laptop screen has gone Dark
I have a Lenovo Ideapad Z500, Intel I7, 3612QM, 6GB Ram with an Nvidia GT740M Graphic Card. My display was absolutely fine, till I installed Windows 8.1. After a few minutes of working properly, the laptop screen went dark. I have installed all avail
-
Indeterminate progressbar freezes when executing thread
Hi people, Here is my problem. In my GUI application, at some point the user needs to perform a time consuming application. I want to tell the user that the task is performing as it is supposed to by displaying an undeterminate progressbar. However,
-
Omit notes during MIDI recording that are not in defined scale
I'm looking for a way to do the following in Logic, but am not sure how to set this up. I want to be able to: 1. Create a new midi track 2. In selected midi track, select a scale (for example, Pentatonic Minor) 3. Press record 4. During recording, on
-
Media Encoder crashing when I try to batch a bunch of files
I am trying to have the Media Encoder batch convert a bunch of files, but when I try to add the files, the whole program crashes, or when it's on the first few files, it crashes. Any suggestions?