標籤:oracle 12.2 樣本 schema
在做Oracle資料庫實驗時都會用到一些樣本SCHEMA如:HR、OE、SH等,在Oracle11g版本時在DBCA時直接勾選Sample Schemas就可以安裝這些樣本SCHEMA,如:
650) this.width=650;" src="https://s3.51cto.com/wyfs02/M02/9E/B0/wKioL1mUaMaBJvtbAAEnBYK5ZxI858.png" title="1.PNG" alt="wKioL1mUaMaBJvtbAAEnBYK5ZxI858.png" />但到了Oracle12.2 版本,也有一個樣本Schemas選項卡如所示:
650) this.width=650;" src="https://s2.51cto.com/wyfs02/M01/9E/B0/wKioL1mUaQ6Ttns9AAC5h-qydjM478.png" title="2.PNG" alt="wKioL1mUaQ6Ttns9AAC5h-qydjM478.png" />但是資料庫安裝完成後卻還是沒有這些樣本SCHEMA,到底是怎麼回事呢?我們來查一下官方文檔:
Starting with Oracle Database 12c Release 2, the latest version of the sample schema scripts are available on GitHub at https://github.com/oracle/db-sample-schemas/releases/latest.
During a complete installation of Oracle Database, the HR schema can be installed either manually or automatically when creating a database using the dbca
option. All the other sample schemas must be installed manually via the scripts available on GitHub.
從上面的官方文檔中我們可以看到從Oracle12.2版本開始,樣本Schemas的指令碼被放到了GitHub上,在DBCA安裝時只會安裝hr樣本Schema。從文檔中給出的指定地址下載樣本Schema安裝指令碼:
650) this.width=650;" src="https://s5.51cto.com/wyfs02/M02/9E/B0/wKioL1mUalCh5__3AABZYHHGMr4457.png" title="3.PNG" alt="wKioL1mUalCh5__3AABZYHHGMr4457.png" />
從README.txt文檔中找到安裝方法,開始安裝:
[email protected]>@mksamplespecify password for SYSTEM as parameter 1:Enter value for 1: 123456specify password for SYS as parameter 2:Enter value for 2: 123456specify password for HR as parameter 3:Enter value for 3: hrspecify password for OE as parameter 4:Enter value for 4: oespecify password for PM as parameter 5:Enter value for 5: pmspecify password for IX as parameter 6:Enter value for 6: ixspecify password for SH as parameter 7:Enter value for 7: shspecify password for BI as parameter 8:Enter value for 8: bispecify default tablespace as parameter 9:Enter value for 9: usersspecify temporary tablespace as parameter 10:Enter value for 10: tempspecify log file directory (including trailing delimiter) as parameter 11:Enter value for 11: /home/oracle/dbcaspecify connect string as parameter 12:Enter value for 12: localhost:1521/ora12cSample Schemas are being created ...mkdir: cannot create directory ‘/home/oracle/dbca’: File existsConnected.DROP USER hr CASCADE *ERROR at line 1:ORA-01918: user ‘HR‘ does not existDROP USER oe CASCADE *ERROR at line 1:ORA-01918: user ‘OE‘ does not existDROP USER pm CASCADE *ERROR at line 1:ORA-01918: user ‘PM‘ does not existDROP USER ix CASCADE *ERROR at line 1:ORA-01918: user ‘IX‘ does not existDROP USER sh CASCADE *ERROR at line 1:ORA-01918: user ‘SH‘ does not existDROP USER bi CASCADE *ERROR at line 1:ORA-01918: user ‘BI‘ does not existConnected.SP2-0310: unable to open file "__SUB__CWD__/human_resources/hr_main.sql"Connected.SP2-0310: unable to open file "__SUB__CWD__/order_entry/oe_main.sql"Connected.SP2-0310: unable to open file "__SUB__CWD__/product_media/pm_main.sql"Connected.SP2-0310: unable to open file "__SUB__CWD__/info_exchange/ix_main.sql"Connected.SP2-0310: unable to open file "__SUB__CWD__/sales_history/sh_main.sql"Connected.SP2-0310: unable to open file "__SUB__CWD__/bus_intelligence/bi_main.sql"Connected.not spooling currentlySP2-0310: unable to open file "__SUB__CWD__/mkverify.sql"
從上面看到輸出報錯,沒有安裝成功。報錯的是“__SUB__CWD__”沒有找到,開啟mksample.sql檔案,確實有這個變數,但不知道在哪裡聲明的。
重新查看README.md文檔看到需要把“__SUB__CWD__”這個變數替換為當前路徑,還給出了命令:
[[email protected] db-sample-schemas-12.2.0.1]$ perl -p -i.bak -e ‘s#__SUB__CWD__#‘$(pwd)‘#g‘ *.sql */*.sql */*.dat
執行完上面的指令碼後重新安裝樣本Schema:
[email protected]>@mksample 123456 123456 hr oe pm ix sh bi users temp /home/oracle/dbca/ 192.168.56.22:1521/ora12c
最終安裝成功:
[email protected]>select username,created from dba_users where created>sysdate-1;USERNAME CREATED------------------------------ -----------------OE 20170816 23:32:22SH 20170816 23:34:25PM 20170816 23:33:13IX 20170816 23:34:12BI 20170816 23:36:20HR 20170816 23:32:07
參考:http://docs.oracle.com/database/122/COMSC/installing-sample-schemas.htm#COMSC-GUID-B0BEE222-D8B0-4B68-B359-DEA153956EF6
本文出自 “DBA Fighting!” 部落格,請務必保留此出處http://hbxztc.blog.51cto.com/1587495/1956932
Oracle 12.2安裝樣本schema