Oracle 存储过程A

create or replace procedure users_procedure is
  cursor users_cursor is select * from users;
  v_id users.id%type;
  v_username users.username%type;
  v_password users.password%type;
begin
  open users_cursor;
  fetch users_cursor into v_id, v_username, v_password;
  while users_cursor%found
    loop
      dbms_output.put_line('v_id = ' || v_id || 'v_username = ' || v_username || 'v_password = ' || v_password);
      fetch users_cursor into v_id, v_username, v_password;
    end loop;
  close users_cursor;
end;
/


create or replace procedure users_batch_insert_procedure is
  v_id users.id%type;
  v_username users.username%type;
  v_password users.password%type;
begin
  for i in 0..1000
    loop
      v_id := i;
      v_username := 'abc' || i;
      v_password := 'efg' || i;
      insert into users values(v_id, v_username, v_password);
      commit;
    end loop;
end;
/

create or replace procedure users_a is
  type users_cursor_type is ref cursor; --return users%rowtype;
  type users_record_type is record (v_id users.id%type, v_username users.username%type, v_password users.password%type);
  v_sql varchar2(2000);
  users_cursor_a users_cursor_type;
  users_record users_record_type;
begin
  v_sql := 'select * from users';
  open users_cursor_a for v_sql;
  fetch users_cursor_a into users_record;
  while users_cursor_a%found
    loop
      dbms_output.put_line('v_id = ' || users_record.v_id || 'v_username = ' || users_record.v_username || 'v_password = ' || users_record.v_password);
      fetch users_cursor_a into users_record;
    end loop;
  close users_cursor_a;
end;
/

create or replace procedure users_a is
  type users_cursor_type is ref cursor return users%rowtype;
  v_row users%rowtype;
  v_sql varchar2(2000);
  users_cursor_a users_cursor_type;
begin
  
  open users_cursor_a for select * from users;
  fetch users_cursor_a into v_row;
  while users_cursor_a%found
    loop
      dbms_output.put_line('v_id = ' || v_row.id || 'v_username = ' || v_row.username || 'v_password = ' || v_row.password);
      fetch users_cursor_a into v_row;
    end loop;
  close users_cursor_a;
end;
/

set serveroutput on size 1000000;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值