自己動手建立免安裝版Oracle客戶端(for 9i/10g)

iihero發表於2009-03-08

宣告: 本文均為作者本人(iihero@CSDN)探索學習Oracle資料庫過程當中的經驗總結,其方法或過程只能用於開發和學習,不能將其用於商業產品釋出,違者後果自負。

 

Oracle資料庫的客戶端向來以“肥大”著稱,即使是它的instant client,也不算瘦。個人以為,雖然instant client釋出並使用了有一段時間,但是比起它的原裝產品來說,穩定性和安全性肯定有些差距。所以,我寧可自己手動extract一些有用的包,為開發所用,也不願意去單獨折騰個instant client來配置。

 

這裡就以9i為例,在你安裝完一份Oracle伺服器版或Oracle客戶端,在安裝的目標目錄會有一份完整的目錄列表。有很多很多都是用不著的檔案。

 

我們通常要用的功能也就是:

1. sqlplus命令列,imp, exp, tnsping, sqlldr (用於管理)

2. oci介面庫,pro*c庫,jdbc, odbc (甚或oledb)等 (用於開發)

有了這些功能,基本上可以做很多事情了。

 

製作原理:

1. 抽取相關目錄,釋出到一個新目錄。

2. 生成登錄檔檔案到這個新目錄。

3. 將這個新目錄複製或移動到新機器的新目錄裡邊,就可以註冊使用了。

 

下邊是我編寫的一個釋出的批處理指令碼oraclient_dist.bat,以及過濾檔案exclude.txt

exclude.txt 檔案要與oraclient_dist.bat檔案位於同一目錄當中

其命令格式是:

oraclient_dist.bat -from d:/oracle/ora92 -to e:/dist -inst d://ora92client

意思是從源:d:/oracle/ora92目錄下邊提取免安裝包到目錄e:/dist裡頭,最終安裝目錄定製在d:/ora92client。

 

@echo off
rem
rem Copyright (c) 2005 ~ 2009, iihero@CSDN
rem
rem This script will ship an Simple Oracle client from an 
rem    installed Oracle9i/10g server or client package.
rem 
rem Any issues, please notify me: iiihero@hotmail.com
rem This script only can be used for learning/researching on oracle db.
rem 

setlocal

:LOOP
    set arg=%1
    if %arg%! == ! goto END_LOOP
    if %arg%! == -help! goto SET_HELP
    if %arg%! == -h! goto SET_HELP
    if %arg%! == -from! goto SET_FROM
    if %arg%! == -to! goto SET_TO
    if %arg%! == -inst! goto SET_INST
    goto LOOP

:SET_FROM
    shift
    set ORA_FROM=%1
    shift
    goto LOOP

:SET_TO    
    shift
    set ORA_TO=%1
    shift
    goto LOOP
:SET_INST
    shift
    set INSTALL_DIR=%1
    shift
    goto LOOP
    
:END_LOOP

echo ORA_FROM = %ORA_FROM%
if %ORA_FROM%! == ! set ORA_FROM=%ORACLE_HOME%
if %ORA_FROM%! == ! goto ERROR_RUNTIME
if %ORA_TO%! == ! goto SET_HELP
if not exist %ORA_TO% goto SET_HELP
if %INSTALL_DIR%! == ! goto SET_HELP

mkdir %ORA_TO%\oracle
set ORACLIENT="%ORA_TO%\oracle"
echo "Begin distribute files into %ORACLIENT%"

mkdir "%ORACLIENT%\network"
xcopy "%ORA_FROM%\network\admin" "%ORACLIENT%\network\admin" /Q /S /I
xcopy "%ORA_FROM%\network\mesg" "%ORACLIENT%\network\mesg" /Q /S /I

xcopy "%ORA_FROM%\ocommon\nls\admin" "%ORACLIENT%\ocommon\nls\admin" /Q /S /I
xcopy "%ORA_FROM%\ocommon\nls\mesg" "%ORACLIENT%\ocommon\nls\mesg" /Q /S /I

xcopy "%ORA_FROM%\odbc" "%ORACLIENT%\odbc" /Q /S /I
xcopy "%ORA_FROM%\oracore" "%ORACLIENT%\oracore" /Q /S /I

xcopy "%ORA_FROM%\rdbms\mesg" "%ORACLIENT%\rdbms\mesg" /Q /S /I
xcopy "%ORA_FROM%\sqlplus\mesg" "%ORACLIENT%\sqlplus\mesg" /Q /S /I

xcopy "%ORA_FROM%\bin" "%ORACLIENT%\bin" /Q /S /I /EXCLUDE:exclude.txt
xcopy "%ORA_FROM%\oci\lib" "%ORACLIENT%\oci\lib" /Q /S /I
xcopy "%ORA_FROM%\oci\include" "%ORACLIENT%\oci\include" /Q /S /I

xcopy "%ORA_FROM%\jdbc\lib" "%ORACLIENT%\jdbc\lib" /Q /S /I
xcopy "%ORA_FROM%\jdbc\Readme.txt" "%ORACLIENT%\jdbc\" /Q /S /I

xcopy "%ORA_FROM%\precomp\admin" "%ORACLIENT%\precomp\admin" /Q /S /I
xcopy "%ORA_FROM%\precomp\mesg" "%ORACLIENT%\precomp\mesg" /Q /S /I
xcopy "%ORA_FROM%\precomp\lib" "%ORACLIENT%\precomp\lib" /Q /S /I
xcopy "%ORA_FROM%\precomp\public" "%ORACLIENT%\precomp\public" /Q /S /I

