首页 > 数据库技术 > 详细

oracle

时间:2017-12-11 20:33:13      阅读:259      评论:0      收藏:0      [点我收藏+]
oracle数据库的安装 :

? ?oracal 11G

? ?centos6:


图形化

? ?安装tools工具

? ? df

? ? cd /media/vmware\ Tools/

? ?tar zxvf VMwareTools-10.0.0-2977863.tar.gz -C ?/tmp

? ?cd /tmp

? ?cd vmware-tools-distrib

? ?./vmware-install.pl

? ?回车

? ?init 3

? ?init 5


安装步骤:


?复制:1of7.zip

? ? ? 2of7.zip

? ? ? /orainst_11g.sh

cd ?Desktop

?ls

?unzip p13390677_112040_linux-x86-64_1of7.zip;unzip p13390677_112040_linux-x86-64_2of7.zip

?mv database/ /root

?cd database

? 保证网卡地址是静态地址

?cd /etc/sysconfig/network-scripts

?vim ?ifcfg-eth0

?BOOTPROTO=static静态?

IP地址要可以跟主机名可以解析 ??

?cd /etc

? vim hosts

?ip地址 ?主机名

172.17.254.150 ?xyd

执行脚本

./orainst_11g.sh


xhost +

su - oracle

cd database

./runInstaller?

?next

?next

?install database software only

?next

?singer instance database installation

?next

?english

?smilp chinese

?next

Enter Edation

?next

?next

?next

oinstall

?next


install



// vim /etc/sysctl.conf

? kernel.shmmax = 10433636224

// sysctl -p

// ?

// cd Desktop

// rz?

// ?pdksh-5.2.14-30.x86_64.rpm

//rpm -ivh pdksh-5.2.14-30.x86_64.rpm

//rpm -e ksh

//yum install ksh

// ssh -X ip地址


cd ?/u01

cd app

cd oracleInventory

ls

/u01/app/oraInventory/orainstRoot.sh

ok


su - oracle

lsnrctl start 开启监听

dbcl

next

next

next

orcl

next

next

use the ... ALL ALLCoures

oracle


next

enable a..

next

sample?

next

character sets

?use uncode?

?AL16UFTF16.....8

next

next

finsh

ok


登录数据库:

su - oracle


sqlplus / as sysdba ?或 sqlplus sys/oracle ?


>select * from scott.dept; 简单的查看

>exit

安装指定的包使数据库可以翻看历史记录

cd Desktop

ls

rpm -ivh rlwrap-0.37-1.e16.x86_64.rpm

su - oracle

rlwrap sqlplus / as sysdba

vim .bash_profile

?alias sqlplus=‘rlwrap sqlplus‘

. .bash_profile 执行生效


重行登录,就可以翻看历史命令

SQL语句的基本使用:

?sqlplus / as sysdba

>select * from scott.dept;

>conn scott/tiger

>alter user scott account unlock;解锁 然后重新登录

>conn / as sysdba 链接

>show user

>alter user scott account unlock identified by tiger;

>conn scott/tiger

>select * from tab;查看表

>desc dept;查看表的信息

>select * from dept;

>select dname from dept; 查看表的一列信息

>select loc,dname from dept;查看表的多列信息

>desc emp;

>select * from emp;

>set line 1000 修改显示格式

>select (sal+comm)*12 from emp;

>select ename xiao,sal*12 nianxin from emp;支持表达式

>select ename as "xiao"|| sal*12 as "nianxin" from emp; 两列变一列

>select distinct sal from emp;显示所有行包括重复行

>


?字符型

?数值型

?日期型


限制和排序数据:

>select * from emp where deptno-20; 限制行的排序 只看为20的

>select * from emp where sal-800;

>select * from emp where hiredate=‘03-DEC-81‘ 字符型数字型要加引号

>select * from emp where ename=‘scott‘;


比较操作符

>select * from emp where sal=800;

>select * from emp where sal between 800 and 3000; 800到3000的都显示出来

>select * from emp where sal in (800,1100); 800或1100

>select * from emp where sal !in (800,1100); 即不是800也不是1100

>select * from emp where ename like ‘sco%‘;


and要求两个都是true

>select ename,sal from where sal > 1000 and job like ‘%MAN%‘;


排序:


>select ename,sal from emp where deptno-20 order by sal DESC; 降序排列

>select deptno ename AS "xingming",sal,sal*12 as "nianxin" from emp where deptno=30 order by "nianxin";

>select deptno ename AS "xingming",sal,sal*12 as "nianxin" from emp where deptno-$bumen order by "nianxin";


define设置环境变量

>define

>defile_editor=‘vim‘ 编辑ed

>select * from emp;

>ed

?select * from dept

>l

>/


提示符的修改

cd $ORACL_HOMF/sql table键补齐 ?/sqlplus/admin

vim glogin.sql

et sqlprompt "_USER"@"_CONNECT_IDFNTIFIFR>"


sqlplus / as sysdba

>conn scott/tiger

>select * from emp where deptno=&bumen

>set line 1000

>set verify off;可关闭最上边的两句话


单行函数:

?字符函数:

sqlplus /as sysdba

>conn / as sysdba

>set pagesize 4000 显示信息的大小设置

>creat ?user magedu identified by magedu; 创建用户(创建时时的写那么显示就为大写)

>creat user MAGEDU identified by magedu;

>select username from dba_users where lower(username) lik "mage%"; 模糊搜索

>select lower(username) from dba_user;查看数据库中的用户

>select sysdate from dual;查看日期



?

转换函数:

>select to_char(sysdate,‘yyy-mm-dd‘) from dual修改日期显示格式

>select to_char(sysdate,‘yyy-mm-dd hh24:mi:ss‘) from dual;

>select ename,to_char(sal,‘$9999.00‘) from emp; 9代表一个数字

>select ename,hirsdate from emp where hiredate < to_date(‘01-01-85‘,‘DD-mm-RR‘);日期转换

>select upper(to_char(sysdate,‘year,month‘)) from dual;大写显示年月

>insert into emptmp (empno,ename,sal) values (8000.‘xyd‘,10000); 插入表

>select ename,nvl(hiredate,‘01-JAN-80‘);from emptmp; 添加日期


分组函数:

>select max(sal) from emp; 最大值

>select avg(sal) from emp; 平均值

>select avg(sal),min(sal),max(sal),sum(sal) from emp;输出多个值

>select avg(sal),min(sal),max(sal),sum(sal) from emp where deptno=30;

>select deptno,avg(sal) from emp group by deptno;创建分组 每个部门的平均值

>select ?deptno,avg(sal) from emp where deptno > 20 group by deptno;

>select deptno,avg(sal) from emp group by deptno having avg(sal) >2000; having的用法


嵌套:

> select max(avg(sal)) from emp group by deptno;


多表查询语句:

?从多个表获取数据

? 自然连接 外连接


?多表查询

>desc dept;

>desc emp;

>select * from dept;

>select * from emp;

>select empno,ename,dname from emp natural join dept;

>create table dept_tmp as select deptno,dname bumenming,loc from dept; 创建新表

>select empno,ename,bumenming from emp natural join dept_tmp; 两个表进行连接

>create table dept_tmp2 as select deptno deptid,dname,loc from dept;

>select * from dept_tmp2;

>select empno,ename,dname from emp join dept_tmp2 on (emp.deptno=dept_tmp2.deptid);两个表进行连接

>select e.empno,e.ename,d.dname from emp e join dept_tmp2 d on (e.deptno=d.deptid);

>select empno,ename,dname from emp join dept using(deptno); 强调列


>drop table emptmp ?purge;删除

>drop table depy_tmp2 purge;删除表


自连接

>select x.ename,s.ename from emp x join emp s on (x.mgr=s.empno); 上下级的排序

?

外连接

>select x.ename yuangong,s.ename lingdao from emp x left join emp s on (x.mgr=s.empno); 左边没有考左边写

>select x.ename yuangong,s.ename lingdao from emp x right join emp s on (x.mgr=s.empno);右边没有考右边写


不等连接

>select e.ename,e.sal,s.grade from emp e join salfrade s on e.sal between s.losal and s.hisal;



子查询

>select ename,sal from emp where sal > (select sal from emp where ename-‘scott‘);


UNION:显示所有的,消除重复的

INTERSECT:显示共有的,消除重复的

MINUS:返回第一个查询有但第二个查询中不存在的所有唯一行记录


一个事物处理是由一系列DML语句逻辑组成的

?



>commit;提交事物

>rollback;回滚



where是在组函数之前进行的 having是在组函数之后进行的

DDL语句:对表进行创建删除,对表中的列进行修改,修改整个表的结构

DCL语句:控制一些用户的权限

??

数据库对象:

object ? 对象 -》描述

table ? ?表-》存储的基础单元,由行和列组成

view ? ? 视图 -》一个或多个表中的数据逻辑子集

sequence 序列 -》数值生成器

index ? ?索引 -》提高某些查询的效率

synonym ?同义词 -》对象的别名 ? ?

?

建表语句:

?>select * from scott.emp;

?>selcet * from hr.

?>select sysdate from dual;查看日期?

?>create table t001(

? ?ename varchar2(10),

? ?deptno number(2),

? ?hiredate date default sysdate); 创建表的列

?>desc t001 查看表

?> select count(*) from t001; 查看

?>insert into t001 values(‘xyd‘,‘01‘,‘08-DEC-18‘);插入表的信息

?>insert into t001 (ename,deptno) values (‘chengcheng‘,02);


?PK-DEPT?

?PK-EMP 索引

优化显示:?

?>col object_name for a10


查看用户的表名信息

>select table_name from user_tables;

>select tname from tab;

>select object_name from user_objects;

>select object_name from user_objects where object_type=‘TABLE‘;

>desc user_objects;


介绍约束:

?约束类型:

? NOT NULL 非空

? UNIQUE 唯一

? PRIMARY KEY 主键

? FOREIGN KEY 外键

? CHECK 检查

?定义约束:



创建表和列约束

>create table t002(

? empno numder(4)

? constraint t002_empno_pk primary key,

? ename varchar(10) not null,

? sal number(5));?


>insert into t002 values (1000,‘jiake‘,null); 插入数据

?

表约束

>create table t003(

?name varchar2(10),

?sex varchar2(10),

?sal number(5),

constraint t003_name_pk primary key (name));

>/ 执行


多级约束

>create table t004 (

?name varchar2(10),

?empid number(5),

?constraint t004_empid_unique unique,

?email varchar2(20)

?constraint t004_email_uk unique ));


子查询建立表:



基本表 视图


序列



索引能够提供一些查询数据的速度

索引:

? ?是一种方案对象

??

?自动创建

?手工创建

??

控制用户的访问:


方案:对象的集合



?

系统权限:


>create user xyd identified by xyd

>grabt create session to xyd 给权限

>conn / as sysdba

>grant create table to xyd

>conn xyd/xyd

>create table t001(id number(2));


role权限的集合


>create role class26

>grant create session,create table,create view,create index,create sequence grant dreated


使用数据字典:




体系结构:内存结构 和 数据文件

? ? ? ? ?实例 进程



启动数据库的步骤:

? 第一:开启实例,读取参数文件

? ? ? ? 加载参数文件来启动实例 ?

? 第二:开启数据库

? ? ? ? ?通过参数文件中记载的数据文件,日志文件大位置来加载打开数据文件,日志文件


? 第三:打开数据库

? ? ? ? ?通过


关闭数据库:

??


oracle

原文:http://blog.51cto.com/13287431/2049508

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!