Oracle逻辑结构与函数入门

Review:
物理结构
控制文件(多路8), 数据文件, 联机日志, 参数文件.
参数文件指定了控制文件所在位置和初始化参数.
由控制文件读取数据文件和联机日志文件.
show parameter control;

逻辑结构
数据库 SID
表空间 TableSpace
段 segment -> 数据
盘区
块 block

安全模式
角色:dba,connect,resource
授权:unlimited_tablespace

内存模式
共享池
高速缓冲区
大型池

启动和关闭
startup:nomount仅启动服务,mount加载控制文件,open
alter database sid open;
shutdown:normal,transaction,immediate,abort

Sequence和topN查询
create sequence seq_userid;
start with ..
increment by ..
minvalue ..
maxvalue ..
nocache
order

seq_userid.nextval;
seq_userid.currval;

insert users(userid) values (seq_userid.nextval);

rowid(不重复),rownum
rownum 只能查小于等于, 不能查大于
分页查询利用子查询.
尽量在子查询中结束结果集.
在oracle8之前,子查询中不能带order

isql*plus
sql*plus -> col username format a30;
desc, @, spool, spool off,col,TTITLE,BTITLE
&(临时变量), &&, define var vartype = ..
accept aaa number format pro..
define
? accept
---------------------------
Oracle 数据类型
字符类型:
char, 默认一个字节
varchar2
long不常用

数字:
number(m, n) -- m最大38位

日期
Date
默认格式:dd-mon-rr
alter session set NLS_DATE_FORMAT='yyyy-MM-dd';
alter system setNLS_DATE_FORMAT='yyyy-MM-dd'; -- oracle8
http://localhost:5501/em/
可修改注册表.

定义空值
NULL不是0也不是空格,是一个未知的值.
PK,NotNull不能为NULL.
运算中有一个NULl结果 也是NULL.

列别名:
select employee_id as '别名' from employees where '别名' > 100;
别名不能出现在where子句中.
select id as abc , abc&10 from xx; // 不行
select employ_id as "em no" from employees;

连字符(||)
select first_name||','||last_name from employees;

in, between只是改写不能对性能优化.

true and null = null;
false and null = false;
null and null = null;

null or true = true;
null or false = null;
null or null = null;

not in (xx,xx, null) 将查不到数据.
优先级: not -> and -> or

order by

select first_name || ' ' || last_name Employee , salary "Monthly Salary" from employees where department_id in (20,
and salary between 5000 and 12000
--------------------------------
sql 函数 :
单行函数

字符函数:
lower,upper,initcap(首字母大写)
concat,substr,length,instr,trim(消除随便啥东西),replace.
select substr(last_name,-4,3), last_name from employees;
abs,cell,mod,
round
trunc: 跟sql server的区别是精度
多行函数

默认日期格式:DD-MON-RR
sysdate;
date + 数字 : 加几天
date + 数字 : 减几天
date - date : 相差几天
date + 数字/24 : 加小时

数据类型转换
表达式赋值只支持char或varchar到number或date.
to_number, to_date, to_char
to_char();
select to_char(23.232,'$99.99') from dual;

通用重点函数 :
NVL(commission_pct,0)
NVL2(commission_pct,'SAL+COMM','SAL')
NULLIF // 如果相等返回NULL
COALESCE(expr1, expr2, ..., exprn) //
CASE
DECODE
case expr when xx thenxx
when xx then xx
else xx end

decode(job_id,xx,xx,
xx,xx,
xx,xx,
salary) revised_salary
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值