Home  >  Article  >  Database  >  oracle数据库学习笔记

oracle数据库学习笔记

WBOY
WBOYOriginal
2016-06-07 17:46:18923browse

1、约束

2、外连接

3、视图

4、转换函数
 
to_char 将参数转换为字符串给我们看。
 
to_char(日期|表示日期的字符串,'格式')按照某种格式表示出来
 
to_char(hiredate,'dd')='03'
 
to_date 将字符串解析为日期类型,为了添加表中date类型的字段的数据的,给不了日期类型
 
 
 
,除了sysdate
 
to_number 将字符串转换为数据
 
to_number('5','xx')
 
 
 
约束:对字段而言
 
  not null不为空     unique唯一  primary key 唯一且不为空  check 检查约束 foreign
 
 
 
key 某一个字段作为外键,这个外键字段的值取值范围必须是主表的主键字段的值
 
 
 
references
 
 
 
行(列)级约束:字段类型后跟着约束,不可以加约束名 not null 只能是行级约束
 
表级约束:定义完表之后再跟约束,可以自定义约束的名字。
 
 
 
级联操作,  foreign key(home) references parent(id) on delete cascade;
 
 on delete set null;
 
 
 
联合主键:只能作为表级约束 两个以上的字段组合要唯一(primary key(id1,id2))
 
create table study( stu_name varchar2(15), con_name varchar2(15),sorce_name
 
 
 
number(4,1) primary key(stu_name,con_name));
 
多表查询:
 
表连接:找关键字段,找关联字段(能让几张表建立起关系起来的字段)
 
emp ,dept(deptno)
 
emp,salgrage(sal,losal,hisal)
 
emp e,emp m (mgr)
 
 
 
左外连接:表1 left outer join 表2 on 表1(字段)=表2(字段)
 
 
 
右外连接:表1 right outer join 表2 on 表1(字段)=表2(字段)
 
 
 
from 表1,表2 where 表1(字段)=表2(字段)(+)在表2+中加上几条空记录,把表1的记
 
 
 
录全找出来     没有+号表示内连接
 
一方增加空记录用来匹配对方表,或者说将对方表我们关心的数据全部找出来
 
找出员工,工作的部门号及名称包括没有员工的部门
 
  emp.ename,dept.deptno,dept.dept.dname,dept.lol from emp,dept where
 
 
 
emp.deptno(+)=dept.deptno; emp.ename会有空记录
 
 
 
将执行结果导出来:
 
spool d:1.sql
 
........
 
 
 
spool off

 

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn