oracle与mysql存储过程insert into

来源:互联网 发布:百度怎样做优化推广 编辑:程序博客网 时间:2024/05/17 07:14

建表语句
create table goods(id int primary key,name varchar2(20),price decimal(16,2));
select * from goods;
建存储过程语句
create or replace PROCEDURE g_sp
as
   g_name varchar2(20);
   g_price decimal(16,2);
begin
  for i in 0..5 loop
     g_name:=concat('tom',i);
     g_price:=dbms_random.value(0,100);
    insert into goods values(i,g_name,g_price);
  end Loop;
  commit;
end;

执行语句
begin
  g_sp;
end;


------------------------------------------mysql---------------------------


create PROCEDURE g_sp()
begin
  declare i int;
  declare g_id int;
  declare g_name varchar(20);
  declare g_price decimal(16,2);
  set i=0;
  labloop:Loop
    set g_id=i;
    set g_name=concat('tom',i);
    set g_price=rand()*100;
    insert into goods values(g_id,g_name,g_price);
  set i=i+1;
  if i>5 then
 leave labloop;
 end if;
  end Loop;
end;
call g_sp();

原创粉丝点击