oracle 저장 과정 중if 문장

9142 단어 저장 프로세스
1. 전체 스토리지 프로세스는 다음과 같습니다.
이 저장 프로세스는 내용이 좀 많을 수 있습니다. 이것은 제가 평소에 사용하던 저장 프로세스입니다. 마침 안에if문장이 사용되었기 때문에 제가 가져와서 여러분께 보여 드리겠습니다.
create or replace procedure p_censor_stat_status_org_real(r_codes       out varchar2,
                                                          r_msg         out varchar2,
                                                          r_data        out varchar2,
                                                          r_cur_data    out sys_refcursor,
                                                          info007_start in varchar2,
                                                          info007_end   in varchar2,
                                                          info008_start in varchar2,
                                                          info008_end   in varchar2,
                                                          p_info010     in varchar2,
                                                          p_info012     in varchar2,
                                                          p_info011     in varchar2,
                                                          p_info013     in varchar2,
                                                          p_info003     in varchar2,
                                                          p_info004     in varchar2,
                                                          p_info101     in varchar2) is

  --            (  )

  m_uuid         varchar2(32); --   id
  m_time         varchar2(30); --     
  m_info101      varchar2(30); --     
  m_info101_word varchar2(30); --     

begin
  r_codes := 'success';
  r_msg   := null;
  r_data  := null;
  --    id  
  select sys_guid() into m_uuid from dual;
  dbms_output.put_line(m_uuid);

  --       
  select to_char(systimestamp, 'yyyy-mm-dd hh24:mi:ss')
    into m_time
    from dual;

  if p_info101 = '0' then
    m_info101_word := '   ';
  elsif p_info101 = '1' then
    m_info101_word := '   ';
  elsif p_info101 = '2' then
    m_info101_word := '   ';
  
  end if;

  begin
  
    if p_info101 is not null then
      m_info101 := p_info101;
      insert into t_tmp_censor_stat_status_org
        (id, uuid, count, value, name, updatetime, indexs)
        (select sys_guid(),
                m_uuid,
                nvl(count(*), 0),
                '0',
                m_info101_word,
                m_time,
                1
           from t_censor_flow_inst_major t
          where (t.del_flag = '0' or t.del_flag is null)
            and t.info101 = m_info101
            and (info007_start is null or t.info007 > info007_start)
            and (info007_end is null or t.info007 < info007_end)
            and (info008_start is null or t.info008 > info008_start)
            and (info008_end is null or t.info008 > info008_end)
            and (p_info010 is null or instr(t.info010, p_info010) > 0)
            and (p_info011 is null or instr(t.info011, p_info011) > 0)
            and (p_info012 is null or instr(t.info012, p_info012) > 0)
            and (p_info013 is null or instr(t.info013, p_info013) > 0)
            and (p_info003 is null or instr(t.info003, p_info003) > 0)
            and (p_info004 is null or t.info004 = p_info004));
    
    else
      --     :        ,       /  
      insert into t_tmp_censor_stat_status_org
        (id, uuid, count, value, name, updatetime, indexs)
        (select sys_guid(),
                m_uuid,
                nvl(count(*), 0),
                '0',
                '    ',
                m_time,
                1
           from t_censor_flow_inst_major t
          where (t.del_flag = '0' or t.del_flag is null)
            and t.info102 = '0'
            and t.info101 = '0'
            and (info007_start is null or t.info007 > info007_start)
            and (info007_end is null or t.info007 < info007_end)
            and (info008_start is null or t.info008 > info008_start)
            and (info008_end is null or t.info008 > info008_end)
            and (p_info010 is null or instr(t.info010, p_info010) > 0)
            and (p_info011 is null or instr(t.info011, p_info011) > 0)
            and (p_info012 is null or instr(t.info012, p_info012) > 0)
            and (p_info013 is null or instr(t.info013, p_info013) > 0)
            and (p_info003 is null or instr(t.info003, p_info003) > 0)
            and (p_info004 is null or t.info004 = p_info004));
    
      --     :    
      insert into t_tmp_censor_stat_status_org
        (id, uuid, count, value, name, updatetime, indexs)
        (select sys_guid(),
                m_uuid,
                nvl(count(*), 0),
                '1',
                '    ',
                m_time,
                3
           from t_censor_flow_inst_major t
          where (t.del_flag = '0' or t.del_flag is null)
            and t.info102 = '1'
            and (info007_start is null or t.info007 > info007_start)
            and (info007_end is null or t.info007 < info007_end)
            and (info008_start is null or t.info008 > info008_start)
            and (info008_end is null or t.info008 > info008_end)
            and (p_info010 is null or instr(t.info010, p_info010) > 0)
            and (p_info011 is null or instr(t.info011, p_info011) > 0)
            and (p_info012 is null or instr(t.info012, p_info012) > 0)
            and (p_info013 is null or instr(t.info013, p_info013) > 0)
            and (p_info003 is null or instr(t.info003, p_info003) > 0)
            and (p_info004 is null or t.info004 = p_info004));
    
      --     :          
      insert into t_tmp_censor_stat_status_org
        (id, uuid, count, value, name, updatetime, indexs)
        (select sys_guid(),
                m_uuid,
                nvl(count(*), 0),
                '3',
                '    ',
                m_time,
                2
           from t_censor_flow_inst_major t
          where (t.del_flag = '0' or t.del_flag is null)
            and t.info101 = '1'
            and (info007_start is null or t.info007 > info007_start)
            and (info007_end is null or t.info007 < info007_end)
            and (info008_start is null or t.info008 > info008_start)
            and (info008_end is null or t.info008 > info008_end)
            and (p_info010 is null or instr(t.info010, p_info010) > 0)
            and (p_info011 is null or instr(t.info011, p_info011) > 0)
            and (p_info012 is null or instr(t.info012, p_info012) > 0)
            and (p_info013 is null or instr(t.info013, p_info013) > 0)
            and (p_info003 is null or instr(t.info003, p_info003) > 0)
            and (p_info004 is null or t.info004 = p_info004));
    
      --    :         
      insert into t_tmp_censor_stat_status_org
        (id, uuid, count, value, name, updatetime, indexs)
        (select sys_guid(),
                m_uuid,
                nvl(count(*), 0),
                '4',
                '   ',
                m_time,
                4
           from t_censor_flow_inst_major t
          where (t.del_flag = '0' or t.del_flag is null)
            and t.info101 = '2'
            and (info007_start is null or t.info007 > info007_start)
            and (info007_end is null or t.info007 < info007_end)
            and (info008_start is null or t.info008 > info008_start)
            and (info008_end is null or t.info008 > info008_end)
            and (p_info010 is null or instr(t.info010, p_info010) > 0)
            and (p_info011 is null or instr(t.info011, p_info011) > 0)
            and (p_info012 is null or instr(t.info012, p_info012) > 0)
            and (p_info013 is null or instr(t.info013, p_info013) > 0)
            and (p_info003 is null or instr(t.info003, p_info003) > 0)
            and (p_info004 is null or t.info004 = p_info004));
    end if;
  
  end;
  begin
    open r_cur_data for
      select t.name, t.count
        from t_tmp_censor_stat_status_org t
       where t.uuid = m_uuid
       order by t.indexs;
  end;
  /*       */
  delete t_tmp_censor_stat_status_org t where t.uuid = m_uuid;
  commit;

end p_censor_stat_status_org_real;

2. 주의해야 할 점
글을 쓸 때 여러 가지 상황이 있으면 반드시 사용하지 마라else if. 이런 용법은oracle 저장 과정에서 잘못된 것이기 때문에 사용해야 한다elsif. 처음 사용할 때 내가 잘못 썼기 때문에 아무리 조정해도 틀릴 수 있다. 마지막에 이것이 문제가 있다는 것을 알게 되었다.그래서 정확한 용법은 다음과 같다.
  if p_info101 = '0' then
    m_info101_word := '   ';
  elsif p_info101 = '1' then
    m_info101_word := '   ';
  elsif p_info101 = '2' then
    m_info101_word := '   ';
  
  end if;

또 하나 저장 과정 중의 판단이 동일한지 여부=를 판단하고 변수에 값을 부여할 때:=를 사용한다.
3. 결어
자, 이쪽 글은 여기까지입니다. 위에 쓴 글은 모두 제가 평소에 테스트한 것입니다. 여러분들이 다른 궁금한 점이 있으면 댓글로 올려주시면 됩니다. 모두 함께 토론하고 진보합시다.

좋은 웹페이지 즐겨찾기