Execute cmd in oracle

Source: Internet
Author: User

I installed an oracle db11g, so I want to try some commands circulating on the Internet that run cmd in sqlplus. I don't know how to use them. None of them work well. It may be because the online conversion is wrong. however, there is a simple method to execute the cmd command:

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.

 

In unix or linux

! Command


================================================= =====

There are two other methods on the Internet:

1 is to use msvcrt. dll

Write a c: orac. SQL

Content:

Rem
Rem merge Md. SQL
Rem
Rem Run system commands via Oracle database servers
Rem
Rem Bugs to david@ngssoftware.com
Rem
Create or replace library exec_shell
C: windowssystem32msvcrt. dll;
/
Show errors
Create or replace package into MD IS
PROCEDURE exec (Response string in char );
End transaction md;
/
Show errors
Create or replace package body already MD IS
PROCEDURE exec (Response string in char)
IS EXTERNAL
NAME "system" LIBRARY exec_shell
Language c;
End transaction md;
/
Show errors

Then 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 (username and password and sid respectively)
Connected.
SQL> @ c: orac. SQL
Library created.
No errors.
Package created.
No errors.
Package body created.
No errors.
SQL>
SQL> exec cmdmd.exe c (dir> c: oracle.txt );

The result is displayed on my local machine.

Row 3 has an error:
ORA-28595: Extproc agent: DLL path invalid
ORA-06512: In "SYSTEM. cmdmd", line 2
ORA-06512: In line 1

Failed.

Method 2

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.exe c (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;

After logging on to the system, it is still executed in sequence.

SQL> @ c: 1. SQL
/

@ C: 2. SQL

/

@ C: 3. SQL

/

Variable x number;

Set serveroutput on;

Exec dbms_java.set_output (100000 );

Grant policyspriv to system;

Grant javauserpriv to system)

Exec: x: = run_cmz (ipconfig); the command is successfully run.

Test environment: win2003 + oracle11g

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.