oracle 创建表,序列,索引,视图,触发器,函数,存储过程,定时器,包体

oracle 创建表table:
create table abin1(
id number(20,0) not null,
name varchar2(100)not null,
pwd nvarchar2(100) not null,
create_time date,
constraint pk_abin1 primary key(id)
)

oracle创建索引(index):
create index myname on abin1(name);

oracle创建序列sequence:
create sequence abin1_seq
minvalue 1
maxvalue 999999999
start with 1
increment by 1
cache 20;
创建触发器:
create or replace trigger abin1_tri
before insert on abin1
for each row
begin
select abin1_seq.nextval into :new.id from dual;
end;


测试一条记录:
insert into abin1 (name,pwd,create_time) values ('abin','lee',sysdate); 
呵呵,这里插入了数据,主键自增了,说明成功了。


创建存储过程procedure:
create or replace procedure abin1_pro
is
cursor mycur is select t.* from abin1 t;
abin mycur%rowtype;
begin
     open mycur;
     loop
        fetch mycur into abin;
        if(abin.name='abin')then
              update abin1 t set t.name='abining',t.pwd=abin.pwd,t.create_time=sysdate where t.id=abin.id;
              commit;
        end if;
        exit when mycur%NOTFOUND;
     end loop;
        if(mycur%ISOPEN)then
             close mycur;
        end if;
end;


测试存储过程示例:
declare
begin
        abin1_pro;
end;


创建oracle函数function:
create or replace function abin_func
return number
is
total number;
begin
select count(1) into total from abin1 t;
return(total);
end;


创建测试函数示例:
declare
total number;
begin
      total:=abin_func;
      dbms_output.put_line(total);
end;


oracle创建视图:
create or replace view abin1_view
as
select t.* from abin1 t;


oracle创建package:
create or replace package abin_pac is
procedure abinpac;
end;


oracle创建package body:
create or replace package body abin_pac is
procedure abinpac is
total number;
begin
 select count(1) into total from abin1;
 dbms_output.put_line(total);
end;
end;

测试代码:
begin
 abin_pac.abinpac;
end;
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值