Oracle在Linux下安装

所属分类:技术

Oracle在Linux下安装

本来是在windows2003上装好了的,秉承着不作死便不会死的原则,以及为了自己能再次操作linux的原则,装上了虚拟机,装上了centos7,开始了作死的不归路?。所有图片均摘自网上。如有雷同,肯定抄的。谢谢合作。

主机配置

--根据经验,关闭一些无用的服务,否则安装时可能会出现某些错误

#vi serverstop.sh

--编写关闭服务脚本

[plain] view plaincopy

  1. chkconfig iptables off  
  2. chkconfig ip6tables off  
  3. chkconfig cups off  
  4. chkconfig firstboot off  
  5. chkconfig wpa_supplicant off  
  6. chkconfig postfix off  
  7. sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config  
  8. sed -i 's/^GSSAPIAuthentication yes$/GSSAPIAuthentication no/' /etc/ssh/sshd_config  
  9. sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config  

#sh serverstop.sh

--执行关闭服务脚本

5.2 安装包

解压安装包

[root@hyldb /]# cd /software

[root@hyldb software]# ls

linuxamd64_12c_database_1of2.zip  linuxamd64_12c_database_2of2.zip

[root@hyldb software]# unzip linuxamd64_12c_database_1of2.zip

[root@hyldb software]# unzip linuxamd64_12c_database_2of2.zip

查看官方文档,没有找到LINUX7需安装包的文档,找到了LINUX6需要安装的包,以LINUX6作为参考,步骤如下:

在系统光盘中,按要求找到需要的包,下面是文档中要求安装的64位的相关包:

[plain] view plaincopy

  1. The following packages (or later versions) must be installed:  
  2. binutils-2.20.51.0.2-5.11.el6 (x86_64)  
  3. compat-libcap1-1.10-1 (x86_64)  
  4. compat-libstdc++-33-3.2.3-69.el6 (x86_64)  
  5. gcc-4.4.4-13.el6 (x86_64)  
  6. gcc-c++-4.4.4-13.el6 (x86_64)  
  7. glibc-2.12-1.7.el6 (x86_64)  
  8. glibc-devel-2.12-1.7.el6 (x86_64)  
  9. ksh  
  10. libgcc-4.4.4-13.el6 (x86_64)  
  11. libstdc++-4.4.4-13.el6 (i686)  
  12. libstdc++-devel-4.4.4-13.el6 (x86_64)  
  13. libaio-0.3.107-10.el6 (x86_64)  
  14. libaio-devel-0.3.107-10.el6 (x86_64)  
  15. libXext-1.1 (x86_64)  
  16. libXtst-1.0.99.2 (x86_64)  
  17. libX11-1.3 (x86_64)  
  18. libXau-1.0.5 (x86_64)  
  19. libxcb-1.5 (x86_64)  
  20. libXi-1.3 (x86_64)  
  21. make-3.81-19.el6  
  22. sysstat-9.0.4-11.el6 (x86_64)  

将找到的包上传到linux系统下,对其进行安装

[root@hyldb package]# vi  rpm.sh

[plain] view plaincopy

  1. rpm -ivh binutils-2.23.52.0.1-16.el7.x86_64.rpm  
  2. rpm -ivh compat-libcap1-1.10-7.el7.x86_64.rpm  
  3. rpm -ivh gcc-4.8.2-16.el7.x86_64.rpm  
  4. rpm -ivh gcc-c++-4.8.2-16.el7.x86_64.rpm  
  5. rpm -ivh glib2-devel-2.36.3-5.el7.x86_64.rpm  
  6. rpm -ivh glibc-2.17-55.el7.x86_64.rpm  
  7. rpm -ivh ksh-20120801-19.el7.x86_64.rpm  
  8. rpm -ivh libaio-0.3.109-12.el7.x86_64.rpm  
  9. rpm -ivh libaio-devel-0.3.109-12.el7.x86_64.rpm  
  10. rpm -ivh libgcc-4.8.2-16.el7.x86_64.rpm  
  11. rpm -ivh libstdc++-4.8.2-16.el7.x86_64.rpm  
  12. rpm -ivh libstdc++-devel-4.8.2-16.el7.x86_64.rpm  
  13. rpm -ivh libX11-1.6.0-2.1.el7.x86_64.rpm  
  14. rpm -ivh libXau-1.0.8-2.1.el7.x86_64.rpm  
  15. rpm -ivh libxcb-1.9-5.el7.x86_64.rpm  
  16. rpm -ivh libXext-1.3.2-2.1.el7.x86_64.rpm  
  17. rpm -ivh libXtst-1.2.2-2.1.el7.x86_64.rpm  
  18. rpm -ivh make-3.82-21.el7.x86_64.rpm  
  19. rpm -ivh sysstat-10.1.5-4.el7.x86_64.rpm  

