orcale 存储过程样例

循环语句:

  temValue number:=1;

 function add_account_func(accountnum in varchar2,accounttype in varchar2,balance in number,customerid in varchar2) return number is

  begin
    for c1 in (select * from scott.account_trade) loop
      temValue:=temValue+c1.t_balance;
    end loop;

    insert into scott.account (accountnumber,accounttype,balance,customerid) values(accountnum,accounttype,balance+temValue,customerid);
    return(temValue);
  end;

SELECT INTO语句:

CREATE OR REPLACE  PROCEDURE "SCOTT"."GETEMP" (
 eno in NUMBER,
 nameout out VARCHAR2
)
as
VS_ENAME VARCHAR2(10);
begin
 select ENAME into vs_ename from scott.emp where empno=eno;
 nameout:=VS_ENAME;
 DBMS_OUTPUT.PUT_LINE('VS_ENAME:'||VS_ENAME);
end;

if 语句:

 动态sql 语句:

declare
  -- Local variables here
  i integer;
  v_processed integer;
  v_sql varchar2(1000);
  v_cursor integer;
  v_row integer:=0;
begin
  -- Test statements here
  v_cursor:=dbms_sql.open_cursor;
  v_sql:='select balance from scott.account'||' where accountnumber<>''NL0005''';
  dbms_sql.parse(v_cursor,v_sql,dbms_sql.native);
  dbms_sql.define_column(v_cursor,1,i);
  v_processed:=dbms_sql.execute(v_cursor);
  v_row:=dbms_sql.fetch_rows(v_cursor);
  while v_row>0 loop
   dbms_sql.column_value(v_cursor,1,i);
   dbms_output.put_line('balance:'||i);
   v_row:=dbms_sql.fetch_rows(v_cursor);
  end loop;
end;

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值