Oracle Final Exam Notes

Automatic Sql Script Sample

--1. 先用管理者登入
sqlplus / as sysdba << EOF

--2. 如果有需要建立 TABLESPACE 就執行以下SCRIPT 
-- "NEWONE" 可以改成題目要求的.ex. "NEWTWO"   (雙引號要保留喔)
-- /opt/oracle/oradata/orcl/NewOne.dbf 路徑以及檔明也是試題目而變動的
CREATE SMALLFILE TABLESPACE "NEWONE" DATAFILE '/opt/oracle/oradata/orcl/NewOne.dbf' 
SIZE 100M AUTOEXTEND ON NEXT 1M MAXSIZE UNLIMITED LOGGING 
EXTENT MANAGEMENT LOCAL SEGMENT SPACE MANAGEMENT AUTO 

--3. 先DROP SCHEMA 擁有者 (避免已經存在不能新增)
-- elmasri 可以改成題目要求的 SCHEMA 名稱
drop user elmasri cascade;

--4. 新增新的 SCHEMA
-- elmasri 可以改成題目要求的 SCHEMA 名稱
-- users 可以改成題目要求的 TABLESPACE(步驟2)
create user elmasri identified by elmasri
default tablespace users;

--5. 允許 連線跟使用 resource 的權限 給剛剛建立的 SCHEMA
-- elmasri 可以改成題目要求的 SCHEMA 名稱
grant connect, resource to elmasri;

--6. 利用剛剛建立的 SCHEMA 做連線
-- elmasri/elmasri 看成 帳號/密碼
connect elmasri/elmasri;

--7. 依照題目建立 TABLE
DROP TABLE employee CASCADE CONSTRAINTS;
CREATE TABLE employee (
  fname    varchar2(15) not null, -- 欄位名稱 	欄位型別(欄位型別大小)	是否允許 NULL
  minit    varchar2(1),
  lname    varchar2(15) not null,
  ssn      char(9),
  bdate    date,
  address  varchar2(30),
  sex      char,
  salary   number(10,2),
  superssn char(9),
  dno      number(4),
  primary key (ssn),-- 主 KEY
  foreign key (superssn) references employee(ssn)
--  foreign key (dno) references department(dnumber) 此行不能執行因為 department 表格還沒被建立 所以等到建立完表格 DEPARTMENT 再去 直行 ALTER TABLE 動作
);


DROP TABLE department CASCADE CONSTRAINTS;
CREATE TABLE department (
  dname        varchar2(15) not null,
  dnumber      number(4),
  mgrssn       char(9) not null, 
  mgrstartdate date,
  primary key (dnumber), -- 主 KEY
  unique (dname), -- 唯一值
  foreign key (mgrssn) references employee(ssn) --參考外部健 foreign key (表內某欄位) references 外部表格(外部表格的某欄位)
);

alter table employee add (
  foreign key (dno) references department(dnumber)
);
...

--8. 以下是填肉的部份拉
DELETE FROM employee;
INSERT INTO employee VALUES ('James', 'E', 'Borg',
        '888665555', '10-NOV-27', 'Houston,TX', 'M', 55000, null, null);
...

DELETE FROM department;
INSERT INTO department VALUES ('Research', 5, '333445555', '22-MAY-78');
...

UPDATE employee SET DNO = 5 WHERE ssn = '333445555';
...

INSERT INTO employee VALUES ('John', 'B', 'Smith',
        '123456789', '09-Jan-55', 'Houston,TX', 'M', 30000, '333445555', 5);
...
INSERT INTO employee VALUES ('Ahmad', 'V', 'Jabbar',
        '987987987', '29-MAR-59', 'Houston,TX', 'M', 25000, '987654321', 4);

DELETE FROM project;
INSERT INTO project VALUES ('ProductX', 1, 'Bellaire',  5);
...

DELETE FROM dept_locations;
INSERT INTO dept_locations VALUES (1, 'Houston');
...

DELETE from dependent;
INSERT INTO dependent VALUES ('333445555','Alice','F','05-APR-76','Daughter');
...

DELETE FROM works_on;
INSERT INTO works_on VALUES ('123456789', 1,  32.5);
...

exit;
EOF

Hopes this all will help you guys!!

[References]

elmasri.sh Download

Oracle 期中考注意事項

5/7-2008 期中考囉!!
大家都在忙安裝 Oracle (安裝步驟)....(考試會考)
至於之前同學有問到考試當天是不是要自己燒兩片 CD 出來已備考試當天使用
哪兩片呢? 1.Enterprise-R4-U6-i386-disc3.iso  (以下這段會用到這 一片)
+ Install the pre-requisite rpms from the EL4 dvd
 # cd /media/cdrom/Enterprise/RPMS/
 # rpm -ivh libaio-0.3.105-2.i386.rpm  (the DB needs this)
2.oracle10gR2_server.iso

畢竟地球在暖化,實在不能再這樣浪費資源了!!