[root@hyldb package]# sh  rpm.sh

安装调用图形化需要的包,使用yum安装下面的包

[root@hyldb yum.repos.d]# yum -y install unixODBC

[root@hyldb yum.repos.d]# yum -y install unixODBC-devel

[root@hyldb scripts]# yum install -y xterm

--xterm这是调用图形化用的包

5.3 添加用户及相关目录

[root@hyldb /]# groupadd oinstall

[root@hyldb /]# groupadd dba

[root@hyldb /]# useradd -g oinstall -G dba oracle

[root@hyldb /]# passwd oracle

Changing password for user oracle.

New password:

BAD PASSWORD: The password is shorter than 8 characters

Retype new password:

passwd: all authentication tokens updated successfully.

[root@hyldb /]# id oracle

uid=1001(oracle) gid=1001(oinstall) groups=1001(oinstall),1002(dba)

[root@hyldb /]# mkdir -p /u01/app/oracle/product/12.1.0/db_1

[root@hyldb /]# mkdir -p /u01/app/oraInventory

[root@hyldb /]# chown -R oracle:oinstall /u01/app

[root@hyldb /]# chmod -R 775 /u01/app

5.4 配置内核参数

[root@hyldb /]# vi /etc/sysctl.conf

[plain] view plaincopy

  1. # System default settings live in /usr/lib/sysctl.d/00-system.conf.  
  2. # To override those settings, enter new settings here, or in an /etc/sysctl.d/ .conf file
  3. #  
  4. # For more information, see sysctl.conf(5) and sysctl.d(5).  
  5. fs.aio-max-nr = 1048576  
  6. fs.file-max = 6815744  
  7. kernel.shmall = 2097152  
  8. kernel.shmmax = 4294967295  
  9. kernel.shmmni = 4096  
  10. kernel.sem = 250 32000 100 128  
  11. net.ipv4.ip_local_port_range = 9000 65500  
  12. net.core.rmem_default = 262144  
  13. net.core.rmem_max = 4194304  
  14. net.core.wmem_default = 262144  
  15. net.core.wmem_max = 1048576  
  16. ~  

[root@hyldb /]# sysctl -p

[plain] view plaincopy

  1. fs.aio-max-nr = 1048576  
  2. fs.file-max = 6815744  
  3. kernel.shmall = 2097152  
  4. kernel.shmmax = 4294967295  
  5. kernel.shmmni = 4096  
  6. kernel.sem = 250 32000 100 128  
  7. net.ipv4.ip_local_port_range = 9000 65500  
  8. net.core.rmem_default = 262144  
  9. net.core.rmem_max = 4194304  
  10. net.core.wmem_default = 262144  
  11. net.core.wmem_max = 1048576  

--修改系统限制

[root@hyldb ~]# vi /etc/security/limits.conf

[plain] view plaincopy

  1. # End of file  
  2. oracle              soft    nproc   2047  
  3. oracle              hard    nproc   16384  
  4. oracle              soft    nofile  1024  
  5. oracle              hard    nofile  65536  

[root@hyldb ~]# vi /etc/pam.d/login

[plain] view plaincopy

  1. session    required     /lib/security/pam_limits.so  
  2. session    required     pam_limits.so  

[root@hyldb ~]# vi /etc/profile

--添加以下参数

[plain] view plaincopy

  1. if [ $USER = "oracle" ]; then  
  2.         if [ $SHELL = "/bin/ksh" ]; then  
  3.               ulimit -p 16384  
  4.               ulimit -n 65536  
  5.         else  
  6.               ulimit -u 16384 -n 65536  
  7.         fi  
  8. fi  

5.5 切换到oracle用户下,配置环境变量

[root@hyldb /]# su - oracle

[oracle@hyldb ~]$ vi .bash_profile

