Oracle 時間轉換,在腳本中執行sql語句

例1:字符串時間轉換成字符串 sql

SQL> select username,account_status,expiry_date from dba_users;

USERNAME                       ACCOUNT_STATUS                   EXPIRY_DATE
------------------------------ -------------------------------- ------------
MGMT_VIEW                      OPEN                             18-SEP-14
SYS                            OPEN                             17-SEP-14
SYSTEM                         OPEN                             21-JUN-15
DBSNMP                         OPEN                             17-SEP-14
SYSMAN                         OPEN                             18-SEP-14 shell

SQL> select username,account_status,to_char(expiry_date,'yy-mm-dd') from dba_users;

USERNAME                       ACCOUNT_STATUS                   TO_CHAR(
------------------------------ -------------------------------- --------
MGMT_VIEW                      OPEN                             14-09-18
SYS                            OPEN                             14-09-17
SYSTEM                         OPEN                             15-06-21
DBSNMP                         OPEN                             14-09-17
SYSMAN                         OPEN                             14-09-18 oracle

例2:在腳本中執行sql語句 spa


#!/bin/sh
# author: shenxiaoran

prog_home=/zlrt/oracle
log="/tmp/oracle_user_expiry.log"
mail=$prog_home/mail_telnet.sh

#su - oracle -c "echo $ORACLE_SID"
#select username,account_status,expiry_date from dba_users;

su - oracle -c "sqlplus / as sysdba" << EOF | awk '/USERNAME/,/rows selected/ {print}> $log
select username,to_char(expiry_date,'yyyy-mm-dd') from dba_users;
exit;
EOF

$mail "Oracle User expiry_date list" "$log"
相關文章
相關標籤/搜索