oracle小记(二)

-- 查看oracle版本
SELECT   *   FROM  v$version;

/*

DDL 数据库定义
DML 数据库管理
DCL 数据库控制
grant + revoke  权限管理

*/

nvl function如果原来的数值为null的话,由指定的数值替代。
nvl(commission_pct,
0 ) / 100

column (col)
column  salary format $ 999999.00  设置数字显示形式
column  name format a15; 设置字符串显示15个字符
column  salary justify  left/right/ center 输出格式
column  clear 清除格式
column  last_name;显示该字段名所用的格式
column  salary justify  left  format $ 99999.000

order   by   asc  升序(默认)  desc  
使用distinct也会触发排序操作
select   *   from  employee  order   by   1 ; 按第一个字段排序
null  被认为无穷大, order   by  也可以用别名。

where  
select   *   from  user_tables  where  table_name  like   ' s\_% '   escape   ' \ ' ;

between   and  在什么之间
not   between   and
in (List) 在某个集合中
not   in  (list) 空值会有影响
like  模糊配置
not   like  通配比较
is   null  是空
and  
or  
not  

查出s_emp表中所有员工的一年的总收入,注意空值处理
select  name , salary  *   12   * 1 +  nvl(commission_pct / 100 , 0 ))  from  s_emp

单行函数 (dual 哑表)
lower  转小写
select   lower ( ' SQLPLUS ' from  dual;
upper  转大写
select   upper ( ' sqlplus ' from  dual;
concat 字符串连接
select  concat(first_name, last_name)  from  s_emp; 等效于 ||
length 求长度
select  length( ' abcdefg ' from  dual;
substr 求子串
select  substr( ' abcdefg ' , 1 , 6 from  dual;
select  substr( ' abcdefg ' , - 2 from  dual; 取后面两个字符
round函数 
select   round ( 45.935 2 from  dual;
trunc 函数(截取,不管后面的数字) 
select  trunc( 45.9995 , 1 from  dual;

select  sysdate  from  dual;
内置函数
months_between(sysdate, addmonths(sysdate,
5 ))  // 两个月有多少天
add_months(sysdate, 
- 5 ) 在系统时间基础上延迟五个月
last_day(sysdate) 一个月的最后一天

格式转换函数
to_char 显示日期
to_char(date,
' 格式 ' )
select  to_char(sysdate, ' yyyy mm dd hh24:mi:ss ' from  dual;

to_date 表达日期
select  to_date( ' 2000 11 20 ' ' yyyy mm dd ' from  dual;

to_number 字符转数字

DDL
table   view  sequence  index
表    视图 序列     索引

表级约束 
create   table  test(c  number primary   key (c));
列级约束 
create   table  test(c  number   primary   key );

commit  提交,此时说明前面所有语句都成功执行
rollback  回退操作,此时会恢复至上一次提交时的状态
savepoint 设置保存点

alter   table  表名  add   constraint  约束名  primary   key  (字段);

select   *   from  cat;

select   *   from  tab;

select  table_name  from  user_all_tables;

select  view_name,  text   from  user_views;

select  index_name ,table_owner, table_name, tablespace_name, status  from  user_indexes  order   by  table_name;

 

转载于:https://www.cnblogs.com/chenqingwei/archive/2010/04/06/1705411.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值