例1:字符串时间转换成字符串
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
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
例2:在脚本中执行sql语句
#!/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"