How to issue a SQL*Plus command from PL/SQL program?
Thanks.
You can't issue a SQL*PLus command from a PL/SQL program. If you can tell us more about what you are trying to do, perhaps we can offer a substitute.
Similar Messages
-
Fire OMB Plus commands from PL/SQL
Hi all,
does anyone know if it is possible to fire OMB Plus commands from PL/SQL procedures?
I can imagine that there might be a PL/SQL package in the repository owner schema that accepts OMB Plus commands as strings...or something similar...
Thanks,
ElioHi Elio
I don't know about any existing package that could do that.
What I'd suggest is to build a stored procedure/function/package that could do that. Or even, execute OMB Scripts in the host from a pl/sql program.
Good luck.
Regards,
Marcos -
Running a SQL*Plus command from Java
I have a requirement to run SQL* Plus commands from Java. The results as they would appear in SQL*Plus window or spool file should be captured and stored in a table.
For example,
SQL> select * from dual;
D
X
1 row selected;
SQL>
All the lines above should be stored for later use.
Could any one give pointers?
Thanks,
Ravi<p>
Hi,
</p>
<p>
<strong><font face="Courier New">
public class RuntimeExecApp {
public static void main(String args[]) throws IOException
Runtime r = Runtime.getRuntime();
r.exec("C:\\Oracle\\sqlplus.exe");
}</font></strong>
</p>
<p>
Kuba
</p>
Message was edited by:
KUBA -
hai every body,
I have a doubt regarding sql plus commands and PL/SQL..I am using Oracle 10g..I have created 1 procedure for deletion/updation of transactions..and the number of effected rows I just displayed with using " *dbms_output.put_line* (SQL%ROWCOUNT)"..hence before executing the procedure the sqlPlus command "*SET SERVEROUTPUT ON*" should turn on..at most times it is forget to turn on and output becomes vague..
hence my question is "*Is there any package or any thing to execute sql plus commands(here it is SET SERVER OUTPUT ON) through PL/SQL statements???*"
with thanks,
jp@valapadjp@valapad wrote:
I have a doubt regarding sql plus commands and PL/SQL..
Easy PL/SQL supports PL/SQL commands and embedded SQL, which are found in the PL/SQL and SQL reference manuals.
http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10472/toc.htm
http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/toc.htm
It does not support the commands of other applications or languages such as SQL*Plus, Unix or COBOL for example.
I am using Oracle 10g..I have created 1 procedure for deletion/updation of transactions..and the number of effected rows I just displayed with using " *dbms_output.put_line* (SQL%ROWCOUNT)"..hence before executing the procedure the sqlPlus command "*SET SERVEROUTPUT ON*" should turn on..at most times it is forget to turn on and output becomes vague..You can set serveroutput on in your log in script for SQL*Plus if you keep forgetting.
http://download.oracle.com/docs/cd/E11882_01/server.112/e10823/ch_two.htm#sthref94
hence my question is "*Is there any package or any thing to execute sql plus commands(here it is SET SERVER OUTPUT ON) through PL/SQL statements???*"No. -
Need to execute SQL PLUS commands from C# code
Hello all,
This is my first question here and hopefully I will get my solution :)
Right now we are doing 3 tasks manually
1) Clearing everything from a DB.
We use sql plus and execute this :
RAMNIVAS_CI/RAMNIVAS_CI@orclwex3
set pages 0
set lines 80
spool c:\delete_objects_CI
select 'drop '||object_type||' '||object_name||';'
from user_objects;
spool off
start c:\delete_objects_CI.lst
purge recyclebin;
set pages 100
select count(*) from user_objects;
RAMNIVAS_CI/RAMNIVAS_CI@orclwex3 are the username and pwd which gets input when we paste entire thing in sql plus
2) Then we restore that DB again using sql plus to do it using the command:
imp file=CL.DMP log=CL.log buffer=1000000 fromuser=RAMNIVAS_CL touser=RAMNIVAS_CL statistics=none grants=n commit=y
3)Execute sql scripts on it using sql developer. (This is not hard I guess coz I know we can use oracle client)
4) Take backup using this command:
exp RAMNIVAS_CI/RAMNIVAS_CI@ORCLWEX3 file=CI.dmp log=CI.log direct=y compress=y buffer=1000000 grants=n statistics=none
Is there anything I cna do to execute SQL PLUS commands using c#?Hi,
You can execute OS commands via the SHELL function provided in .NET. See the MSDN for more info.
Some of the things you can do directly from .NET via ODP and PLSQL, some not.
1) Dropping the user objects can be done via a plsql procedure where you open a cursor for "select 'drop '||object_type||' '||object_name||';' ..." and then use EXECUTE IMMEDIATE to execute the resulting commands. You can invoke the procedure via ODP.
2) IMP is an exe, not a sqlplus command, so you're not actually using sqlplus there. You can still use the SHELL command though to invoke that.
3) Executing SQL Scripts via ODP.NET is not something you can do very easily. If you search the threads here you should be able to find some solutions others have come up with to parse the file and execute the statements one by one, but there's nothing built in to ODP to execute a script file.
You may want to just shell out to sqlplus user/pwd@db @scriptfile.sql but you may have issues trying to track down errors if any occurred, as I'm not sure where they go in that case.
4) just as with IMP, EXP is an exe, so you could shell out to that.
Corrections/comments welcome.
Greg -
Is Sql plus command avaliable in sql developer
SQL developer is able to do most of thing can be done with sql plus with GUI , cool.
However, seems sql command, such as show parameter, start database have to be done in sql plus.
is this true?
most of time in my development, I just open sql developer now. but seems in this statuation, i have to use sql plus.jz2 wrote:
SQL developer is able to do most of thing can be done with sql plus with GUI , cool.
However, seems sql command, such as show parameter, start database have to be done in sql plus.
is this true?
most of time in my development, I just open sql developer now. but seems in this statuation, i have to use sql plus.As far as I know you still have to start the database from SQL*PLUS. If your schema has privileges you can get parameter values in SQL*Developer by querying V$PARAMETER (SET_CATALOG_ROLE privilege).
The two tools are not the same. Much of what you can do with SQL*PLUS you can do with SQL*Developer but I feel that SQL*PLUS still has better scripting abilities along with its bind variable storate. On the other hand the GUI interface of SQL*Developer Is fairly easy to use. The danger is editing procedures/functions/packages in the database forgetting to back them up from SQL*Developer first; SQL*PLUS forces me to use scripts.
Depending on what I am doing I use either SQL*PLUS or SQL*Developer (which I like better for queries with long select lists).
I'm having trouble getting DBMS_OUTPUT.PUT_LINE to work the way I expect in SQL*Developer; sometimes the output just does not appear without repeated executions of the generating program. -
How to find GUI SQL*Plus command tool in Oracle 8i (version 8.1.7)
I had installed Oracel 8i Enterprise Edition (version 8.1.7) on my server machine (Windows NT 4.0), I'd like to use Oracle Navigator (GUI SQL*PLUS command tool), but I can not find it from the menu. I know Oracle Navigator is available in Oracle 7. Can anyone tell me where and how to use GUI SQL*PLUS command tool in Oracle 8i Enterprise Edition (version 8.1.7) ?
thanks a lot.
David ZhuHi
Oracle Navigator is part of Personal Oracle7 and Oracle Lite. I don't know is it available in 8i Personal Edition but I am sure that it is not part of Standard and Enterprise Edition.
Regards
null -
How to: execute operating system commands from PL/SQL
System: IBM pSeries AIX
Oracle: 11g Enterprise
Is there a quick way to execute operating system commands from PL/SQL?
Without creating a JAVA class....
I need to execute a Loader script.
I want to do this from within PL/SQL.
I need to to do 4 things.
Three require SQL scripts.
The fourth is SQL*Loader.
The usual way is with a UNIX script calling 3 SQL scripts and one Loader control file.
Is there way to do all this from within ONE PL/SQL SCRIPT ??
Just let me know.Is there a quick way to execute operating system commands from PL/SQL?
NO
Without creating a JAVA class....
I need to execute a Loader script.
I want to do this from within PL/SQL.
WHY ON EARTH, such action will create a new connection and become a resource hog?
I need to to do 4 things.
Three require SQL scripts.
The fourth is SQL*Loader.
The usual way is with a UNIX script calling 3 SQL scripts and one Loader control file.
Which is perfect for the purpose.
Is there way to do all this from within ONE PL/SQL SCRIPT ??
Just let me know.
NO, there is NOT. Nor should there be. Why create unstable ineffcient Mickey Mouse systems, glued together by hacking?
Sybrand Bakker
Senior Oracle DBA -
Run OS command from Pl/SQL
Is there any way to execute an OS command from pl/sql other than using dbms_pipe & pro*C combo. I have done this way before but it seems there is built-in oracle package which can do this in 8/8i.
Also HOST command in forms will execute the OS coomand from the clinet. Is there any way to execute the OS command on the server from the forms clinet?
thanks,
Ravi.
nullRavi,
Can you send me an example how one can
execute a this command from a PL/SQL
program 'sed 3q /etc/passwd'.
Please write to me at
[email protected]
thanks
Pramod -
Issue with Executing OS commands from Stored Procedure
I am trying to execute the scripts provided at :
http://github.com/xtender/XT_SHELL
provided by xtender user.
As required, I have asked my DBAs to grant privileges by executing the following scripts:
Begin
--change to needed permissions and execute
dbms_java.grant_permission( 'ODS', 'SYS:java.io.FilePermission', '/var/factiva/ODS/bin/CVIM_Rpt_ExportCSVFile’, 'read,write,execute' );
end;
/where CVIM_Rpt_ExportCSVFile is my script residing in the Unix server where my Oracle is installed.
The error I am facing when I try to execute the following command is:
select * from table(xt_shell.shell_exec('/var/scripts/CVIM_Rpt_ExportCSVFile',100))
Exception:the Permission (java.io.FilePermission /var/scripts/CVIM_Rpt_ExportCSVFile execute) has not been granted to ODS. The PL/SQL to grant this is dbms_java.grant_permission( 'ODS', 'SYS:java.io.FilePermission', '/var/scripts/CVIM_Rpt_ExportCSVFile', 'execute' )I have asked my DBA to also execute the following scripts: - But I still see the same error as above. I am not able to figure out whats going on. Can anyone pls help me out??
EXEC Dbms_Java.Grant_Permission('ODS', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
EXEC Dbms_Java.Grant_Permission(ODS', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
dbms_java.grant_permission( 'ODS', 'SYS:java.io.FilePermission', '/var/scripts/CVIM_Rpt_ExportCSVFile', 'execute' )DUPLICATE
===============================================================
Issue with Executing OS commands from Stored Procedure
============================================================== -
Running sqlldr command from PL/SQL Block
DECLARE
BEGIN
END;In SQL * plus we can run DOS commands using the following command
HOST DIR
HOST DIR/P
But When we can't run the HOST command in PL/SQL Block..
I have to Run sqlldr command from PL/SQL Block..
i tried as follows
DECLARE
BEGIN
EXECUTE IMMEDIATE ' host sqlldr control= bad= ';
END;
By
BalaNagaRaju -
Execute SQL*PLUS script from VB6?
I'm using VB6 to connect to oracle 10 with oracle client 8i, I can establish the connection without any problems.
If I run a SQL statement from VB it works prefect, but when I try to run a SQL Plus script from VB I get error ORA-00900, "invalid SQL statement". Everything works fine in oracle SQLPLUS.
Is there anything I have missed about running SQL*PLUS script from VB6? Is'nt it the same as a SQL statement?Thanks for you answer Justin,
This is a short variant of SQL*Plus I wanna execute from VB and transfer the result into a listview in VB.
If this is possible from VB, can you show me how I should do?
COLUMN customer_1 NEW_VALUE customer_1 NOPRINT
COLUMN customer_2 NEW_VALUE customer_2 NOPRINT
SELECT customer customer_1
FROM (
SELECT customer,
ROW_NUMBER() OVER(PARTITION BY customer ORDER BY CustomerTotalSales DESC) CustomerTotalSalesRank
FROM (
SELECT customer,
SUM(SalesQty) OVER(PARTITION BY customer) CustomerTotalSales
FROM CustTable
WHERE year_month BETWEEN 200709 AND 200801
WHERE CustomerTotalSalesRank = 1
AND ROWNUM = 1
SELECT customer customer_2
FROM (
SELECT customer,
ROW_NUMBER() OVER(PARTITION BY customer ORDER BY CustomerTotalSales DESC) CustomerTotalSalesRank
FROM (
SELECT customer,
SUM(SalesQty) OVER(PARTITION BY customer) CustomerTotalSales
FROM CustTable
WHERE year_month BETWEEN 200709 AND 200801
WHERE CustomerTotalSalesRank = 2
AND ROWNUM = 1
SET VERIFY OFF
SELECT year_month,
SUM(
CASE CustomerTotalSalesRank
WHEN 1
THEN
SalesQty
ELSE
NULL;
END
) "&customer_1",
SUM(
CASE CustomerTotalSalesRank
WHEN 2
THEN
SalesQty
ELSE
NULL;
END
) "&customer_2"
FROM (
SELECT year_month,
SalesQty,
ROW_NUMBER() OVER(PARTITION BY customer ORDER BY CustomerTotalSales DESC) CustomerTotalSalesRank
FROM (
SELECT customer,
year_month,
SalesQty,
SUM(SalesQty) OVER(PARTITION BY customer) CustomerTotalSales
FROM CustTable
WHERE year_month BETWEEN 200709 AND 200801
WHERE CustomerTotalSalesRank <= 10
GROUP BY year_month
ORDER BY year_month
/ -
O/s commands from PL/SQL
hi all..
i want to execute operating system commands from PL/SQL..
particulary imp command....
i have used the f/wg approach but while i execute the imp command it does not responds me any output..
I have to kill the process from o/s.
prodn is my user
--AS SYS user
begin
dbms_java.grant_permission( 'PRODN',
'SYS:java.io.FilePermission',
'/oracle/product/9.2.0/bin/imp',
'execute' );
dbms_java.grant_permission
('PRODN',
'java.lang.RuntimePermission',
'writeFileDescriptor' );
end;
---------------------------------AS PRODN user
create or replace and compile
java source named "Util"
as
import java.io.*;
import java.lang.*;
public class Util extends Object
public static int RunThis(String args)
Runtime rt = Runtime.getRuntime();
int rc = -1;
try
Process p = rt.exec(args);
int bufSize = 4096;
BufferedInputStream bis = new BufferedInputStream(p.getInputStream(),
bufSize);
int len;
byte buffer[] = new byte[bufSize];
// Echo back what the program spit out
while ((len = bis.read(buffer, 0, bufSize)) != -1)
System.out.write(buffer, 0, len);
rc = p.waitFor();
catch (Exception e)
e.printStackTrace();
rc = -1;
finally
return rc;
create or replace
function RUN_CMD(p_cmd in varchar2) return number
as
language java
name 'Util.RunThis(java.lang.String) return integer';
create or replace procedure RC(p_cmd in varchar2)
as
x number;
begin
x := run_cmd(p_cmd);
end;
i executed the command as follows in sql>
BEGIN
rc('/oracle/product/9.2.0/bin/imp tim/tim file=/home/oracle/vas4359.dmp log
=log1.log');
END;
it runs fine creates log1.log in / home/oracle but there is no output in
log1.log file.
I have to kill the process as follows after which sql> displays me :
"PL/SQL procedure successfully completed."
[oracle@msebdb oracle]$ ps aux|grep imp
oracle 20052 0.0 0.2 12732 4328 ? S 11:57 0:00 /oracle/product/
.2.0/bin/imp file=/home/oracle/vas4359.dmp log=log1.log
oracle 20102 0.0 0.0 3692 652 pts/2 S 12:03 0:00 grep imp
Note:There is no tim user.. i just want to get error in my log file..
my further steps are to read this log file and send email/notifications to users.
my main program is as f/ws:
/*imp and check log file*/
create or replace procedure abc
as
v_exists boolean;
v_exists_log boolean;
ex_open BOOLEAN;
flen NUMBER;
bsize NUMBER;
vInHandle_open utl_file.file_type;
vInHandle_open_log utl_file.file_type;
v_filelog utl_file.file_type;
v_fl utl_file.file_type;
v_pth varchar2(60);
v_fnm varchar2(60);
v_file_exists varchar2(60);
v_logline varchar2(30) ;
v_search varchar2(30) :='ORA-';
vNewLine VARCHAR2(32767);
cursor c_fname is
select full_pth ,f_name from upld_file_t where f_name in
(select f_name from tbl_file_nm where typ_file='D' AND DEL_FLG='N');
BEGIN
for v_sec in c_fname
loop
utl_file.fgetattr(LOCATION=>'ORALOAD',
FILENAME=>v_sec.f_name,
FEXISTS=>v_exists,
FILE_LENGTH=> flen,
BLOCK_SIZE=>bsize);
if v_exists
THEN
dbms_output.put_line('File Exists' || v_sec.f_name);
v_file_exists:=v_sec.f_name;
--dbms_output.put_line('v_file_exists ' || v_file_exists);
dbms_output.put_line('File Length: ' || TO_CHAR(flen));
dbms_output.put_line('Block Size: ' || TO_CHAR(bsize));
dbms_output.put_line(' before file open');
vInHandle_open := utl_file.fopen('ORALOAD',v_sec.f_name,'R',32767);
-- dbms_output.put_line(' after file open');
-- do whater with teh file data
v_fl:=utl_file.fopen('ORALOAD','v_sec.f_name','W');
dbms_output.put_line('v_sec.f_name');
IF utl_file.is_open(vInHandle_open)
THEN
/*if log file exists..*/
utl_file.fgetattr(LOCATION=>'ORALOAD',
FILENAME=>v_sec.f_name||'.log',
FEXISTS=>v_exists_log,
FILE_LENGTH=> flen,
BLOCK_SIZE=>bsize);
if v_exists_log
then
dbms_output.put_line('file' ||v_sec.f_name||'.log');
v_filelog :=utl_file.fopen('ORALOAD',v_sec.f_name||'.log','W',32767);
LOOP
BEGIN
UTL_FILE.PUT(v_filelog,'ORA-');
exit;
END;
END LOOP;
else
dbms_output.put_line('File not found' || v_sec.f_name);
END IF;
UTL_FILE.fclose(v_filelog);
dbms_output.put_line('Closed File ' || v_sec.f_name|| '.log');
END IF;
/*imp THE FILE and read log file*/
utl_file.fgetattr(LOCATION=>'ORALOAD',
FILENAME=>v_sec.f_name||'.log',
FEXISTS=>v_exists_log,
FILE_LENGTH=> flen,
BLOCK_SIZE=>bsize);
if v_exists_log
then
dbms_output.put_line('file' ||v_sec.f_name||'.log');
v_filelog :=utl_file.fopen('ORALOAD',v_sec.f_name||'.log','R',32767);
LOOP
BEGIN
UTL_FILE.get_line(v_filelog,v_logline);
if v_logline = v_search then
dbms_output.put_line(v_logline);
end if;
UTL_FILE.fclose(v_filelog);
dbms_output.put_line('Closed File ' || v_sec.f_name|| '.log');
exit;
END;
END LOOP;
else
dbms_output.put_line('File not found' || v_sec.f_name);
END IF;
END IF;
END LOOP;
--close the curosr .. check this
EXCEPTION
WHEN UTL_FILE.ACCESS_DENIED THEN
DBMS_OUTPUT.PUT_LINE('No Access!!!');
when others then
dbms_output.put_line('ERROR (open_file) => '||sqlcode);
dbms_output.put_line('MSG (open_file) => '||sqlerrm);
end;Hi,
You might have better luck in the PL/SQL or Java forums. They are located here:
PL/SQL: PL/SQL
Java: http://forums.oracle.com/forums/forum.jsp?forum=99
Good luck,
Mark -
SQL Plus command to print a report in Landscape format
Hi,
what is the SQL Plus command to print a report in Landscape format?841731 wrote:
Hi,
what is the SQL Plus command to print a report in Landscape format?SQLPlus doesn't print, and it doesn't know about 'landscape' vs. 'portrait' any more than it knows about fonts. the only 'formatting' it knows is line size, page size. And all it does with line size is know where to insert a CR/LF pair (windows) or a CR (*nix). The only thing it knows to do with page size is repeat column headers.
The rest is up to whatever application you use to open the pure asciii text spool file. -
How to open report in the browser from PL/SQL procedure
Hi,
I need to call the report (with destype = SCREEN) from the PL/SQL procedure and display in the browser.
For Example: when I call P_call_report procedure in my Forms6i button or at sql*plus, the report output PDF/HTML should open in the Browser window.
Iam Using IE, report6i, forms 6i, Oracle 8.1.7, Windows OS
I tried using UTL_HTTP(' ') in a procedure. But when I execute the procedure at sql*plus it says Pl/sql procedure completed successfully message without opening report output in the browser window. If I copy the same url and paste it in the browser, it works.
Please let me know if there is any solution.
thanks alot.I guess event driven publishing may work. But Iam not sure about the opening of the browser from inside the procedure.
Maybe you are looking for
-
Printing only one page problem
Hi, I have a printable class that needs to print some text only on 1 page. The thing is that when I hit print the printer prints 3 pages: page 1 - with correct content page 2 - empty page page 3 - page with content translated some how then the printi
-
Trigger problem on Sql Server with linked server to Oracle
Hi All, I have a simple insert trigger on Sql Server 2005, it uses linked server to Oracle. like that ; USE [YTM08] GO SET QUOTED_IDENTIFIER ON GO ANSI_NULLS ON go ANSI_WARNINGS ON CEATE TRIGGER [dbo].[YTM_TBLSTSABIT_I] ON [dbo].[TBLSTSABIT] FOR INSE
-
Tried to update to latest iTunes after a prompt and keep getting Microsoft C runtime errors
Any way to o back and reinstall the older version?
-
Does anyone have trouble obtaining the split screen in email and text in the landscape mode on the iPhone 6 plus? Works with Safari and bookmarks
-
Hi, We have a finished product which is planned in APO, so set up as external planning in ECC. The components are planned in APO, we run the MRP with planning mode = 3 and we can see that the planned order created in APO for the FERT is modified in