• 记点事! oracle 调用外部命令


    oracle执行系统命令

     
    测试成功环境:windows XP+oracle 10g、window 2008 R2 + 11g
     
    代码如下:
    www.2cto.com  
    Sql代码  
    create or replace and compile Java Source named "OSCommand" as  
    -- java:        OS COMMAND  
     
    import java.io.*;  
    import java.lang.*;  
    public class OSCommand{  
       
            public static String Run(String Command){  
       
                    Runtime rt = Runtime.getRuntime();  
                    int     rc = -1;  
       
                    try{  
                            Process p = rt.exec( Command );  
                            int bufSize = 32000;  
                            int len = 0;  
                            byte buffer[] = new byte[bufSize];  
                            String s = null;  
       
                            BufferedInputStream bis = new BufferedInputStream( p.getInputStream(), bufSize );  
                            len = bis.read( buffer, 0, bufSize );  
       
                            rc = p.waitFor();  
       
                            if ( len != -1 ){  
                                    s = new String( buffer, 0, len );  
                                    return( s );  
                            }  
       
                            return( rc+"" );  
                    }    www.2cto.com  
       
                    catch (Exception e){  
                            e.printStackTrace();  
                            return(  "-1 command[" + Command + "] " + e.getMessage() );  
                    }  
       
            }  
    }  
    /   
    show errors  
       
    create or replace function OSexec( cCommand IN string ) return varchar2 is  
    -- function:    OS EXEC  
    -- descr:       PL/SQL wrapper for the Java OSCOMMAND stored proc  
    --  
    language        JAVA  
    name            'OSCommand.Run(java.lang.String) return java.lang.String';  
    /     www.2cto.com  
    show errors  
       
    -- sysdba. Substitute SCOTT with the applicable schema that owns the OSEXEC  
    -- and OSCOMMAND stored procs.  
    declare  
            SCHEMA  varchar2(30) := 'SCOTT';  
    begin  
            dbms_java.grant_permission(  
                    SCHEMA,  
                    'SYS:java.io.FilePermission',  
                    '<<ALL FILES>>',  
                    'execute'  
            );  
       
            dbms_java.grant_permission(  
                    SCHEMA,  
                    'SYS:java.lang.RuntimePermission',  
                    'writeFileDescriptor',  
                    '*'  
            );  
            dbms_java.grant_permission(  
                    SCHEMA,  
                    'SYS:java.lang.RuntimePermission',  
                    'readFileDescriptor',  
                    '*'  
            );  
       
    commit;  
    end;  
    /     www.2cto.com  
       
    -- 查看本地连接信息  
    SQL> select OSexec('ipconfig') as STDOUT from dual;  
       
    STDOUT  
    --------------------------------------------------------------------------------  
    Windows IP ????  
       
    ??????????? ????l?? 3:  
      www.2cto.com  
       l??????? DNS ??? . . . . . . . :  
       ????t?? IPv6 ???. . . . . . . . : *************  
       IPv4 ??? . . . . . . . . . . . . : 192.168.100.100  
       ????????  . . . . . . . . . . . . : 255.255.255.0  
       ??????. . . . . . . . . . . . . : 0.0.0.0  
    --激活guest账号  
     SQL> select OSexec('cmd.exe /c net user guest /active:yes') as STDOUT from dual;  
    STDOUT  
    --------------------------------------------------------------------------------  
    0  
  • 相关阅读:
    JS的构造函数
    Wdcp在安装memcached出现错误的解决办法
    mac 下 xampp 多域名 多站点 多虚拟主机 配置
    JS快速获取图片宽高的方法
    全文检索引擎Solr系列——整合MySQL、MongoDB
    php:获取浏览器的版本信息
    css3 media媒体查询器用法总结
    转:利用node压缩、合并js,css,图片
    火车进站
    三角形有向面积
  • 原文地址:https://www.cnblogs.com/fat_li/p/3860351.html
Copyright © 2020-2023  润新知