[plain] view plaincopy

  1. # .bash_profile  
  2. # Get the aliases and functions  
  3. if [ -f ~/.bashrc ]; then  
  4.         . ~/.bashrc  
  5. fi  
  6. # User specific environment and startup programs  
  7. #PATH=$PATH:$HOME/.local/bin:$HOME/bin  
  8. #export PATH  
  9. ORACLE_BASE=/u01/app/oracle  
  10. ORACLE_HOME=$ORACLE_BASE/product/12.1.0/db_1  
  11. ORACLE_SID=shenlan  
  12. PATH=$PATH:$HOME/bin:$ORACLE_HOME/bin  
  13. LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib  
  14. export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH LD_LIBRARY_PATH  
  15. ~  
  16. ~  
  17. ".bash_profile" 18L, 430C written  

[oracle@hyldb ~]$ source .bash_profile

5.6 安装oracle软件

远程调用图形安装oracle软件

此处使用的X-manager软件

以下出现的错误忽略即可!!!

产生这个问题的原因是,12c的第一版本,还不支持linux7,因此需要手工解决这个问题。

[root@hyldb stubs]# cd /u01/app/oracle/product/12.1.0/db_1/lib/stubs

[root@hyldb stubs]# cp * /bak

[root@hyldb bak]# rm -rf /u01/app/oracle/product/12.1.0/db_1/lib/stubs/*

[root@hyldb bak]# cp /u01/app/oracle/product/12.1.0/db_1/rdbms/lib/env_rdbms.mk /u01/app/oracle/product/12.1.0/db_1/rdbms/lib/env_rdbms.mk.orig

[root@hyldb bak]# vi /u01/app/oracle/product/12.1.0/db_1/rdbms/lib/env_rdbms.mk

176行

修改前:

LINKTTLIBS=$(LLIBCLNTSH) $(ORACLETTLIBS) $(LINKLDLIBS)

修改后:

LINKTTLIBS=$(LLIBCLNTSH) $(ORACLETTLIBS) $(LINKLDLIBS) -lons

279-280行

修改前:

LINK=$(FORT_CMD) $(PURECMDS) $(ORALD) $(LDFLAGS) $(COMPSOBJS)

LINK32=$(FORT_CMD) $(PURECMDS) $(ORALD) $(LDFLAGS32) $(COMPSOBJS)

修改后:

LINK=$(FORT_CMD) $(PURECMDS) $(ORALD) $(LDFLAGS) $(COMPSOBJS) -Wl,--no-as-needed

LINK32=$(FORT_CMD) $(PURECMDS) $(ORALD) $(LDFLAGS32) $(COMPSOBJS) -Wl,--no-as-needed

3041-3042行

修改前:

TG4PWD_LINKLINE= $(LINK) $(OPT) $(TG4PWDMAI) \

         $(LLIBTHREAD) $(LLIBCLNTSH) $(LINKLDLIBS)

修改后:

TG4PWD_LINKLINE= $(LINK) $(OPT) $(TG4PWDMAI) \

         $(LLIBTHREAD) $(LLIBCLNTSH) $(LINKLDLIBS) -lnnz12

修改后,点击Retry,如下:

手工修正后,继续安装。

[root@hyldb bak]# /u01/app/oraInventory/orainstRoot.sh

Changing permissions of /u01/app/oraInventory.

Adding read,write permissions for group.

Removing read,write,execute permissions for world.

Changing groupname of /u01/app/oraInventory to oinstall.

The execution of the script is complete.

[root@hyldb bak]# /u01/app/oracle/product/12.1.0/db_1/root.sh

Performing root user operation for Oracle 12c  

The following environment variables are set as:

    ORACLE_OWNER= oracle

    ORACLE_HOME=  /u01/app/oracle/product/12.1.0/db_1 

Enter the full pathname of the local bin directory: [/usr/local/bin]:

   Copying dbhome to /usr/local/bin ...

   Copying oraenv to /usr/local/bin ...

   Copying coraenv to /usr/local/bin ...

Creating /etc/oratab file...

Entries will be added to the /etc/oratab file as needed by

Database Configuration Assistant when a database is created

Finished running generic part of root script.

Now product-specific root actions will be performed.

至此,oracle软件安装完成。

5.7 dbca建库

使用X-manager调用图形化界面。

[oracle@hyldb ~]$ xhost +

access control disabled, clients can connect from any host

