簡體   English   中英

在Sqlplus中運行Linux函數

[英]Running Linux Functions inside Sqlplus

我可以使用HOST命令從Oracle SQLPLUS內部調用用戶創建的shell函數嗎? 如果沒有,解決問題的最佳方法是什么?

本質上,我想運行一個shell文件:

Shell commands
sqlplus
@file.sql
HOST mylinuxfunction...
@file2.sql
HOST anotherlinuxfunction..
exit
Shell commands

謝謝!

你肯定可以從SQLPlus腳本調用HOST命令,但我想你真的在問你是否可以在其余的SQLPlus腳本中使用linux函數的返回值。 而且您可能還想在Linux函數中使用SQL查詢的結果。

如果你不需要 SQL信息傳遞給你的Linux功能,並且不需要從Linux訪問功能在您的SQL其余部分的結果,那么你有什么幾乎工作。 這個會

date
sqlplus / << xxENDxx \
    @file.sql
    HOST mylinuxfunction...
    @file2.sql
    HOST anotherlinuxfunction..
    exit
xxENDxx
date

現在,如果要將信息從linux函數獲取到SQL中,則必須使用外部表。 很多設置,但請看這里: https//asktom.oracle.com/pls/apex/f?p = 100 :11:0 ::::P11_QUESTION_ID439619916584並搜索“但這里是另一個有趣的方法,在10.2.0.5和更高版本中可用:“

如果要將在調用SQLPlus之前完成的Linux命令中的信息傳遞到SQL命令中,那么就是這樣,將行插入到uptimes表中,並使用存儲在BASH變量$UPTIMESuptime命令的輸出:

#!/bin/bash
if [ "$1" = "" ]
then
    echo Missing User ID parm
    exit 1
else
    USER_ID=$1
fi

read  -p "Enter Your password for Oracle instance $ORACLE_SID for user $USER_ID: " PW

UPTIMES=`uptime | awk -F,  '{print $3, $4, $5}' | awk '{printf "%2.2f,%2.2f,%2.2f\n", $3, $4, $5}'`
sqlplus /nolog << xxENDxx \

connect $USER_ID/$PW

        insert into uptimes (date_stamp, one_min, five_min, fifteen_min) values (sysdate, $UPTIMES);
        HOST ls -o uptimes.sh
        --@file2.sql
        select * from uptimes;
        HOST du -sh .
        exit
xxENDxx

date

調用上面的代碼可以得到:

oracle. (/home/oracle/sql)
Linux> ./uptimes.sh mark.stewart
Enter Your password for Oracle instance ecs03 for user mark.stewart: xxxx

SQL*Plus: Release 12.1.0.2.0 Production on Thu Mar 17 20:09:36 2016
Dev:@> Connected.
Dev:MARK.STEWART@ecs03> Dev:MARK.STEWART@ecs03>
1 row created.

Dev:MARK.STEWART@ecs03> -rwxr-xr-x. 1 oracle 548 Mar 17 20:09 uptimes.sh

Dev:MARK.STEWART@ecs03> Dev:MARK.STEWART@ecs03>
DATE_STAM    ONE_MIN   FIVE_MIN FIFTEEN_MIN
--------- ---------- ---------- -----------
17-MAR-16          0        .01         .05
17-MAR-16          0        .01         .05
17-MAR-16          0        .01         .05

Dev:MARK.STEWART@ecs03>  146M    .

Dev:MARK.STEWART@ecs03> Disconnected from Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
Thu Mar 17 20:09:36 CET 2016
oracle. (/home/oracle/sql)
Linux>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM