oracle学习总复习

作者在 2010-06-13 08:31:44 发布以下内容
oracle 总复习
distinct去掉重复字段
nvl(字段,0)
like 's\%_%' escape '\'
substr('abcdef',4,3) 截取字符串
next_day(sysdate,'星期一')表示这个星期的是几号
add_months(sysdate,4)在当前月加4,或-4
trunc(sysdate,'month')//格式化日day格式化小时year格式化月hour格式化分
select to_char(sysdate,'fm yyyy-mm-dd d hh:mi:ss fm') from dual;
fm表示在这个区间的0和空格将不会输出来
左外连接e.message=e.id(+)
右外连接e.id=e.message
全连接
select c.name,c.sales_rep_id,e.id,e.last_name
     from s_customer c full outer join s_emp e
     on c.sales_rep_id=e.id
~~~~~~~~~~~~~~~~~
select name from (select rownum r,name from employee) where e>4
自定义的两种形式
   (1)define 变量名=值 创建变量值 
   (2)accept 变量名 类型 prompt[默认信息] hide[默认值]
    &变量名  得到变量值
constraint为约束取名字
default设置默认值
check 自定义约束 check age>12 and age<120
references 创建外键
create table test3(id number(23) constraint zhujian primary key,
       name varchar2(12) constraint name not null,
       age number default 12 check(age>12 and age<120) constraint age not null);
update 表名 set name='abcd' where name='abc'
修改姓名为abc的,改成abcd
alter table 表名 add(字段 类型 约束);向表中插入一条字段
alter table 表名 drop(字段) 删除字段
alter table 表名 rename column 表中字段名 to 新字段名//修改列名
rename 表名 to 新表名  //为表重命名
alter table 表名 add 约束(字段)//为表增加约束
创建序列
create sequence s_test3 increment by 4
start with 20039
maxvalue 99999
nocycle
nocache;
字段名 类型 references 表名(列名); 创建外键
create view 视图名 as 语句//创建 视图
select view_name from all_view;//查看所有视图
select index 索引名 on test21;//创建一个索引
declare
v_name constant number(12):=12;
 begin
dbms_output.put_line(v_name);
end;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
declare
vname test21.name%type;
 begin
for vname in reverse 1..3 loop
dbms_output.put_line('aineij');
end loop;
end;
~~~~~~~~~~~~~~~~
if then
elsif then
~~~~~~~~~~~~~~~~~
for 变量 in reverse 1..3 loop
end loop;
~~~~~~~~~~~~~~~
create user 名称 IDENNTIFIED BY 密码
create user wqjsd IDENTIFIED by abcd;
~~~~~~~~~~~~~~~~~~~~~~~~~~
create procedure win(
moi in/out/in out number
)as
execut 存储过程名
create procedure proc_11(myno in number)  
  is
  zcrow test21%rowtype;  
  begin 
    select * into  zcrow from test21 where id=myno;
    dbms_output.put_line('员工id:'||zcrow.id||'员工名字'||zcrow.name);  
  end;  
//存储过程调用execut proc_11(3);
~~~~~~~~~
create or replace function myadd(a number,b number)  
return number   
is 
    re number(4);
begin 
     re:=a+b;  
     return re;  
end;  
函数调用
select myadd(12,23) from dual; 
~~~~~~~~~~~~~~~~~~~
专业文章 | 阅读 985 次
文章评论,共2条
源本英明C
2010-06-17 14:05
1
很厉害
源本英明C
2010-06-21 16:17
2
<img src="image/face/2.gif" class="face">
游客请输入验证码
浏览275875次