第一次写存储过程

学编程,好像都有个仪式,打印hello Word,我学python打印了,好简单print(‘hello Word’),plsql里要复杂一点,点开存储过程编辑框,输入:create or replace procedure hello is
begin
  dbms_output.put_line('hello word');
end hello;

然后进命令窗口,SQL> set serverout on;
SQL> exec hello;
hello word
PL/SQL procedure successfully completed

成功打印出来。现在想写个稍微复杂一点的,自己建个表sb,只有一个字段gbidsb,现在想手输入商品代码,执行过程从另一个数据库取数,插入sb表中。过程如下:

create or replace procedure getgdid( n_number in number) is
 n_num number;
begin
  select gbid into n_num  from goodsbase@hdqt_db t where t.gbid=n_number;
  dbms_output.put_line('代码'||n_num);
  insert into sb(gbidsb) values (n_num);
  commit;
end getgdid;

然后在命令窗口执行:

SQL> exec getgdid(754985);
代码754985
PL/SQL procedure successfully completed

完成,用select * from sb 查询有结果,成功。

posted @ 2020-10-15 16:47  蜕变大哥  阅读(99)  评论(0)    收藏  举报