[oracle@hyldb ~]$ dbca

5.8 配置监听

[oracle@hyldb ~]$ netca

验证监听状态,如下:

[oracle@hyldb ~]$ lsnrctl status

LSNRCTL for Linux: Version 12.1.0.1.0 - Production on 12-APR-2015 17:12:03

Copyright (c) 1991, 2013, Oracle.  All rights reserved.

Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=hyldb)(PORT=1521)))

STATUS of the LISTENER

------------------------

Alias                     LISTENER

Version                   TNSLSNR for Linux: Version 12.1.0.1.0 - Production

Start Date                12-APR-2015 17:03:10

Uptime                    0 days 0 hr. 8 min. 54 sec

Trace Level               off

Security                  ON: Local OS Authentication

SNMP                      OFF

Listener Parameter File   /u01/app/oracle/product/12.1.0/db_1/network/admin/listener.ora

Listener Log File         /u01/app/oracle/diag/tnslsnr/hyldb/listener/alert/log.xml

Listening Endpoints Summary...

  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=hyldb)(PORT=1521)))

  (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1521)))  (DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=hyldb)(PORT=5500))(Security=(my_wallet_directory=/u01/app/oracle/admin/shenlan/xdb_wallet))(Presentation=HTTP)(Session=RAW))

Services Summary...

Service "shenlan" has 1 instance(s).

  Instance "shenlan", status READY, has 1 handler(s) for this service...

Service "shenlanXDB" has 1 instance(s).

  Instance "shenlan", status READY, has 1 handler(s) for this service...

The command completed successfully

5.9 配置Net Configuration Assistant

[oracle@hyldb ~]$ netca

简单演示:

[oracle@hyldb ~]$ sqlplus scott/tiger@localdb

SQL*Plus: Release 12.1.0.1.0 Production on Sun Apr 12 17:14:44 2015

Copyright (c) 1982, 2013, Oracle.  All rights reserved.

Last Successful login time: Sun Apr 12 2015 17:10:20 +08:00

Connected to:

Oracle Database 12c Enterprise Edition Release 12.1.0.1.0 - 64bit Production

With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options

SQL>

关于Net Configuration Assistant的配置一般是在客户端进行配置,此处只作为一种演示。

至此,在LINUX7下安装Oracle12C完成。

设置开机启动

在CentOS 6.3下安装完Oracle 10g R2,重开机之后,你会发现Oracle没有自行启动,这是正常的,因为在Linux下安装Oracle的确不会自行启动,必须要自行设定相关参数,首先先介绍一般而言如何启动oracle。

一、在Linux下启动Oracle

登录到CentOS,切换到oracle用户权限

# su – oracle

接着输入:

$ sqlplus "/as sysdba"

原本的画面会变为 SQL>

接着请输入 SQL> startup

就可以正常的启动数据库了。

另外停止数据库的指令如下: SQL> shutdown immediate

二、检查Oracle DB监听器是否正常

回到终端机模式,输入:

$ lsnrctl status

检查看看监听器是否有启动

如果没有启动,可以输入:

$ lsnrctl start

启动监听器

SQL> conn sys@orcl as sysdba

然后输入密码,sys以sysdba身份登入数据库。

三、启动emctl

另外也可以发现http://localhost.localdomain:1158/em 目前是没有反应的,这边要另外启动,启动的指令如下:

$ emctl start dbconsole

这个指令运行时间较长,执行完的画面如下:

手动启动Oracle数据库完毕,下面创建系统自行启动Oracle的脚本。

四、Oracle启动&停止脚本

1. 修改Oracle系统配置文件:/etc/oratab,只有这样,Oracle 自带的dbstart和dbshut才能够发挥作用。

# vi /etc/oratab orcl:/opt/oracle/102:Y

# Entries are of the form: #   $ORACLE_SID:$ORACLE_HOME: <n|y> : </n|y>

2. 在 /etc/init.d/ 下创建文件oracle,内容如下:

#!/bin/sh

# chkconfig: 35 80 10

# description: Oracle auto start-stop script.

#

# Set ORA_HOME to be equivalent to the $ORACLE_HOME

# from which you wish to execute dbstart and dbshut;

#

# Set ORA_OWNER to the user id of the owner of the

# Oracle database in ORA_HOME.

ORA_HOME=/opt/oracle/102

ORA_OWNER=oracle

