orcale基础摘要

来源:互联网 发布:linux cp拷贝进度条 编辑:程序博客网 时间:2024/05/16 02:12

1. alter session set nls_date_format='yyyy=mm-dd';


2. trunc(4.5) -> 4 round(4.5) -> 5


3. select 'Hello' || name || '!' from bbs;


4. initcap 首字母大写 initcap(字段)
   tower 小写  tower(字段)
   upper 大写  upper(字段)
   replace 替换  replace(字段,原值,替换为)
   substr 字符串截取 substr(字段,开始位置,结果位置)
   length 长度  length(字段)
   nvl  空值转换 nvl(字段,转换为)
   decode if elseif... decode(字段,if,{},elseif,{},elseif,{}......)
   sign  正负值1 -1 0 sign(-5) -> -1


5. alter table a add primary key(id);  加主键
   alter table a add modify(name not null); 加非空
   alter table a add check(sex in('男','女')); 加检查
   alter table a add check(sal between 500 and 1000); 加检查


6. select table_name from user_tables; 当前用户拥有表
   select talbe_name from all_tables; 拥有+他人授权


7. 1)instersect  select name from a  instersect select name from b;
   2)union   ..     union  ..
   3)minus   ..     minus ..
 a  1,2,3,4,5,6
 b  4,5,6
  1)4,5,6  交集
  2)1,2,3,4,5,6 合集
  3)1,2,3  差集


8. create table a as select * from b;
        复制表(不能复制约束)
   create table a as select * from b where 1=2;
     复制结构
   insert into a select * from b;
   insert into a(name) select name from b;


9. alter table a add(job varchar2(1));  添加字段
   alter table a modify(job varchar2(20)); 修改字段属性
   alter table a drop colomn job;  删除字段
   
   rename a to aa; 改表名


10. create synonym xxx from scott.emp; 同义词
      -〉
 select * from scott.emp;
 select * from xxx;


11. grant select on emp to yan;  授权
    grant 权限   on 表  to 用户;


12. create index idx_hiredate on emp(hiredate);  索引

    drop index idx_hiredate;

原创粉丝点击