echo "Begin register entry into %ORACLIENT%\oraclient.reg"
echo Windows Registry Editor Version 5.00 >> %ORACLIENT%\oraclient.reg

echo [HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\Oracle in OraHome] >> %ORACLIENT%\oraclient.reg
echo "APILevel"="1" >> %ORACLIENT%\oraclient.reg
echo "CPTimeout"="60" >> %ORACLIENT%\oraclient.reg
echo "ConnectFunctions"="YYY" >> %ORACLIENT%\oraclient.reg
echo "Driver"="%INSTALL_DIR%\\BIN\\SQORA32.DLL" >> %ORACLIENT%\oraclient.reg
echo "DriverODBCVer"="03.51" >> %ORACLIENT%\oraclient.reg
echo "FileUsage"="0" >> %ORACLIENT%\oraclient.reg
echo "Setup"="%INSTALL_DIR%\\BIN\\SQORAS32.DLL" >> %ORACLIENT%\oraclient.reg
echo "SQLLevel"="1" >> %ORACLIENT%\oraclient.reg

echo [HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE] >> %ORACLIENT%\oraclient.reg
echo "ORACLE_HOME"="%INSTALL_DIR%" >> %ORACLIENT%\oraclient.reg
echo "ORACLE_HOME_NAME"="OraHome" >> %ORACLIENT%\oraclient.reg
echo "NLS_LANG"="NA" >> %ORACLIENT%\oraclient.reg

echo [HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\ALL_HOMES] >> %ORACLIENT%\oraclient.reg
echo "HOME_COUNTER"="1" >> %ORACLIENT%\oraclient.reg
echo "DEFAULT_HOME"="OraHome" >> %ORACLIENT%\oraclient.reg
echo "LAST_HOME"="0" >> %ORACLIENT%\oraclient.reg

echo [HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\ALL_HOMES\ID0] >> %ORACLIENT%\oraclient.reg
echo "NAME"="OraHome" >> %ORACLIENT%\oraclient.reg
echo "PATH"="%INSTALL_DIR%" >> %ORACLIENT%\oraclient.reg
echo "NLS_LANG"="NA" >> %ORACLIENT%\oraclient.reg

echo [HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\HOME0] >> %ORACLIENT%\oraclient.reg
echo "ID"="0" >> %ORACLIENT%\oraclient.reg
echo "ORACLE_GROUP_NAME"="Oracle - OraHome" >> %ORACLIENT%\oraclient.reg
echo "ORACLE_HOME_NAME"="OraHome" >> %ORACLIENT%\oraclient.reg
echo "ORACLE_HOME"="%INSTALL_DIR%" >> %ORACLIENT%\oraclient.reg
echo "NLS_LANG"="SIMPLIFIED CHINESE_CHINA.ZHS16GBK" >> %ORACLIENT%\oraclient.reg
echo "ORACLE_HOME_KEY"="Software\\ORACLE\\HOME0" >> %ORACLIENT%\oraclient.reg

echo "Begin genrating readme file for Oracle client into %ORACLIENT%\readme.txt"
echo 本程式是Oracle 9.2 for windows的簡化客戶端版本。>> %ORACLIENT%\readme.txt
echo 帶有最基礎的一些功能: sqlplus(w), exp, imp, oci, pro*c, ocopy, tkprof, tnsping, odbc, jdbc>> %ORACLIENT%\readme.txt
echo 1. 將%ORACLIENT%目錄移動到目標目錄: %INSTALL_DIR", >> %ORACLIENT%\readme.txt
echo 2. 匯入登錄檔oracleint.reg之後,將bin目錄全路徑新增到path之後,>> %ORACLIENT%\readme.txt
echo 3. 編輯%INSTALL_DIR%\network\admin\tnsnames.ora檔案,新增適當的servicename>> %ORACLIENT%\readme.txt
echo 就可以正常使用.>> %ORACLIENT%\readme.txt>> %ORACLIENT%\readme.txt
echo 有問題,歡迎聯絡:iiihero@hotmail.com (iihero@CSDN)>> %ORACLIENT%\readme.txt

echo "Successfully distribute oracle client into %ORACLIENT%!!!"

goto END

:SET_HELP
echo "Usage:"
echo "oraclient_dist -from <ORACLE_HOME> -to <TargetDir> -inst <InstallDir>"
echo "eg:  oraclient_dist -from d:\oracle\ora92 -to f:\income -inst d:\\ora92"
echo "InstallDir format: d:\\ora92 (there should be 2 '\' in the path)"
echo "Thanks!   iiihero@hotmail.com (iihero@CSDN) "
goto END

:ERROR_RUNTIME
echo "Please set ORACLE_HOME or use as the help"

:END
endlocal



最終你還可以將目標目錄壓縮,也就30來M,最終使用時,參見釋出後生成的readme.txt檔案。

 

exclude.txt檔案內容如下:

C-sharp程式碼 
  1. .bat  
  2. .bmp  
  3. \COREJAVA  
  4. \OracleNet  
  5. \ag  
  6. \ldap  
  7. \hs  
  8. \ib  
  9. \omts  
  10. \scc  
  11. \snmim  
  12. \va  
  13. \vm  
  14. \vo  
  15. \vs  
  16. \xp  

 

相關文章