How to detect client OS from SQL*Plus script
Sometimes in a SQL*Plus script I need to execute OS commands e.g.
host rm tempfile.bufHowever of course Windows has no "rm" command by default, so I have to edit the script to use
host del tempfile.bufNow if I could define &DELETE (for example, "cat"/"type" is another) as a substitution variable, I could just use
host &DELETE tempfile.bufMaybe I need more coffee but all I could come up with was something like this:
def rm=rm
def cat=cat
spool sqlplus_windows_defs.cmd
prompt echo def rm=del
prompt echo def cat=type
spool off
host .\sqlplus_windows_defs > sqlplus_windows_defs.sql
@sqlplus_windows_defs.sql
host &rm sqlplus_windows_defs.cmd
host &rm sqlplus_windows_defs.sqlthe idea being that you first define the variables for nix ("rm" and "cat"), then attempt to create and execute a Windows command file containing DOS versions ("dele" and "type"), which does not run under nix. Unfortunately the OS failure message (".sqlplus_windows_defs: not found" in Unix) appears on the screen despite SET TERM OFF, so I'm back where I started.
I know there are various ways to get the server OS, and you can get the SQL*Plus version with &_SQLPLUS_RELEASE and so on, but I can't see a way to determine the client OS. Any suggestions?
Thanks guys. This seems to work in Windows XP - will try on Unix when I get a chance:
col DELETE_COMMAND new_value DELETE_COMMAND
col LIST_COMMAND new_value LIST_COMMAND
def list_command = TYPE
def delete_command = DEL
SELECT DECODE(os,'MSWIN','TYPE','cat') AS list_command
, DECODE(os,'MSWIN','DEL','rm') AS delete_command
FROM ( SELECT CASE WHEN UPPER(program) LIKE '%.EXE' THEN 'MSWIN' END AS os
FROM v$session
WHERE audsid = SYS_CONTEXT('userenv','sessionid') );
host &LIST_COMMAND xplan_errors.lst
host &DELETE_COMMAND xplan_errors.lstIf the user doesn't have access to v$session it will just default to the Windows commands.
http://www.williamrobertson.net/code/xplan.sql
Similar Messages
-
How execute this stored procedure from SQL PLUS???
Hello folks....
Help me please...
I have this procedure....
CREATE OR REPLACE PROCEDURE TEST(COD OUT VARCHAR2, NUM OUT
VARCHAR2, ID OUT VARCHAR2)
AS
BEGIN
END;
SO, I4D LIKE TO EXECUTE IT FROM SQL PLUS::
BUT, I DONT KNOW HOW TO DO..PLEASE SEND ME A SAMPLE..
THANK UThank u man!!!
look, my error before was :
SQL> set serveroutput on
SQL> declare
SQL> cod varchar2(100);
SQL> num varchar2(100);
SQL> id varchar2(100);
SQL> begin
SQL> TEST( cod, num, id );
SQL> EXEC DBMS_OUTPUT.put_line( cod || ' ' || num || ' ' ||
id );
SQL> end;
SQL> /
i put the EXEC....
thank u!!! -
How to return a value from sql plus activity
Hi,
I want to return a value from sqlplus activity to a processflow variable.
SQL PLUS activity has a property :"RESULT_CODE", whenever i run the process flow this value is always reurned as 0.
in sqlplus activity i have written some pl/sql block....
for example
begin
end;
exit
i want to do something like
begin
if v=100 then
return 1
else
return 0;
end if;
end;
exit
can some please tell me how can i return value from this pl/sql block to proessflow.
Regards,
RD_RBStable ==> function
input param from table to function. ==> input mapping paramter to store the output from the mapping.
Will this now work. -
How to compile a procedure from Sql*Plus?
Dear friends,
I couldnt find the way how to compile my invalid procedure through sql*Plus.
I know this is very awkward,but I m in need of that command only.
Thanks
Ritesh SharmaPls check it --
SQL>
SQL>
SQL> @C:\RND\Oracle\Function\a.sql;
11 /
Function created.
SQL>
SQL>
SQL> start C:\RND\Oracle\Function\a.sql;
11 /
Function created.
SQL> Regards.
Satyaki De. -
How to Strip Extraneous Output from SQL*Plus Session
We are running Oracle Database 11g on Solaris 10, and I am trying to use SQL*Plus to create a temporary .sql file that I can execute in a later step of a Korn shell script. Here is the code:
$ORACLE_HOME/bin/sqlplus / as sysdba <<EOF
--whenever oserror exit failure;
--whenever sqlerror exit sql.sqlcode;
set serveroutput on
set termout off
set trimspool on
set verify off
set heading off
set feedback off
set echo off
spool /usr/oracle/temp/apply_site_security_for_oracle_database_11g.ksh.tmp
declare
Value_DSC varchar2(2000);
CommandLine_DSC varchar2(4000);
begin
select v\$parameter.value into Value_DSC from v\$parameter where lower(name)='diagnostic_dest';
CommandLine_DSC := 'host chmod 751 ' || Value_DSC;
dbms_output.put_line('--Ready to execute: ' || CommandLine_DSC);
dbms_output.put_line(CommandLine_DSC);
CommandLine_DSC := 'host ls -ld ' || Value_DSC;
dbms_output.put_line('--Ready to execute: ' || CommandLine_DSC);
dbms_output.put_line(CommandLine_DSC);
end;
spool off;
exit;
EOF
I've tried to turn off everything I don't need, but I am missing something. When I run the script, I get the following in the temporary file:
SQL>
SQL> declare
2 Value_DSC varchar2(2000);
3 CommandLine_DSC varchar2(4000);
4
5 begin
6 select v$parameter.value into Value_DSC from v$parameter where lower(name)='diagnostic_dest';
7
8 CommandLine_DSC := 'host chmod 751 ' || Value_DSC;
9 dbms_output.put_line('--Ready to execute: ' || CommandLine_DSC);
10 dbms_output.put_line(CommandLine_DSC);
11
12 CommandLine_DSC := 'host ls -ld ' || Value_DSC;
13 dbms_output.put_line('--Ready to execute: ' || CommandLine_DSC);
14 dbms_output.put_line(CommandLine_DSC);
15 end;
16 /
--Ready to execute: host chmod 751 /s01/app/oracle
host chmod 751 /s01/app/oracle
--Ready to execute: host ls -ld /s01/app/oracle
host ls -ld /s01/app/oracle
SQL>
SQL> spool off;
I am hoping to whittle this down to just the following lines so I can execute them as a script.
--Ready to execute: host chmod 751 /s01/app/oracle
host chmod 751 /s01/app/oracle
--Ready to execute: host ls -ld /s01/app/oracle
host ls -ld /s01/app/oracle
Any ideas?
Edited by: shew01 on Jan 19, 2010 10:51 AMI just found it. Just add "-S" to the sqlplus command. Argh... I hunted for that a while back. Why didn't I remember it??????????
This works:
$ORACLE_HOME/bin/sqlplus -S / as sysdba <<EOF
whenever oserror exit failure;
whenever sqlerror exit sql.sqlcode;
set serveroutput on
set linesize 2000
set pagesize 0
set termout off
set trimspool on
set feedback off
spool /usr/oracle/temp/apply_site_security_for_oracle_database_11g.ksh.tmp
declare
Value_DSC varchar2(2000);
CommandLine_DSC varchar2(4000);
begin
select v\$parameter.value into Value_DSC from v\$parameter where lower(name)='diagnostic_dest';
CommandLine_DSC := 'host chmod 751 ' || Value_DSC;
dbms_output.put_line('--Ready to execute: ' || CommandLine_DSC);
dbms_output.put_line(CommandLine_DSC);
CommandLine_DSC := 'host ls -ld ' || Value_DSC;
dbms_output.put_line('--Ready to execute: ' || CommandLine_DSC);
dbms_output.put_line(CommandLine_DSC);
end;
spool off;
exit;
EOF
Edited by: shew01 on Jan 19, 2010 11:02 AM -
How to control logic flow in SQL Plus script
Hi
I have the requirement below:
Before I start running an SQL script, I need to ensure that I am connecting as a particular user. If I am not that user, then the script should show a msg "Error - Invalid User - Log in as <<username>>"
Let's say i am executing a script A.sql.
SQL > @<path>a.sql
But before this script is executed -- i shall check for the user:
block begins...
select user into var1 from dual
if upper(var1) != 'ABCUSER' then
-- display the error message and stop execution of this script
else
@<path>a.sql (*it executes what i want :) )
end if;
block ends...
How do I write this code using an SQL script ? Pls suggesHi,
As Centinul said, SQL*Plus is poorly equipped to deal with problems like this. If possible, try to do what you want outside of SQL*Plus.
If you really have to do it in SQL*Plus, here are two ideas:
(1) run a script conditionally
(2) deliberately raise an error
(1) Using SQL*Plus substitution variables, you can decide which of several scripts to run as a sub-script, based on the results of some query.
For example, if a.sql is the script that only user ABCUSER is allowed to run, then write two other very short scripts:
(a) warning.sql, such as the following:
-- warning.sql
PROMPT You are not authorized to do this.
QUIT(b) step_1.sql, which decides whether a.sql or warning.sql should be run, and does it:
-- step_1.sql - Decide whether a.sql or warning.sql is to be run next, and do it.
-- (a) decide:
COLUMN script_name_col NEW_VALUE script_name
SELECT CASE
WHEN USER = 'ABCUSER'
THEN 'a.sql'
ELSE 'warning.sql'
END AS script_name_col
FROM dual;
-- do:
@&script_nameYou may want to use @@, or specify a complete path name.
(2) Deliberately raise an error, either in a separate script or in a.sql itself, like this:
WHENEVER SQLERROR EXIT
SELECT CASE
WHEN USER = 'ABCUSER'
THEN NULL
ELSE TO_NUMBER ('This will raise ORA-01722')
END AS "Welcome!"
FROM dual;
WHENEVER SQLERROR NONE
-- continue with the original a.sql -
How to run OWB mappings from SQL*Plus
Hi:
I used to run OWB mappings using the sample code RUN_MY_OWB_STUFF in a customized PL/SQL procedure. This works for OWB 10g release 1 but not for OWB Paris (10g Release 2) because the execution always returns FAILURE.
Is there something new in OWB Paris that RUN_MY_OWB_STUFF doesn't work anymore?
Thanks,
Hazbleydi C. VerásteguiHi Maruthi:
I already check the input parameters of the mapping. I'm setting them as a custom parameters. This is the output of the execution:
16:01:11 SQL> EXEC PR_RUN_OWBMAPPING_TABLA2('MPG_EMPLEADOS_NOMINA_PERIODO',2007,01);
Stage 1: Decoding Parameters
| location_name=LOC_DM_STAGING
| task_type=PLSQL
| task_name=MPG_EMPLEADOS_NOMINA_PERIODO
Stage 2: Opening Task
| l_audit_execution_id=39635
Stage 3: Overriding Parameters
| P_ANO%CUSTOM='2007'
| P_MES%CUSTOM='1'
Stage 4: Executing Task
| l_audit_result=3 (FAILURE)
Stage 5: Closing Task
Stage 6: Processing Result
| exit=3
By the way, RUN_MY_OWB_STUFF is the same as RUN_OWB_CODE.sql except for the two first parameters (p_result and p_audit_id):
create or replace procedure run_owb_code
( p_result out number
, p_audit_id out number
, p_repos_owner in varchar2 default null
, p_location_name in varchar2 default null
, p_task_type in varchar2 default null
, p_task_name in varchar2 default null
, p_system_params in varchar2 default '","'
, p_custom_params in varchar2 default '","'
, p_oem_friendly in number default 0
is
CREATE OR REPLACE function run_my_owb_stuff
( p_repos_owner in varchar2 default null
, p_location_name in varchar2 default null
, p_task_type in varchar2 default null
, p_task_name in varchar2 default null
, p_system_params in varchar2 default '","'
, p_custom_params in varchar2 default '","'
, p_oem_friendly in number default 0
) return number
is
How do you invoke your wrapper PL/SQL with these two first parameters?
Thanks in advance,
Hazbleydi C. Verástegui -
How to use bind vars in SQL*Plus Script?
I am trying to use a bind var in my script ... does not seem to work ... something along these lines.
variable v_id number;
select max(user_id) into :v_id
from user_id_tbl;
exec trace_user(:v_id);
This is in a UNIX Script - I don't get any errors but the binding is not working - not passing a valid v_id ... Any ideas?For the record a solution is:
variable v_id number;
begin
select max(user_id) into :v_id from user_id_tbl;
end;
exec trace_user(:v_id);
-- CJ -
How to Eliminate Special Character in SQL LOADER Script
How to eliminate special character from SQL LOADER script file which suppose not to insert in TABLE
example.CSV lile like this
<ABC/ , 7747>
<DEF/ , 7763>
<NEW/ , 7779>
<OLD/, 7795>
I have to remove < > and / character at the time of loading into table. How It could be done. It is not possible to remove < , > , / character manually from CSV fileOn Unix/Linux that's very easy, on Windows... I don't know...
$ cat myfile.csv
<ABC/ , 7747>
<DEF/ , 7763>
<NEW/ , 7779>
<OLD/, 7795>
$ tr -d "\057\074\076" <myfile.csv >outfile.csv
$ cat outfile.csv
ABC , 7747
DEF , 7763
NEW , 7779
OLD, 7795
$ -
How to pass table type variable into function from SQL*PLUS ?
How to pass a table type variable from sql*plus prompt into a function ?
Thanx in advance.Krishna,
Do you mean like this?SQL> DECLARE
2 TYPE t_tbl IS TABLE OF VARCHAR2(20);
3 l_sample_tbl t_tbl;
4
5 FUNCTION print_contents ( p_tbl IN t_tbl )
6 RETURN VARCHAR2
7 IS
8 l_string VARCHAR2(1000);
9 BEGIN
10 FOR i IN 1..p_tbl.COUNT LOOP
11 IF (i = 1) THEN
12 l_string := p_tbl(i);
13 ELSE
14 l_string := l_string || ', ' || p_tbl(i);
15 END IF;
16 END LOOP;
17 RETURN (l_string);
18 END print_contents;
19
20 BEGIN
21 l_sample_tbl := t_tbl();
22 l_sample_tbl.EXTEND;
23 l_sample_tbl(1) := 'one';
24 l_sample_tbl.EXTEND;
25 l_sample_tbl(2) := 'two';
26 l_sample_tbl.EXTEND;
27 l_sample_tbl(3) := 'three';
28 l_sample_tbl.EXTEND;
29 l_sample_tbl(4) := 'four';
30 l_sample_tbl.EXTEND;
31 l_sample_tbl(5) := 'five';
32 DBMS_OUTPUT.PUT_LINE(print_contents(l_sample_tbl));
33 END;
34 /
one, two, three, four, five
PL/SQL procedure successfully completed.
SQL> HTH,
T. -
HI,I came to know that direct exit from SQL Plus without Oracle shutdown causes future issues of ORA-0600 kind of errors. Is it true? If yes could u pls suggest me how to shutdown from user "SYSTEM/manager". Bcoz with this am warned that I dont have previleges.
Hello,
HI,I came to know that direct exit from SQL Plus without Oracle shutdown causes future issues of ORA-0600 kind of errors. Is it true?The ORA-00600 is an internal error it can be caused for instance by a Bug, a corruption, ... , and if someday you experience this kind of error, you should open a Service Request to My Oracle Support.
However, I've never heard that exiting sqlplus could cause this kind of error. Where did you get such information ?
how to shutdown from user "SYSTEM/manager". To shutdown the database you should be connected with the User SYS (as SYSDBA). You may use the following statement:
sqlplus /nolog
connect / as sysdba
shutdown immediate;
exitHope this help.
Best regards,
Jean-Valentin -
How to connect from sql*plus to Sql Server
Dear Profs.
How I can connect from sql*plus v8 on my local pc(Win XP) to Sql Server Express 2005 light weight installed in same local pc ?
Thanks,
Ahmed.You'll need to setup heterogeneous services. This is done by creating an init file for the SQL Server db with %ORACLE_HOME%\hs\admin that refers to a DSN for the Sql Server Database. The listener would also need an entry for the SQL Server DB DSN. After that you would create a dblink to SQL Server in your Oracle instance and then could query across the dblink.
-
How to login as DBA in oracle 9i from sql plus .
how to login as DBA in oracle 9i from sql plus . ???
First you need to check whether your HR schema is still unlocked or not? If it is locked - then you have to unlock it. And, then you can connect the Hr schema.
But, i'm not sure - why you need system to log into the HR schema?
Regards.
Satyaki De. -
How to start/stop process flow from sql*plus?
Hi,
i know how to start a process flow via sqlplus_exec_template.sql, but i cannot find any information on how to stop (and rollback) a working flow from sql*plus. Any help would be appreciated.
Greetings
Christoph
Message was edited by:
ctrierweilerHi,
I've had a go.
How should I interpret the results of list_requests:
owner_owr@ORKDEV01> @list_requests
====================
DEPLOYMENTS
====================
Audit ID Status Name Date Owner
2706 READY Deployment Fri Nov 11-NOV-05 10:49:59 OWNER_OWR
11 10:46:37 CET 2
005
====================
DEPLOYMENT UNITS
====================
Audit ID Status Name Date Owner
2707 READY Unit0 11-NOV-05 10:49:59 OWNER_OWR
====================
EXECUTIONS
====================
Er zijn geen rijen geselecteerd.
owner_owr@ORKDEV01>
Whilst a process flow is executing the last query will list executions, all of which have status BUSY:
owner_owr@ORKDEV01> @list_requests
====================
DEPLOYMENTS
====================
Audit ID Status Name Date Owner
2706 READY Deployment Fri Nov 11-NOV-05 10:49:59 OWNER_OWR
11 10:46:37 CET 2
005
====================
DEPLOYMENT UNITS
====================
Audit ID Status Name Date Owner
2707 READY Unit0 11-NOV-05 10:49:59 OWNER_OWR
====================
EXECUTIONS
====================
Audit ID Status Name Date Owner
394512 BUSY PF_ONB01 04-MEI-06 09:11:12 OWNER_OWX
395328 BUSY ONB:FULL_PREPARE 04-MEI-06 09:11:55 OWNER_OWR
395324 BUSY PF_ONB01:ONB 04-MEI-06 09:11:55 OWNER_OWR
owner_owr@ORKDEV01>
As an aside, I will attempt to get rid of the READY deployment and deployment unit using deactive_deployment.sql
Now, if I attempt to use deactivate_execution.sql on any of the executions with status BUSY I get:
owner_owr@ORKDEV01> @deactivate_execution
Voer waarde voor 1 in: 396136
declare
FOUT in regel 1:
.ORA-20003: The object is not in a valid state for the requested operation
ORA-06512: at "OWNER_OWR.WB_RTI_EXCEPTIONS", line 94
ORA-06512: at "OWNER_OWR.WB_RTI_EXECUTION", line 774
ORA-06512: at "OWNER_OWR.WB_RT_EXECUTION", line 90
ORA-06512: at line 4
owner_owr@ORKDEV01>
So all the seems to remain is to use abort_exec_request.sql
This does the job, but the script itself hangs.
I think it has to do with the l_stream_id not being checked again after the initial IF. I think it should probably be part of the loop condition as it is again reset in the do_acks inside the loop.
Cheers & thanks,
Colin -
How to execute procedure returning data rows from sql plus
Hi,
I want to execute a stored procedure that returns data rows from sql plus. please let me know the syntax for the same.
Thanks,
YGuser13065317 wrote:
Even if i get the result set into the cursor, do i have to do normal fetch into all the coumn variables within a loop
But suppose no of columns in my result set varies depending on a parameter to the stored procedure.
Is there any straightforward way to retrieve all the data irrespective of no of columns in the result set.There is no such thing as a "+result set+". Oracle does not create a temporary data set in memory that contains the results of your query. What would happen if this result set is a million rows and is too large to fit into memory? Or there are a 100 clients each with a 100,000 row result set?
This is not scalable. You will be severely limited in the number and sizes of these "+result sets+" that can be created in server memory.
A cursor is in fact a "program" that is created by compiling the SQL source code that you provide. This source code is parsed and compiled into what Oracle calls an execution plan. This is nothing but a series of instructions that the cursor will execute in order to return the rows required.
Thus the result set is actually the output from a cursor (a program). Likewise, bind variables are the input parameters to this program.
All SQLs are parsed and compiled as cursors and stored in the SQL Shared Pool. Oracle gives you handle in return to use to address this cursor - bind values to it, execute it, describe the output structure returned by the cursor, and fetch the output from the cursor.
On the client side, this handle is used in different ways. In PL/SQL alone, this cursor handle can be used as an implicit cursor (you do not even see or use the cursor handle in your PL/SQL code). Or you can use a PL/SQL cursor variable. Or a DBMS_SQL cursor variable. Or a reference cursor variable.
Why so many different client structures for the very same SQL cursor handle returned by Oracle? Because to allow you, the programmer, all kinds of different features and flexibility.
The ref cursor feature is the ability to pass this cursor handle around, not only between PL/SQL code, but also from PL/SQL to the actual client process (Java. VB, SQL*Plus, TOAD, etc).
The primary thing to remember - irrespective of what the client calls this (e.g. ref cursor, SQL statement handle, etc), this all refers to the same SQL cursor in the Shared Pool. And that this SQL cursor is a program that outputs data, and not a result set in itself.
Maybe you are looking for
-
Won't display-MS Internet Exploder Does...
I've had a problem from time to time with Safari not showing pages where Explorer does or will. For example, I'm trying to access a page from a realtor in Maui. The link is: http://maui.fnismls.com/publink/default.asp?GUID=36b045dc-9909-4ac3-8c2f-8e0
-
The new iPhone 5 A1428 bought in canada work in Italy?
Hi I'm a student and I currently live in Toronto but soon return to Italy. I wanted to buy the new iPhone 5 unlocked and use Wind as an line. I have two questions: When I go back to Italy, I can use it, with the Italian line? Which model should I ask
-
HT201363 I forgot my Id and password for I cloud to opean my mobil , please
I forgot my Id And password to opean Icloud ( my mmobil )
-
Import photos from iPad to iPhoto keeping album structure
Hi All, I have an iPad 2 with a camera connect kit. I've imported and organised several hundred photos using the kit and the iPad. I just purchased a Macbook Pro and want to import those photos into iPhoto. The photos all imported, but the album s
-
How to disable AutoCommit at DataSource level for 9.2
Hi, I am trying to persist my JMS messages into timesten datastore for which connection received from timesten needs to be with AutoCommit disabled. Any idea how to do it in Weblogic 9.2 admin console/JDBC data source level? Thanks, Alan