码迷,mamicode.com
首页 > 数据库 > 详细

Mac 编写oracle 连接脚本

时间:2016-11-27 12:00:55      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:family   terminal   字符集   index   color   baidu   code   oracle   imp   

 

首先需要本地存有sqlplus命令, 如果没有则需要到官网下载 也可点击我进行下载 (解压 readme.txt 有安装配置说明):

Oracle官网下载instant client for os x。

http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html
至少要下载
instantclient-basic-macos和 instantclient-sqlplus-macos两个包
解压缩这两个包到目录instantclient中
复制instantclient到/opt/oracle目录中
sudo cp -r instantclient /opt/oracle  (执行命令前先建立这文件夹)
二. 配置环境变量
1. 启动终端Terminal
2. 进入当前用户的home目录    输入cd ~
3. 创建.bash_profile    输入touch .bash_profile
4. 编辑.bash_profile文件    输入vi  .bash_profile
环境变量配置
DYLD_LIBRARY_PATH="/opt/oracle/instantclient"
export DYLD_LIBRARY_PATH
export ORACLE_HOME=$DYLD_LIBRARY_PATH
export PATH=$ORACLE_HOME:$PATH

5. 保存文件,关闭.bash_profile
6. 更新刚配置的环境变量
    输入source .bash_profile

这样在命令行中即可直接使用sqlplus,   修改字符集, 可直接写在sh脚本中
export NLS_LANG="simplified chinese_china.zhs16gbk"

 

调用示例

function get_access_reference()
{
reference=`sqlplus -S  dbname/dbpwd@tns << EOF
set feedback off;
set pagesize 0;
select ATL_REFERENCE from t_access_tradelist where atl_primary = ${1};
EOF`
}
echo ${reference} # 直接输出查询结果

 

 

Mac 编写oracle 连接脚本

标签:family   terminal   字符集   index   color   baidu   code   oracle   imp   

原文地址:http://www.cnblogs.com/vagabond/p/6106111.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!