那要如何只靠著 ISO 檔案就去應付考試呢?以下是教學:

  1. 老師他說會幫我們先安裝好 LINUX到 VMWARE 所以到時候我們會有類似這樣的檔案 otherlinux.vmx
  2. 先備份 otherlinux.vmx 以防萬一改壞
  3. 利用 記事本 或 Notepad++ 打開 otherlinux.vmx
  4. 找出類似以下這段
    ide1:0.present 或 ide1:0.fileName 或 ide1:0.deviceType
  5. 改成以下後存檔
  6. 這次開啟應該就會載入 CD 囉

注意:此更改需要重開機才會有效

以下是我的安裝筆記

Installing Oracle Database 10gR2 on EL4U5 Linux x86  (Chi-Chung Lee)
這個檔案為了中華大學教學的目的修改自Oracle OTN網站上的檔案而完成
檔名: Oracle Database 10g Rel 2 and Oracle Apex 2.2.1 on OEL4u4 
網址:http://www.oracle.com/technology/tech/linux/install/index.html
Feb 2008

### Install Oracle 10g (10.2.0.1) on EL4
Boot from EL4 CD or dvd
press enter for graphical install
 ** Need at least 512MB RAM / 2.5GB Space **
+ Select custom package install

+ Automaticaly or Manually partition your hard drive with Disk Druid
 /tmp = 512MB ext3 fixed size
 /boot = 128MB ext3 fixed size
 swap = 1024MB fixed size
 / = fill to maximum allowable size

+ Accept defaults for GRUB boot loader, configure networking, set hostname eg.joburg

+ Most Linux distros and EL4 ship with default security preferences locked down.
For testing purposes I typically turn off the firewall and disable SE Linux.

+ Set language preferences and root password

+ Make sure the packages essential for installing Oracle are selected.
  Desktop : X Window System; Gnome or KDE
  Editors : at least one editor - vi etc.
  Graphical Internet : a web browser - firefox
  Development : Development Tools, and Legacy Software Development
  System : Administration Tools (useful)

+ Uncheck the non-essential packages.
  Servers : Web Server, and Windows File Server
  System : Printing support


For post-install configuration login as root
--------------------------------------------
+ Install the pre-requisite rpms from the EL4 dvd //PS:需要第三光碟片
 # cd /media/cdrom/Enterprise/RPMS/
 # rpm -ivh libaio-0.3.105-2.i386.rpm  (the DB needs this)
 

+ create groups
 # /usr/sbin/groupadd oinstall
 # /usr/sbin/groupadd dba
 # /usr/sbin/groupadd oper

+ create OS user oracle with group permissions and home /home/oracle
 # /usr/sbin/useradd -g oinstall -G dba,oper -d /home/oracle oracle

+ set user oracle's password
 # /usr/bin/passwd oracle

+ Append user oracle's bash profile with PATH and ORACLE:BASE,HOME and SID information
 # vi /home/oracle/.bash_profile

 umask 022
 PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
 LD_LIBRARY_PATH=/usr/lib:/usr/X11R6/lib

 ORACLE_BASE=/u01/app/oracle
 ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
 ORACLE_SID=orcl
 PATH=$ORACLE_HOME/bin:$PATH

 export PATH LD_LIBRARY_PATH ORACLE_BASE ORACLE_HOME ORACLE_SID

+ Create the directory for the software installation and assign ownership to oracle:oinstall
 # mkdir -p /u01/app/oracle
 # chown -R oracle:oinstall /u01/app
 # chmod -R 775 /u01/app

+ Make sure the correct kernel parmeters are appended to sysctl.conf
 # vi /etc/sysctl.conf (these can be easily copied from the Quick Installation Guide
                              for Linux x86 doc on the Oracle10g CD)
 kernel.shmall = 2097152
 kernel.shmmax = 2147483648
 kernel.shmmni = 4096
 kernel.sem = 250 32000 100 128
        net.core.rmem_default = 262144
 net.core.rmem_max = 262144
 net.core.wmem_default = 262144
 net.core.wmem_max = 262144
 fs.file-max = 65536
 net.ipv4.ip_local_port_range = 1024 65000

+ set the kernel parameters or reboot //PS: 重開機喔 之後用 ORACLE 這帳號登入進行安裝 DB
 # /sbin/sysctl -p


Login in to xwindows session as user oracle
-------------------------------------------
+ Mount the Oracle10gR2 cd or dvd and run the Database installer
 mount /media/cdrom/
 (cd $HOME && /media/cdrom/database/runInstaller)
 //cd $HOME && /media/cdrom/runInstaller  本人的版本不需要加上 database
 - follow the installer instructions 
(installer checks for 3GB of swap, default partitioning gives 2GB )
 - use password mgmt to unlock DBuser HR & set password 'hr'

+ Installation successful
 http://localhost:5560/isqlplus  ( iSQL*Plus Url )
 http://localhost:5560/isqlplus/dba  ( iSQL*Plus DBA Url )
 http://localhost:1158/em   (bookmark the Enterprise Manager console)

+ The following enables the oracle user to dbshut, dbstart, lsnrctl start and stop  
 As root # vi /etc/oratab  change :N to :Y 
           # cp /etc/oratab /opt/oracle/oratab
[參考連結] How-to: VMware player modification Running .iso Files in VMWare Player

top