先create package,在里面聲明procedure
成都創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都做網(wǎng)站、成都網(wǎng)站設(shè)計、江城網(wǎng)絡(luò)推廣、微信小程序定制開發(fā)、江城網(wǎng)絡(luò)營銷、江城企業(yè)策劃、江城品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎;成都創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供江城建站搭建服務(wù),24小時服務(wù)熱線:13518219792,官方網(wǎng)址:www.cdcxhl.com
然后再create package body,在package body里面編寫procedure的代碼即可(相當(dāng)于create procedure)。
包里沒有create procedure
示例如下:
CREATE OR REPLACE PACKAGE pkg_test IS
PROCEDURE pro_test(V_OLD IN VARCHAR2,V_NEW IN VARCHAR2);
...
END test;
/
CREATE OR REPLACE PACKAGE BODY pkg_test IS
...
PROCEDURE pro_test(V_OLD IN VARCHAR2,V_NEW IN VARCHAR2) IS
BEGIN
...
END;
...
END pkg_test;
--創(chuàng)建包頭
CREATE OR REPLACE PACKAGE ELS.pkg_proxy
AS
TYPE cursortype IS REF CURSOR;
-- 得到交接確認(rèn)代理人數(shù)據(jù)
PROCEDURE get_proxy_info (
v_emp_no IN VARCHAR2, --當(dāng)前登錄用戶
v_to_emp_no IN VARCHAR2, --代理人工號
v_to_emp_name IN VARCHAR2, --代理人姓名
v_proxy_date1 IN VARCHAR2, --代理開始時間: yyyy/mm/dd
v_proxy_date2 IN VARCHAR2, --代理結(jié)束時間: yyyy/mm/dd
v_from_emp_no IN VARCHAR2, --被代理人工號
v_from_emp_name IN VARCHAR2, --被代理人姓名
p_cursor OUT cursortype
);
END pkg_proxy;
--創(chuàng)建包頭
CREATE OR REPLACE PACKAGE BODY ELS.pkg_proxy
AS
-- 得到交接確認(rèn)代理人數(shù)據(jù)
PROCEDURE get_proxy_info (
v_emp_no IN VARCHAR2, --當(dāng)前登錄用戶
v_to_emp_no IN VARCHAR2, --代理人工號
v_to_emp_name IN VARCHAR2, --代理人姓名
v_proxy_date1 IN VARCHAR2, --代理開始時間: yyyy/mm/dd
v_proxy_date2 IN VARCHAR2, --代理結(jié)束時間: yyyy/mm/dd
v_from_emp_no IN VARCHAR2, --被代理人工號
v_from_emp_name IN VARCHAR2, --被代理人姓名
p_cursor OUT cursortype
)
AS
BEGIN
OPEN p_cursor FOR
WITH v AS
(
--查找當(dāng)前登錄人是否為管理員
SELECT *
FROM employee
WHERE dept_id IN (
SELECT ID
FROM department
START WITH ID =
(SELECT dept_id
FROM employee
WHERE emp_no = v_emp_no
AND is_admin IN (
SELECT r_value
FROM role_conditions
WHERE r_key =
'ProxySearch')
UNION
SELECT dept_id
FROM employee_add
WHERE emp_no = v_emp_no
AND is_admin IN (
SELECT r_value
FROM role_conditions
WHERE r_key =
'ProxySearch'))
CONNECT BY PRIOR ID = parent_id)
UNION
SELECT *
FROM employee
WHERE emp_no = v_emp_no)
SELECT DISTINCT *
FROM (SELECT a.currentuser, a.toagrentuser,
DECODE (a.agent_type,
'A', '當(dāng)前交接確認(rèn)代理',
'B', '將來離職簽核代理',
'C', '當(dāng)前離職簽核代理',
'D', '將來交接確認(rèn)代理',
''
) agent_type,
a.from_date, a.TO_DATE,
DECODE
(a.to_date1,
'', '無',
TO_CHAR (a.TO_DATE,
'yyyy/mm/dd am hh:mi:ss'
)
) to_date1,
a.flowinfo, b.emp_cname AS currentusername,
b1.emp_cname AS toagrentusername, workitem
FROM (
--當(dāng)前交接確認(rèn)代理
SELECT SUBSTR
(x.currentuser,
1,
INSTR (x.currentuser, '(') - 1
) AS currentuser,
SUBSTR
(x.toagrentuser,
1,
INSTR (x.toagrentuser, '(') - 1
) AS toagrentuser,
'A' AS agent_type,
x.create_date AS from_date,
x.create_date AS TO_DATE,
NULL AS to_date1, x.workid,
NULL AS formid, y.NAME workitem,
(SELECT e.emp_no
|| '('
|| e.emp_cname
|| ')'
FROM employee e
WHERE e.emp_no = y.emp_no)
AS flowinfo
FROM currentworkagrent x,
worktransferitem_m y
WHERE x.workid = y.ID
UNION ALL
--將來交接確認(rèn)代理
SELECT SUBSTR
(currentuser,
1,
INSTR (currentuser, '(') - 1
) AS currentuser,
SUBSTR
(toagrent,
1,
INSTR (toagrent, '(') - 1
) AS toagrent,
'D' AS agent_type, starttime,
endtime, endtime AS to_date1, NULL,
NULL, NULL, NULL
FROM futureagrent) a,
employee b,
employee b1
WHERE a.currentuser = b.emp_no(+)
AND a.toagrentuser = b1.emp_no(+)) a
WHERE currentuser IN (SELECT emp_no
FROM v)
AND (currentuser = v_from_emp_no OR v_from_emp_no IS NULL
)
AND ( currentusername = v_from_emp_name
OR v_from_emp_name IS NULL
)
AND (toagrentuser = v_to_emp_no OR v_to_emp_no IS NULL)
AND ( toagrentusername = v_to_emp_name
OR v_to_emp_name IS NULL
)
AND from_date =
TO_DATE (NVL (v_proxy_date2, '2099/12/31'),
'yyyy/mm/dd'
)
AND TO_DATE =
TO_DATE (NVL (v_proxy_date1, '1000/12/31'),
'yyyy/mm/dd'
)
ORDER BY a.agent_type, a.from_date DESC;
END;
END pkg_proxy;
1.配置hostname
[root@oracledb ~]#hostnamectl set-hostname oracledb
[root@oracledb ~]#echo " 10.100.1.10 oracledb" /etc/hosts
2.關(guān)閉selinux和防火墻
[root@oracledb ~]#sed -i "s/SELINUX=enforcing/SELINUX=disabled/" /etc/selinux/config
[root@oracledb ~]#setenforce 0
[root@oracledb ~]#systemctl stop firewalld
[root@oracledb ~]#systemctl disable firewalld
[root@oracledb ~]#systemctl status firewalld
3.下載Oracle軟件包 且上傳到服務(wù)器上,進(jìn)行解壓縮
建議使用winSCP工具進(jìn)行上傳到服務(wù)器的/opt目錄下
[root@oracledb ~]# ls -lh /opt/
-rw-r--r-- 1 root root 1.2G Mar 30 16:12 linux.x64_11gR2_database_1of2.zip
-rw-r--r-- 1 root root 1.1G Mar 30 16:11 linux.x64_11gR2_database_2of2.zip
4.安裝oracle環(huán)境所需要的依賴包-配置YUM源
安裝依賴包之前,一定要設(shè)置好服務(wù)器上的安裝源,原因是:可以在沒有互聯(lián)網(wǎng)的時候安裝服務(wù)所需依賴包;常用的安裝源有兩種方式:
(1) 配置本地yum源
新建配置文件vi /etc/yum.repos.d/localsource.repo輸入如下內(nèi)容:
[localsource]
name=localsource
baseurl=
enabled=1
gpgcheck=0
(2) 生成本地yum 緩存
注意:從Oracle 11g 11.2.0.2版本開始,在Linux x86_64上安裝時,只需要安裝64位的軟件包,但是,對于11.2.0.2之前的任何Oracle database 11g,下表中列出的32位和64位的安裝包都必須安裝
5.安裝oracle環(huán)境所需要的依賴包-安裝依賴包
(1)安裝依賴包
[root@oracledb ~]# yum -y install binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libXi libXtst make sysstat unixODBC unixODBC-devel zlib zlib-devel pcre-devel unzip
(2)安裝完成后,檢查依賴是否全部安裝成功
[root@oracledb ~]# rpm -q binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libXi libXtst make sysstat unixODBC unixODBC-devel zlib zlib-devel pcre-devel unzip | grep "not installed"
(3)創(chuàng)建所需的用戶組和用戶
如果要安裝Oracle數(shù)據(jù)庫,通常需要以下本地操作系統(tǒng)用戶組和用戶:
Oracle inventory組(通常為 oinstall)
OSDBA組 (通常為 dba)
OSOPER組 (通常為 oper)
Oracle軟件所有者(通常為 oracle)
創(chuàng)建用戶組和用戶:
[root@oracledb ~]# groupadd oinstall
[root@oracledb ~]# groupadd dba
[root@oracledb ~]# groupadd oper
[root@oracledb ~]# useradd -g oinstall -G dba oracle
(4)修改oracle用戶密碼:建議密碼配置為字符+數(shù)字+特殊字符
[root@oracledb ~]# passwd oracle
6.配置內(nèi)核參數(shù)和資源限制
(1)編輯配置文件vi /etc/sysctl.conf添加如下參數(shù):
vm.max_map_count = 655360
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 2147483648 ###最小值: 536870912
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
注意:如果系統(tǒng)中某個參數(shù)高于上面的參數(shù)的值 ,保留較大的值,上面的數(shù)值只是官方要求的最小值,可以根據(jù)系統(tǒng)調(diào)整數(shù)值,以優(yōu)化系統(tǒng)性能
(2)使內(nèi)核參數(shù)生效
[root@oracledb ~]# sysctl -p
7.創(chuàng)建oracle安裝目錄
如下目錄,根據(jù)自己的實(shí)際情況可做修改:
[root@oracledb ~]# mkdir -p /data/app/oracle/product/11.2.0
[root@oracledb ~]# cd /data/app/oracle/
[root@oracledb oracle]# mkdir oradata inventory fast_recovery_area
[root@oracledb ~]# chown -R oracle:oinstall /data/app/oracle
[root@oracledb ~]# chmod -R 775 /data/app/oracle
8.配置oracle用戶環(huán)境變量
編輯配置文件vi /home/oracle/.bash_profile添加如下內(nèi)容:
export ORACLE_BASE=/data/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0
export ORACLE_SID=orcl
export PATH=$PATH:$ORACLE_HOME/bin
9. 解壓下載好的兩個Oracle數(shù)據(jù)庫文件
[root@oracledb ~]# cd /opt
[root@oracledb ~]# unzip linux.x64_11gR2_database_1of2.zip -d /data
[root@oracledb ~]# unzip linux.x64_11gR2_database_2of2.zip -d /data
10. 編輯靜默安裝響應(yīng)文件
(1)切換到oracle用戶執(zhí)行
[root@oracledb ~]# su - oracle
(2)切換到響應(yīng)文件的目錄下
[oracle@oracledb ~]$ cp -R /data/database/response/ .
[oracle@oracledb ~]$ cd response/
[oracle@oracledb response]$ ls
dbca.rsp db_install.rsp netca.rsp
11.修改配置文件:vi /home/oracle/response/db_install.rsp,修改以下變量的值
oracle.install.option=INSTALL_DB_SWONLY
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/data/app/oracle/inventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=/data/app/oracle/product/11.2.0
ORACLE_BASE=/data/app/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba
DECLINE_SECURITY_UPDATES=true
12. 開始靜默安裝Oracle 11g
(1)開始安裝oracle數(shù)據(jù)庫
[oracle@oracledb ~]$ cd /data/database
[oracle@oracledb ~]$ ./runInstaller -silent -responseFile /home/oracle/response/db_install.rsp -ignorePrereq
注意:安裝期間可以使用tail命令查看oracle的安裝日志,且日志文件名稱是根
據(jù)自己的實(shí)際執(zhí)行時間確定的,安裝日志文件會在安裝時提示,需要等待3分鐘左右,注意不要停止運(yùn)行;安裝完成后有如下提示,如果有類似如下提示,說明安裝完成。
The following configuration scripts need to be executed as the "root" user.
#!/bin/sh
#Root scripts to run
/data/app/oraInventory/orainstRoot.sh
/data/app/oracle/product/11.2.0/db_1/root.sh
To execute the configuration scripts:
1. Open a terminal window
2. Log in as "root"
3. Run the scripts
4. Return to this window and hit "Enter" key to continue
Successfully Setup Software.
13.使用 root用戶執(zhí)行腳本
(1)切換到root用戶執(zhí)行
[root@oracledb ~]# su - root
(2)執(zhí)行兩個用戶腳本
[root@oracledb ~]# sh /data/app/oracle/inventory/orainstRoot.sh
[root@oracledb ~]# sh /data/app/oracle/product/11.2.0/root.sh
14.配置監(jiān)聽程序
(1)切換到oracle用戶執(zhí)行(建議退出重進(jìn)oracle用戶)
[root@oracledb ~]# su - oracle
(2)配置監(jiān)聽,查看輸出結(jié)果
[oracle@oracledb ~]$ netca /silent /responsefile /home/oracle/response/netca.rsp
(3)查看監(jiān)聽服務(wù)狀態(tài),若沒啟動需要啟動
[oracle@oracledb ~]$ lsnrctl status
[oracle@oracledb ~]$ lsnrctl start
查看結(jié)果:
Parsing command line arguments:
Parameter "silent" = true
Parameter "responsefile" = /data/etc/netca.rsp
Done parsing command line arguments.
Oracle Net Services Configuration:
Profile configuration complete.
Oracle Net Listener Startup:
Running Listener Control:
/data/app/oracle/product/11.2.0/bin/lsnrctl start LISTENER
Listener Control complete.
Listener started successfully.
Listener configuration complete.
Oracle Net Services configuration successful. The exit code is 0
(4)查看監(jiān)聽端口
[oracle@oracledb ~]$ netstat -tnpl | grep 1521
15.靜默創(chuàng)建數(shù)據(jù)庫
GDBNAME = "orcl"
SID = "orcl"
SYSPASSWORD = "oracle"
SYSTEMPASSWORD = "oracle"
SYSMANPASSWORD = "oracle"
DBSNMPPASSWORD = "oracle"
DATAFILEDESTINATION =/data/app/oracle/oradata
RECOVERYAREADESTINATION=/data/app/oracle/fast_recovery_area
CHARACTERSET = "ZHS16GBK"
TOTALMEMORY = " 6552 "
##其中TOTALMEMORY = " 6552 " 為6552 MB,物理內(nèi)存8G*80%
(2)切換到oracle用戶執(zhí)行
[root@oracledb ~]# su - oracle
(3)執(zhí)行靜默建庫
[oracle@oracledb ~]$ dbca -silent -responseFile /home/oracle/response/dbca.rsp
執(zhí)行過程如下:
Copying database files
1% complete
3% complete
11% complete
18% complete
26% complete
37% complete
Creating and starting Oracle instance
40% complete
45% complete
50% complete
55% complete
56% complete
60% complete
62% complete
Completing Database Creation
66% complete
70% complete
73% complete
85% complete
96% complete
100% complete
Look at the log file "/data/app/oracle/cfgtoollogs/dbca/orcl/orcl.log" for further details.
(4)查看進(jìn)程
[oracle@oracledb ~]$ ps -ef | grep ora_ | grep -v grep
(5)再次查看監(jiān)聽狀態(tài)進(jìn)行確認(rèn)
[oracle@oracledb ~]$ lsnrctl status
結(jié)果顯示:
The command completed successfully
16.至此數(shù)據(jù)庫就安裝成功了,下面我們登錄下數(shù)據(jù)庫
(1)切換到oracle用戶執(zhí)行
[root@oracledb ~]# su - oracle
(2)登錄數(shù)據(jù)庫
[oracle@oracledb ~]$ sqlplus / as sysdba
(3)查詢實(shí)例狀態(tài)
SQLselect status from v$instance;
(4)查看數(shù)據(jù)庫版本
SQL select * from v$version;
(5)激活scott用戶
SQLalter user scott account unlock;
SQLalter user scott identified by tiger;
SQLselect username,account_status from dba_users;
17.設(shè)置Oracle開機(jī)啟動
(1)修改配置文件vi /data/app/oracle/product/11.2.0/bin/dbstart 修改如下內(nèi)容:
將腳本中的ORACLE_HOME_LISTNER=$1,修改為ORACLE_HOME_LISTNER=$ORACLE_HOME
(2)修改配置文件vi /data/app/oracle/product/11.2.0/bin/dbshut 修改如下內(nèi)容:
將腳本中的ORACLE_HOME_LISTNER=$1,修改為ORACLE_HOME_LISTNER=$ORACLE_HOME
(3)修改配置文件 vi /etc/oratab修改如下內(nèi)容,
orcl:/data/app/oracle/product/11.2.0:Y
(4)新建文件:vi /etc/rc.d/init.d/oracle 注意:建議全部復(fù)制腳本內(nèi)容
#! /bin/bash
# oracle: Start/Stop Oracle Database 11g R2
# chkconfig: 345 90 10
# description: The Oracle Database is an Object-Relational Database Management System.
# processname: oracle
. /etc/rc.d/init.d/functions
LOCKFILE=/var/lock/subsys/oracle
ORACLE_HOME=/data/app/oracle/product/11.2.0
ORACLE_USER=oracle
case "$1" in
start)
if [ -f $LOCKFILE ]; then
echo $0 already running.
exit 1
fi
echo -n #34;Starting Oracle Database:"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl start"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbstart $ORACLE_HOME"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl start dbconsole"
touch $LOCKFILE
;;
stop)
if [ ! -f $LOCKFILE ]; then
echo $0 already stopping.
exit 1
fi
echo -n #34;Stopping Oracle Database:"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/lsnrctl stop"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/dbshut"
su - $ORACLE_USER -c "$ORACLE_HOME/bin/emctl stop dbconsole"
rm -f $LOCKFILE
;;
restart)
$0 stop
$0 start
;;
status)
if [ -f $LOCKFILE ]; then
echo $0 started.
else
echo $0 stopped.
fi
;;
*)
echo "Usage: $0 [start|stop|status]"
exit 1
esac
exit 0
(5)給 /etc/init.d/oracle添加執(zhí)行權(quán)限
[root@oracledb ~]# chmod +x /etc/init.d/oracle
(6)開機(jī)啟動oracle
[root@oracledb ~]# chkconfig oracle on
(7)給啟動文件加權(quán)限
[root@oracledb ~]# cd /data/app/oracle/product/11.2.0/bin/
[root@oracledb bin]# chmod 6751 oracle
[root@oracledb bin]# cd /var/tmp
[root@oracledb tmp]# chown -R oracle:oinstall .oracle
(8)重啟測試
[root@oracledb ~]# reboot
(9)切換到oracle用戶登錄狀態(tài)下
[root@oracledb ~]# su - oracle
[oracle@oracledb ~]$ sqlplus / as sysdba
(10)解除鎖定
SQL alter user SYSTEM account unlock;
(11)這時候就可以用Navicat連接了
SQL conn;
用戶名:SYSTEM
密碼:oracle
如果不能正確連接,改下密碼試試
alter user system identified by 新密碼
[root@oracledb ~]# mkdir -p /data/szzt
[root@oracledb ~]# cd /data/
[root@oracledb data]# chown oracle:oinstall -R szzt
[root@oracledb data]# ll
total 0
drwxr-xr-x 3 root root 20 Apr 8 21:14 app
drwxr-xr-x 8 root root 128 Aug 21 2009 database
drwxr-xr-x 2 oracle oinstall 6 Apr 14 16:17 szzt
[root@oracledb ~]# su - oracle
[oracle@oracledb ~]$ sqlplus / as sysdba
SQL conn cshi
Enter password: 登錄失敗
Connected.
SQL create temporary tablespace DB_DATA_TMP tempfile'/data/szzt/DB_DATA_TMP.dbf' size 500m autoextend on next 100m maxsize 10240m extent management local;
顯示結(jié)果:
Tablespace created.
SQL create tablespace DB_DATA logging datafile'/data/szzt/DB_DATA.dbf' size 2048m autoextend on next 100m maxsize 10240m extent management local;
顯示結(jié)果:
Tablespace created.
SQL create user ceshi identified by ceshi default tablespace DB_DATA temporary tablespace DB_DATA_TMP;
顯示結(jié)果:
User created.
SQL grant dba to ceshi;
顯示結(jié)果:
Grant succeeded.
SQL conn ceshi ###用戶名和密碼一樣,此時登錄成功
[oracle@oracledb ~]$ cd /data/app/oracle/product/11.2.0/bin/
注意:數(shù)據(jù)庫導(dǎo)出操作是在 源服務(wù)器 上進(jìn)行
[oracle@oracledb bin]$ exp 用戶名/密碼@ IP地址 /orcl file =/data/szzt/ceshi.dmp owner='用戶名'
Export terminated successfully without warnings.
注意:數(shù)據(jù)庫導(dǎo)入操作是在 目標(biāo)服務(wù)器 上進(jìn)行
[oracle@oracledb bin]$ imp ceshi/ceshi@ 10.100.1.10 /orcl file=/data/szzt/ceshi.dmp fromuser=ceshi touser=ceshi
顯示結(jié)果:可以看到導(dǎo)入的表過程(10.100.1.10是自己的目標(biāo)數(shù)據(jù)庫服務(wù)器)
Import terminated successfully without warnings .
(1)、數(shù)據(jù)導(dǎo)入完畢后,我們可以使用DBeaver對數(shù)據(jù)庫進(jìn)行遠(yuǎn)程管理
(2)、測試連接,沒問題后完成新建
(3)、連接上來后,我們就可以使用工具來進(jìn)行管理數(shù)據(jù)庫
請說明您所謂的排名是怎么排名的 是按工號還是按工資排名???
IC介紹
許多人正在使用Oracle Instant Client,它提供一個部署基于OCI、OCCI、JDBC OCI應(yīng)用容易和快速的方法。
通過添加更多的工具,Instant Client可以變成一個更加強(qiáng)大的工具,如下:
1. tnsping
2. sqlldr
3. tkprf
4. exp/imp
5. OCM
6. 你自己的工具
這樣做的主要優(yōu)點(diǎn)是:
1. 安裝是一件輕而易舉的事情,只要解壓即可完成。
2. 體積小,未壓縮100MB到150MB或壓縮50MB,它可以安裝在USB盤上
3. 不涉及到SA(軟件架構(gòu))
比較一個完整的Oracle安裝需要大量的磁盤空間,而且還涉及到SA。
IC需求
1. 一個帶有150MB+磁盤空間的Unix/Linux賬號:
hadoop@192.168.8.162:/home/hadoop/oracle
2. 安裝Oracle 11gR2的相同平臺,一個具有讀訪問權(quán)限的賬號:
root@192.168.8.192:/u01/product/oracle/11.2.0/db_1
IC安裝
從Oracle官方網(wǎng)址下載安裝包,
注:請根據(jù)操作系統(tǒng)版本下載相應(yīng)的安裝包,這里下載Linux X86-64安裝包。
instantclient-basic-linux.x64-11.2.0.4.0.zip
instantclient-jdbc-linux.x64-11.2.0.4.0.zip
instantclient-sdk-linux.x64-11.2.0.4.0.zip
instantclient-sqlplus-linux.x64-11.2.0.4.0.zip
注:下載Instant Client時需要創(chuàng)建一個Oracle賬號才能下載。
使用SSH客戶端使用安裝賬號登錄到服務(wù)器,在根目錄下創(chuàng)建一個oracle目錄:
$mkdir /home/hadoop/oracle
上傳所有壓縮包或至少basic和sqlplus兩個包到你賬號的根目錄下oracle中。
解壓到當(dāng)前目錄下完成安裝。
$ cd /home/hadoop/oracle
$ unzipinstantclient-basic-linux.x64-11.2.0.4.0.zip
$ unzipinstantclient-sqlplus-linux.x64-11.2.0.4.0.zip
$ unzip instantclient-sdk-linux.x64-11.2.0.4.0.zip
$ unzip instantclient-jdbc-linux.x64-11.2.0.4.0.zip
解壓完畢后會在當(dāng)前目錄下生成一個instantclient_11_2目錄。
$ ll /home/hadoop/oracle/instantclient_11_2
IC配置
配置下面的環(huán)境變量到你的Shell配置文件中。
$ vi ~/.bashrc
跳到文件的末尾,添加下面這些環(huán)境變量:
export RACLE_IC_HOME=/home/hadoop/oracle/instantclient_11_2
exportORACLE_HOME=$ORACLE_IC_HOME
exportTNS_ADMIN=$ORACLE_IC_HOME
exportPATH=$PATH:$ORACLE_IC_HOME
exportLD_LIBRARY_PATH=$ORACLE_IC_HOME
exportCLASSPATH=$ORACLE_IC_HOME/ojdbc6.jar:./
$ source ~/. bashrc
或 $ . ~/.bashrc
注:如果需要讓所有用戶都能使用,需要把上面的配置添加/etc/profile中。
在$ORACLE_IC_HOME目錄下創(chuàng)建一個tnsnames.ora文件:
$ vi /home/hadoop/oracle/instantclient_11_2/tnsnames.ora
orcl=(description=(address=(protocol=tcp)(host=192.168.8.161)(port=1521))(connect_data=(server=dedicated)(service_name=wcdma)))
或
ora =(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL = TCP)(HOST = 192.168.8.161)(PORT = 1521)))(CONNECT_DATA =(SERVER =DEDICATED)(SERVICE_NAME = wcdma)))
SQL*Plus
$ sqlplus kqi/kqi@192.168.8.161:1521/wcdma
或
$ sqlplus kqi/kqi@orcl
SQL*Plus: Release 11.2.0.4.0 Production onThu Nov 20 14:01:49 2014
Copyright (c) 1982, 2013, Oracle. All rights reserved.
Connected to:
Oracle Database 11g Enterprise EditionRelease 11.2.0.2.0 - 64bit Production
With the Partitioning, OLAP, Data Miningand Real Application Testing options
SQL
ERROR:
ORA-12154: TNS:could not resolve theconnect identifier specified
對于這種問題,排除添加的配置格式錯誤后??赡茉蚴亲x取的tnsnames.ora路徑根本就不是$ORACLE_HOME/network/admin下。
注:tnsnames.ora文件的查找路徑順序?yàn)椋?/p>
$HOME = $TNS_ADMIN = /etc =$ORACLE_HOME/network/admin/。
現(xiàn)在我們已經(jīng)有一個構(gòu)建自己的Instant Client包的基礎(chǔ)了。下面是Instant Client的核心文件(位于/home/hadoop/oracle/instantclient_11_2中):
1. libclntsh.so.11.1:客戶端代碼庫
2. libociei.so:OCI InstantClient數(shù)據(jù)共享庫
3. libnnz11.so:安全庫
4. libocci.so.11.1:Oracle C++調(diào)用接口庫
5. libocijdbc11.so:JDBC OCI庫
6. ojdbc6/5.jar:JDBC驅(qū)動(OCI和Thin)
7. orai18n.jar:字符集轉(zhuǎn)換和本地支持庫
Tnsping
從安裝Oracle的服務(wù)器上拷貝tnsping過來,執(zhí)行命令:
$ cd /home/hadoop/oracle/instantclient_11_2
$ scp root@192.168.8.192:/u01/product/oracle/11.2.0/db_1/bin/tnsping./
現(xiàn)在讓在IC安裝服務(wù)器上嘗試運(yùn)行下它:
$ tnsping ora
TNS Ping Utility for Linux: Version11.2.0.4.0 - Production on 20-NOV-2014 14:30:21
Copyright (c) 1997, 2013, Oracle. All rights reserved.
Message 3511 not found; No message file forproduct=network, facility=TNSMessage 3512 not found; No message file forproduct=network, facility=TNSMessage 3513 not found; No message file forproduct=network, facility=TNSMessage 3509 not found; No message file forproduct=network, facility=TNS
運(yùn)行后tnsping抱怨一些文件丟失,更具體的說一個消息文件丟失。現(xiàn)在,我們把該文件從Oracle安裝服務(wù)器上拷貝過來,進(jìn)入到instantclient_11_2目錄:
$ mkdir -p network/mesg
$ cd network/mesg/
現(xiàn)在從安裝Oracle服務(wù)上拷貝tnsus.msb文件到該目錄中:
$ scp root@192.168.8.192:/u01/product/oracle/11.2.0/db_1/network/mesg/tnsus.msb ./
讓我們再嘗試一次tnsping,結(jié)果如下:
$ tnsping ora
TNS Ping Utility for Linux: Version11.2.0.4.0 - Production on 20-NOV-2014 14:49:54
Copyright (c) 1997, 2013, Oracle. All rights reserved.
Used parameter files:
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION=(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.8.161)(PORT =1521)))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = wcdma)))
OK (0 msec)
Sqlldr
本節(jié)將添加另外一個工具sqlldr。
首先,我們從安裝Oracle的服務(wù)器上拷貝sqlldr到IC安裝目錄instantclient_11_2下。
$ cd /home/hadoop/oracle/instantclient_11_2
$ scproot@192.168.8.192:/u01/product/oracle/11.2.0/db_1/bin/sqlldr ./
嘗試運(yùn)行它:
$ sqlldr
Message 2100 not found; No message file forproduct=RDBMS, facility=ULMessage 2100 not found; No message file forproduct=RDBMS, facility=UL
首先我們需要在instantclient_11_2下創(chuàng)建rdbms/mesg目錄。
$ cd /home/hadoop/oracle/instantclient_11_2
$ mkdir -p rdbms/mesg
$ cd rdbms/mesg
把ORACLE安裝目錄下rdmsb/mesg/ulus.msb拷貝到當(dāng)前目錄。
$ scp root@192.168.8.192:/u01/product/oracle/11.2.0/db_1/rdbms/mesg/ulus.msb./
現(xiàn)在,讓我們再次嘗試運(yùn)行它。
$ sqlldr
SQL*Loader: Release 11.2.0.4.0 - Productionon Thu Nov 20 16:40:10 2014
Copyright (c) 1982, 2011, Oracle and/or itsaffiliates. All rights reserved.
Usage: SQLLDR keyword=value[,keyword=value,...]
Valid Keywords:
Exp/imp
從安裝Oracle服務(wù)器上拷貝二進(jìn)制文件過來。
$ cd /home/hadoop/oracle/instantclient_11_2
$ scp root@192.168.8.192:/u01/product/oracle/11.2.0/db_1/bin/imp ./
$ scp root@192.168.8.192:/u01/product/oracle/11.2.0/db_1/bin/exp ./
嘗試運(yùn)行imp和exp,結(jié)果如下:
$ imp
Message 100 not found; No message file forproduct=RDBMS, facility=IMP: Release 11.2.0.4.0 - Production on Thu Nov 2017:02:57 2014
Copyright (c) 1982, 2011, Orac
Invalid format of Import utility name
Verify that ORACLE_HOME is properly set
Import terminated unsuccessfully
IMP-00000: Message 0 not found; No messagefile for product=RDBMS, facility=IMP
$ exp
Message 206 not found; No message file forproduct=RDBMS, facility=EXP: Release 11.2.0.4.0 - Production on Thu Nov 20 17:03:392014
Copyright (c) 1982, 2011, Orac
Invalid format of Export utility name
Verify that ORACLE_HOME is properly set
Export terminated unsuccessfully
EXP-00000: Message 0 not found; No messagefile for product=RDBMS, facility=EXP
再從安裝Oracle服務(wù)器上拷貝rdbms/mesg下的expus.msb和ipus.msb過來。
$ cd rdbms/mesg/
$ scproot@192.168.8.192:/u01/product/oracle/11.2.0/db_1/rdbms/mesg/impus.msb ./
$ scproot@192.168.8.192:/u01/product/oracle/11.2.0/db_1/rdbms/mesg/expus.msb ./
再次運(yùn)行imp/exp工具錯誤提示消失,可以正常運(yùn)行。
Tkprof
現(xiàn)在我們繼續(xù)添加我最喜歡的工具tkprof。
從安裝Oracle的服務(wù)器拷貝tkprof到instantclient_11_2目錄下。
$ cd /home/hadoop/oracle/instantclient_11_2
$ scp root@192.168.8.192:/u01/product/oracle/11.2.0/db_1/bin/tkprof ./
$ mkdir -p oracore/mesg/
$ cd oracore/mesg/
$ scproot@192.168.8.192:/u01/product/oracle/11.2.0/db_1/oracore/mesg/lrmus.msb ./
使用示例:
$ tkprof test.trc test.out
Instant Client Bundle
現(xiàn)在,我們已經(jīng)讓所有工具都能正常工作。簡單的使用工具壓縮打包instantclient_11_2目錄,這樣你就獲得你自己的Instant Client包。例如:
$ cd /home/hadoop/oracle
$ tar zcf instantclient_11_2.tar.gzintantclient_11_2
正如你所看到的,打包成的instant client帶有tnsping,sqlldr, exp/imp,tkprof工具,這讓IC更加的功能強(qiáng)大。
安裝自定義的IC包步驟如下:
1. 上傳到服務(wù)器上解壓縮
2. 修改環(huán)境變量
$ vi ~/.bashrc
跳到文件的末尾,添加下面這些環(huán)境變量:
export ORACLE_IC_HOME=解壓目錄/instantclient_11_2
export ORACLE_HOME=$ORACLE_IC_HOME
export TNS_ADMIN=$ORACLE_IC_HOME
export PATH=$PATH:$ORACLE_IC_HOME
export LD_LIBRARY_PATH=$ORACLE_IC_HOME
exportCLASSPATH=$ORACLE_IC_HOME/ojdbc6.jar:./
$ source ~/. bashrc
或 $ . ~/.bashrc
3. 添加連接數(shù)據(jù)庫的配置
$ vi $ORACLE_IC_HOME/tnsnames.ora
安裝完成,現(xiàn)在就可以使用Instant Client中的工具啦!
create or replace package UBS_USER_PKG is
type user_record_type is record
(
userID number(4),
username varchar2(20),
createdate date,
deptID number(4),
gender number(1),
job varchar2(30),
remarks varchar2(200),
birthday date,
jobexperience varchar2(200),
education varchar2(200),
relationship varchar2(200)
);
type user_ref_cursor is ref cursor return user_record_type;
type user_table_type is table of user_record_type index by binary_integer;
procedure user_query(dmlset in out user_ref_cursor);
procedure user_lock(dmlset in out user_table_type);
procedure user_insert(dmlset in out user_table_type);
procedure user_update(dmlset in out user_table_type);
procedure user_delete(dmlset in out user_table_type);
end UBS_USER_PKG;
/
create or replace package body UBS_USER_PKG is
procedure user_query(dmlset in out user_ref_cursor) is
begin
open dmlset for
select
userid,
username,
createdate,
deptid,
gender,
job,
remarks,
birthday,
jobexperience,
education,
relationship
from ubs_user;
end;
procedure user_lock(dmlset in out user_table_type) is
userID_holder number;
begin
select userID into userID_holder from ubs_user where userID=dmlset(1).userID for update;
end;
procedure user_insert(dmlset in out user_table_type) is
begin
insert into ubs_user
(
userid,
username,
createdate,
deptid,
gender,
job,
remarks,
birthday,
jobexperience,
education,
relationship
)
values
(
dmlset(1).userid,
dmlset(1).username,
dmlset(1).createdate,
dmlset(1).gender,
dmlset(1).job,
dmlset(1).remarks,
dmlset(1).birthday,
dmlset(1).jobexperience,
dmlset(1).education,
dmlset(1).education,
dmlset(1).relationship
);
end;
procedure user_update(dmlset in out user_table_type) is
begin
update ubs_user set