if [ ! -f $ORA_HOME/bin/dbstart ]

then

   echo "Oracle startup: cannot start"

   exit

fi

case "$1" in

'start')

# Start the Oracle databases:

echo "Starting Oracle Databases ... "

echo "-------------------------------------------------" >> /var/log/oracle

date +" %T %a %D : Starting Oracle Databases as part of system up." >> /var/log/oracle

echo "-------------------------------------------------" >> /var/log/oracle

su - $ORA_OWNER -c "$ORA_HOME/bin/dbstart" >>/var/log/oracle

echo "Done"

# Start the Listener:

echo "Starting Oracle Listeners ... "

echo "-------------------------------------------------" >> /var/log/oracle

date +" %T %a %D : Starting Oracle Listeners as part of system up." >> /var/log/oracle

echo "-------------------------------------------------" >> /var/log/oracle

su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl start" >>/var/log/oracle

echo "Done."

echo "-------------------------------------------------" >> /var/log/oracle

date +" %T %a %D : Finished." >> /var/log/oracle

echo "-------------------------------------------------" >> /var/log/oracle

touch /var/lock/subsys/oracle

;;

'stop')

# Stop the Oracle Listener:

echo "Stoping Oracle Listeners ... "

echo "-------------------------------------------------" >> /var/log/oracle

date +" %T %a %D : Stoping Oracle Listener as part of system down." >> /var/log/oracle

echo "-------------------------------------------------" >> /var/log/oracle

su - $ORA_OWNER -c "$ORA_HOME/bin/lsnrctl stop" >>/var/log/oracle

echo "Done."

rm -f /var/lock/subsys/oracle

# Stop the Oracle Database:

echo "Stoping Oracle Databases ... "

echo "-------------------------------------------------" >> /var/log/oracle

date +" %T %a %D : Stoping Oracle Databases as part of system down." >> /var/log/oracle

echo "-------------------------------------------------" >> /var/log/oracle

su - $ORA_OWNER -c "$ORA_HOME/bin/dbshut" >>/var/log/oracle

echo "Done."

echo ""

echo "-------------------------------------------------" >> /var/log/oracle

date +" %T %a %D : Finished." >> /var/log/oracle

echo "-------------------------------------------------" >> /var/log/oracle

;;

'restart')

$0 stop

$0 start

;;

esac

3. 改变文件权限 # chmod 755 /etc/init.d/oracle

4. 添加服务 # chkconfig --level 35 oracle on

5. 需要在关机或重启机器之前停止数据库,做一下操作 # ln -s /etc/init.d/oracle /etc/rc0.d/K01oracle   //关机 # ln -s /etc/init.d/oracle /etc/rc6.d/K01oracle   //重启

6. 使用方法 # service oracle start        //启动oracle # service oracle stop        //关闭oracle # service oracle restart     //重启oracle

7. 测试

a. 开机自启动

Last login: Mon Nov 26 19:57:06 2012 from 10.0.0.145

[root@ORS ~]# su - oracle

[oracle@ORS ~]$ sqlplus "/as sysdba"

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Nov 26 20:07:33 2012

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to:

Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

SQL> set linesize 300;

SQL> set pagesize 30;

SQL> select * from scott.emp;

    EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO

---------- ---------- --------- ---------- --------- ---------- ---------- ----------

     7369 SMITH      CLERK           7902 17-DEC-80        800                    20

     7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30

     7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30

     7566 JONES      MANAGER         7839 02-APR-81       2975                    20

     7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30

     7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30

     7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10

     7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20

     7839 KING       PRESIDENT            17-NOV-81       5000                    10

     7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30

     7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20

     7900 JAMES      CLERK           7698 03-DEC-81        950                    30

     7902 FORD       ANALYST         7566 03-DEC-81       3000                    20

     7934 MILLER     CLERK           7782 23-JAN-82       1300                    10

14 rows selected.

SQL>

b. service oracle stop

SQL> Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production

With the Partitioning, OLAP and Data Mining options

[oracle@ORS ~]$ logout

[root@ORS ~]# service oracle stop

Stoping Oracle Listeners ...

Done.

Stoping Oracle Databases ...

Done.

[root@ORS ~]# su - oracle

[oracle@ORS ~]$ sqlplus "/as sysdba"

SQL*Plus: Release 10.2.0.1.0 - Production on Mon Nov 26 20:17:20 2012

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to an idle instance.

