oracle笔记

1:导入数据库(直接cmd)
imp 姓名/密码@服务 file=文件路劲 full=y
例如:imp zhl/password@orcl file=d:\zhl.dmp full=y

2:创建 赋值权限 删除用户
CREATE USER 姓名 IDENTIFIED BY 密码
grant all on 数据库名 to 用户名
drop USER  姓名(删除用户)


3:修改 添加表 删除表字段 格式:
alter table 表名 add 新列列名 列数据类型   [default 0 not null]   (添加列默认值为0)
alter table 表名 drop 列名   (删除列)
alter table 表名 alter column 列名 新添加的数据类型  (修改列)

4:oracle删除序列化
DROP SEQUENCE 序列名字 

oracle创建序列化:
CREATE SEQUENCE seq_itv_collection
            INCREMENT BY 1  -- 每次加几个  
            START WITH 1399    -- 从1开始计数  
            NOMAXVALUE        -- 不设置最大值  
            NOCYCLE           -- 一直累加,不循环  
            CACHE 10; 

5:oracle修改序列化:Alter Sequence  
如果想要改变 start值,必须 drop  sequence 再  re-create .   
Alter sequence 的例子
ALTER SEQUENCE emp_sequence  
           INCREMENT BY 10  
           MAXVALUE 10000  
           CYCLE    -- 到10000后从头开始  
           NOCACHE ;  
实例:
create sequence AA_BASE_DS_PARAM_SEQ
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
cache 20;


有两种方式可以实现条件循环

一、for  变量  in  开始数值...结束数值 loop     end loop;

二、while 条件 loop       end  loop;

6:Oracle数据库中实现某一列的自动增加
在 oracle里有序列(sequence)我们要创建一个序列才能完成自动增加
create sequence AA_BASE_DS_PARAM_SEQ
minvalue 1
maxvalue 999999999999999999999999999
start with 1
increment by 1
cache 20;

这样就创建了一个序列 向数据库中插入数据时SQL的格式如下
insert into auto_incre_test (id) values(序列名.nextval);
 
--------------------------------------------------
declare
  i number;
begin
  i := 0;
  loop
    i := i + 1;
    insert into XMS_EXAME_TEM (id) values (AA_BASE_DS_PARAM_SEQ.nextval);
    if i > 5 then
      exit;
    end if;
  end loop;

end;

-------------------------------
declare
  i number;
begin
  i := 0;
  for i in 1 .. 99999 loop
    insert into XMS_EXAME_TEM (id) values (seq_XMS_EXAME_TEM.nextval);
  end loop;

end;s
还有一种方法就是象Access和Sql Server 里自动增加的字段效果一样的 在insert 语句里
不用指明字段 自己就添加的方法  首先也要生成一个序列,此外还有给被插入的表添加一个触发器
让表中的某列值自动加一(用序列和触发器实现):   
   
  建立触发器:  
create or replace trigger ait_bir
  before insert on auto_incre_test
  for each row
begin
  select 序列名.nextval into :new.id from dual;
end; 
  在往表auto_incre_test插入记录时,只需插入除ID以外的列的值,ID值会自动递增


存储过程:

create or replace procedure SS_VEHICLE_PRODUCT_CONFIRM(v_id      in varchar2, --接车单ID
                                                       v_user_id in varchar2, --操作人员ID
                                                       v_result  out varchar2,
                                                       v_ok      out number) is
  /*
  存储过程说明:                                                                                         
  精品销售处理:
  */

  -------------------------------------------------------------------------------------------
  /*
  rowtype变量
  */
  t_aa_sec_user aa_sec_user%rowtype; --人员信息
  t_b_lot_cargo b_lot_cargo%rowtype; --库存信息
  t_ss_vehicle  ss_vehicle%rowtype; --接车单

  -------------------------------------------------------------------------------------------
  /*
  number变量
  */

  -------------------------------------------------------------------------------------------
  /*
  varchar2变量
  
  */
  -------------------------------------------------------------------------------------------
  /*
  cursor变量
  */
  --精品销售信息
  cursor c_ss_vehicle_product is
    select a1.id,
           a1.aa_headquarter_id,
           a1.aa_client_id,
           a1.aa_org_id,
           a1.create_by,
           a1.create_date,
           a1.update_by,
           a1.update_date,
           a1.isactive,
           a1.entitytype,
           a1.status,
           a1.b_lot_cargo_id,
           a1.cargo_name,
           a1.cargo_code,
           a1.b_warehouse_id,
           a1.cur_price,
           a1.qty_num,
           a1.cur_amount,
           a1.ss_vehicle_id,
           a1.aa_sec_user_id_sale,
           a1.cur_price_vip,
           a1.cur_price_novip,
           a1.sel_is_redu_able,
           a1.manual_receive_no,
           a1.b_lot_id,
           a1.b_cargo_id,
           a2.qty_num - nvl(a2.qty_lock, 0) qty_num_able
      from ss_vehicle_product a1, b_lot_cargo a2
     where a1.b_lot_cargo_id = a2.id
       and a1.ss_vehicle_id = t_ss_vehicle.id;

  --入库货物库位处理信息
  cursor c_ss_vehicle_product_store is
    select a1.b_cargo_id,
           a1.aa_org_id,
           a1.update_date,
           a1.qty_num,
           a1.aa_sec_user_id_sale,
           a1.b_warehouse_id
      from ss_vehicle_product a1, b_lot_cargo a2
     where a1.b_lot_cargo_id = a2.id
       and a1.ss_vehicle_id = t_ss_vehicle.id
     group by a1.b_cargo_id;
  -------------------------------------------------------------------------------------------
  /*
  公共变量
  */
  v_curr_date    date := sysdate;
  v_count        number;
  error1 exception;
begin

  --接车单信息
  select a.* into t_ss_vehicle from ss_vehicle a where a.id = v_id;

  --获取人员信息
  begin
    select *
      into t_aa_sec_user
      from aa_sec_user a
     where a.aa_user_id = v_user_id;
  exception
    when no_data_found then
      --不做处理
      null;
  end;

  --精品销售明细不能为空
  select count(*)
    into v_count
    from ss_vehicle_product a
   where a.ss_vehicle_id = t_ss_vehicle.id;
  if v_count = 0 then
    v_result := '提示: 精品销售明细不能为空!';
    raise error1;
  end if;

  --循环处理精品销售信息
  for v_ss_vehicle_product in c_ss_vehicle_product loop
    --判断精品销售数量信息
    if nvl(v_ss_vehicle_product.qty_num, 0) <= 0 then
      --返回错误信息
      v_result := '错误:产品 ' || v_ss_vehicle_product.cargo_name ||
                  ' 的精品销售货物必须大于0';
      raise error1;
    end if;
  
    --减少产品库存信息(即 b_lot_cargo 中qty_num减少)
    update b_lot_cargo a
       set a.qty_num = a.qty_num - v_ss_vehicle_product.qty_num
     where a.id = v_ss_vehicle_product.b_lot_cargo_id;
  
    --新增 产品库存跟踪记录(b_lot_cargo_track)的出库信息
    insert into b_lot_cargo_track
      (id,
       aa_headquarter_id,
       aa_client_id,
       aa_org_id,
       create_by,
       create_date,
       update_by,
       update_date,
       isactive,
       entitytype,
       status,
       b_lot_id,
       b_cargo_id,
       aa_sec_org_id,
       qty_num,
       sel_inout,
       work_date,
       aa_sec_user_id)
    values
      (b_lot_cargo_track_seq.nextval, --id
       t_aa_sec_user.aa_headquarter_id, --aa_headquarter_id,
       t_aa_sec_user.aa_client_id, --aa_client_id
       t_aa_sec_user.aa_org_id, --aa_org_id
       t_aa_sec_user.aa_user_id, --create_by
       v_curr_date, --create_date,
       t_aa_sec_user.aa_user_id, --update_by,
       v_curr_date, --update_date,
       'Y', --isactive,
       'U', --entitytype,
       0, --status,
       t_b_lot_cargo.b_lot_id, --b_lot_id,
       t_b_lot_cargo.b_cargo_id, --b_cargo_id,
       v_ss_vehicle_product.aa_org_id, --aa_sec_org_id,
       v_ss_vehicle_product.qty_num, --qty_num,
       '1', --sel_inout,--1 表示出货 0 表示进货
       v_ss_vehicle_product.update_date, --work_date,
       v_ss_vehicle_product.aa_sec_user_id_sale --aa_sec_user_id
       );
  
  end loop c_ss_vehicle_product;

  --如果“仓库”不为空,减少“仓库”的产品库位信息(B_LOT_STORE)

  for v_ss_vehicle_product_store in c_ss_vehicle_product_store loop
    if v_ss_vehicle_product_store.b_warehouse_id is not null then
      --则产生减少“仓库”的产品库位信息(B_LOT_STORE)
      update b_lot_store a
         set a.update_by   = t_aa_sec_user.aa_user_id,
             a.update_date = v_curr_date,
             a.qty_num     = a.qty_num - v_ss_vehicle_product_store.qty_num
       where a.b_cargo_id = v_ss_vehicle_product_store.b_cargo_id
         and a.b_Warehouse_Id = v_ss_vehicle_product_store.b_warehouse_id;
    
      --产生“仓库”的的产品库位跟踪记录(B_LOT_STORE_TRACK)的出库信息
      insert into b_lot_store_track
        (id,
         aa_headquarter_id,
         aa_client_id,
         aa_org_id,
         create_by,
         create_date,
         update_by,
         update_date,
         isactive,
         entitytype,
         status,
         b_cargo_id,
         b_warehouse_id,
         qty_num,
         sel_inout,
         work_date,
         aa_sec_user_id)
      values
        (b_lot_store_track_seq.nextval, --id
         t_aa_sec_user.aa_headquarter_id, --aa_headquarter_id,
         t_aa_sec_user.aa_client_id, --aa_client_id
         t_aa_sec_user.aa_org_id, --aa_org_id
         t_aa_sec_user.aa_user_id, --create_by
         v_curr_date, --create_date,
         t_aa_sec_user.aa_user_id, --update_by,
         t_b_lot_cargo.update_date, --update_date,
         'Y', --isactive,
         'U', --entitytype,
         0, --status,
         v_ss_vehicle_product_store.b_warehouse_id, --b_warehouse_id,
         v_ss_vehicle_product_store.aa_org_id, --aa_sec_org_id,
         v_ss_vehicle_product_store.qty_num, --qty_num,
         '1', --sel_inout,--1 表示出货 0 表示进货
         v_ss_vehicle_product_store.update_date, --work_date,
         v_ss_vehicle_product_store.aa_sec_user_id_sale --aa_sec_user_id
         );
    end if;
  
  end loop v_ss_vehicle_product_store;

  -------------------------------------------------------------------------------------------
  /*
  最后返回消息  0(错误),1(成功但不提示),2(成功并提示)
  */
  v_result := '提示: 操作成功!';
  v_ok     := 1;

exception
  when error1 then
    v_ok := 0;
    rollback;
  when others then
    rollback;
    v_result := '错误: ' || v_id || sqlerrm;
    v_ok     := 0;
end SS_VEHICLE_PRODUCT_CONFIRM;


 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值