存過及如何給變量賦值

####無參存過less

create or replace procedure init_Income_EveMonth is
begin
  -- Created on 2016/9/6 by YANGQC 
  --每個月初始化薪資表
  declare
    cursor salesset is
      select s.user_id, to_char(sysdate, 'yyyy-mm') month
        from sys_salesman s
        left join sys_user u on s.user_id = u.user_id
       where u.status = 0
         and not exists (select 1
                from sys_income_main m
               where m.month = to_char(sysdate, 'yyyy-mm')
                 and m.user_id = s.user_id);
    salary Integer;
  begin
    for salesman in salesset loop
    
      select nvl((select b.salary
                 
                   from sys_income_basicsalay b
                  where b.user_id = salesman.user_id
                    and b.flag = 0),
                 0)
        into salary
        from dual;
      insert into sys_income_main m
        (m.id, USER_ID, month, BASIC_SALARY, ALLRESULT)
      values
        ((select max(m1.id) + 1 from sys_income_main m1),
         salesman.user_id,
         salesman.month,
         salary,
         salary);
    end loop;
    commit;
  end;
end init_Income_EveMonth;

上面是一個無參存過;oop

  • 使用into給參數salary賦值,這個只適用於select語句查詢出結果的狀況;
  • 存過格式以下:
create or replace procedure xxx
begin 
end xxx;

####有參存過測試

create or replace procedure test_parameter(emp_name in varchar2, dept_no out number ) is
begin
  dept_no:=2;
end test_parameter;

這個存過定義了輸入和輸出參數 測試該存過code

-- Created on 2016/9/6 by YANGQC 
declare 
  -- Local variables here
  i integer:=20;
  x varchar2(20);
begin
  test_parameter(x,i);
   dbms_output.put_line('After swap: x = ' || x || ',i= ' ||i);
end;
  • 輸出結果:After swap: x = ,i= 2 有參存過的輸入和輸出參數都不可缺乏
相關文章
相關標籤/搜索