SQL> set linesize 300;

SQL> set pagesize 30;

SQL> select * from scott.emp;

select * from scott.emp

*

ERROR at line 1:

ORA-01034: ORACLE not available

SQL>

c. service oracle start

SQL> Disconnected

[oracle@ORS ~]$ logout

[root@ORS ~]# service oracle start

Starting Oracle Databases ...

Done

Starting Oracle Listeners ...

Done.

[root@ORS ~]#

d. service oracle restart

[root@ORS ~]# service oracle restart

Stoping Oracle Listeners ...

Done.

Stoping Oracle Databases ...

Done.

Starting Oracle Databases ...

Done

Starting Oracle Listeners ...

Done.

[root@ORS ~]#

至此,Oracle服务启动&停止脚本与开机自启动设置完毕。

创建c##scott用户及相关数据表

SQLPlus中依次输入:

SQL> conn sys/susheng as sysdba;

已连接。

SQL> CREATE USER SCOTT IDENTIFIED BY susheng;

CREATE USER SCOTT IDENTIFIED BY susheng

           *

第 1 行出现错误:

ORA-65096: 公用用户名或角色名无效

 --查官方文档得知"试图创建一个通用用户,必需要用C##或者c##开头"。

    3、将以下SQL语句保存为C:\scott.sql文件中:

--以下语句可参考%ORACLE_HOME%\dbhome_1\RDBMS\ADMIN\scott.sql进行修改:

CREATE USER c##scott IDENTIFIED BY tiger;

GRANT CONNECT,RESOURCE,UNLIMITED TABLESPACE TO c##scott;

ALTER USER c##scott DEFAULT TABLESPACE USERS;

ALTER USER c##scott TEMPORARY TABLESPACE TEMP;

conn c##scott/susheng;

DROP TABLE DEPT;

CREATE TABLE DEPT

      (DEPTNO NUMBER(2) CONSTRAINT PK_DEPT PRIMARY KEY,

    DNAME VARCHAR2(14) ,

    LOC VARCHAR2(13) ) ;

DROP TABLE EMP;

CREATE TABLE EMP

      (EMPNO NUMBER(4) CONSTRAINT PK_EMP PRIMARY KEY,

    ENAME VARCHAR2(10),

    JOB VARCHAR2(9),

    MGR NUMBER(4),

    HIREDATE DATE,

    SAL NUMBER(7,2),

    COMM NUMBER(7,2),

    DEPTNO NUMBER(2) CONSTRAINT FK_DEPTNO REFERENCES DEPT);

INSERT INTO DEPT VALUES

    (10,'ACCOUNTING','NEW YORK');

INSERT INTO DEPT VALUES (20,'RESEARCH','DALLAS');

INSERT INTO DEPT VALUES

    (30,'SALES','CHICAGO');

INSERT INTO DEPT VALUES

    (40,'OPERATIONS','BOSTON');

INSERT INTO EMP VALUES

(7369,'SMITH','CLERK',7902,to_date('17-12-1980','dd-mm-yyyy'),800,NULL,20);

INSERT INTO EMP VALUES

(7499,'ALLEN','SALESMAN',7698,to_date('20-2-1981','dd-mm-yyyy'),1600,300,30);

INSERT INTO EMP VALUES

(7521,'WARD','SALESMAN',7698,to_date('22-2-1981','dd-mm-yyyy'),1250,500,30);

INSERT INTO EMP VALUES

(7566,'JONES','MANAGER',7839,to_date('2-4-1981','dd-mm-yyyy'),2975,NULL,20);

INSERT INTO EMP VALUES

(7654,'MARTIN','SALESMAN',7698,to_date('28-9-1981','dd-mm-yyyy'),1250,1400,30);

INSERT INTO EMP VALUES

(7698,'BLAKE','MANAGER',7839,to_date('1-5-1981','dd-mm-yyyy'),2850,NULL,30);

INSERT INTO EMP VALUES

(7782,'CLARK','MANAGER',7839,to_date('9-6-1981','dd-mm-yyyy'),2450,NULL,10);

INSERT INTO EMP VALUES

(7788,'SCOTT','ANALYST',7566,to_date('13-JUL-87')-85,3000,NULL,20);

INSERT INTO EMP VALUES

(7839,'KING','PRESIDENT',NULL,to_date('17-11-1981','dd-mm-yyyy'),5000,NULL,10);

INSERT INTO EMP VALUES

(7844,'TURNER','SALESMAN',7698,to_date('8-9-1981','dd-mm-yyyy'),1500,0,30);

INSERT INTO EMP VALUES

(7876,'ADAMS','CLERK',7788,to_date('13-JUL-87')-51,1100,NULL,20);

INSERT INTO EMP VALUES

(7900,'JAMES','CLERK',7698,to_date('3-12-1981','dd-mm-yyyy'),950,NULL,30);

INSERT INTO EMP VALUES

(7902,'FORD','ANALYST',7566,to_date('3-12-1981','dd-mm-yyyy'),3000,NULL,20);

INSERT INTO EMP VALUES

(7934,'MILLER','CLERK',7782,to_date('23-1-1982','dd-mm-yyyy'),1300,NULL,10);

DROP TABLE BONUS;

CREATE TABLE BONUS

    (

    ENAME VARCHAR2(10)    ,

    JOB VARCHAR2(9)  ,

    SAL NUMBER,

    COMM NUMBER

    ) ;

DROP TABLE SALGRADE;

CREATE TABLE SALGRADE

     ( GRADE NUMBER,

    LOSAL NUMBER,

    HISAL NUMBER );

INSERT INTO SALGRADE VALUES (1,700,1200);

INSERT INTO SALGRADE VALUES (2,1201,1400);

INSERT INTO SALGRADE VALUES (3,1401,2000);

INSERT INTO SALGRADE VALUES (4,2001,3000);

INSERT INTO SALGRADE VALUES (5,3001,9999);

COMMIT;

在SQL Plus中执行:

SQL> @ "C:\scott.sql";

执行成功后,以创建的c##scott用户登录并测试:

conn c##scott/tiger;

select * from emp;

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏杨建荣的学习笔记

关于primary key和unique index的奇怪问题 (58天)

今天一个dba交给我一个问题,让我帮忙查一下。说有个脚本运行的时候有错,让我看看是什么原因。 脚本的思路如下: 先drop PK,FK之类的constraint...

26512
来自专栏数据之美

详解 MySQL 5.7 新的权限与安全问题

1、新版 MySQL 权限问题:  问题:SQL Error (1130): Host '192.168.1.100' is not allowed to co...

96110
来自专栏流柯技术学院

MySQL数据库不能远程访问的解决办法

MySQL的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "u...

1283
来自专栏数据库新发现

Oracle诊断案例-Job任务停止执行[最终版]

Last Updated: Friday, 2004-11-26 9:48 Eygle

933
来自专栏转载gongluck的CSDN博客

后台进程(守护进程)自动备份PostgreSQL数据库

从当前目录中读取ini配置文件的登录数据库必要的参数,登录数据库后获取两次备份的间隔天数,然后启动一个线程隔1分钟检查一下是否需要备份。 之前查资料查了好久,才...

2774
来自专栏乐沙弥的世界

SQL*PLus 帮助手册(SP2-0171)

    对于经常在SQL*Plus 下工作的大师们而言,总是时不时查询SQL*Plus的帮助命令。着实太多了,记不住。SQL*Plus下直接提供了help命令来...

1073
来自专栏乐沙弥的世界

MySQL 用户与权限管理

    MySQL权限系统的主要功能是证实连接到一台给定主机的用户,并且赋予该用户在数据库上的相关DML,DQL权限。MySQL存取控制包含2个阶段,一是服务器...

701
来自专栏杨建荣的学习笔记

关于创建索引的ora问题 (96天)

创建index的时候,报了如下的错误。让人有些摸不着头脑。 create unique index t_pk on t(object_id,object_nam...

2737
来自专栏杨建荣的学习笔记

excel文件内容导入数据库的问题及解决(20天)

今天需要导一些数据,从excel导入到数据库中。 没有装现成的plsqldev,只能用sql*loader来弄了。 首先我把excel文件的内容转换成csv文件...

3296
来自专栏乐沙弥的世界

数据导入时遭遇 ORA-01187 ORA-01110

最近的数据导入(IMP)时碰到了ORA-01187 ORA-01110 错误,由于这个数据库是使用热备恢复过来的,且恢复也是成功的,因为数据库能够成功open,...

653

扫码关注云+社区