if p_quarter = '1' then
       str_month := p_year+'-01-01';
       end_month := p_year+'-04-01';
    elsif p_quarter = '2' then 
       str_month := p_year+'-04-01';
       end_month := p_year+'-07-01'; 
    elsif p_quarter = '3' then
       str_month := p_year+'-07-01';
       end_month := p_year+'-10-01'; 
    else
       str_month := p_year+'-10-01';
       end_month := to_char(to_number(p_year)+1)+'-01-01'; 
    end if;
p_quarter 表示的是季度、p_year 表示年份、为什么这样写判断不出来、要怎么写才可以、
过程没有语法错误
我以前没写过过程、所以不懂

解决方案 »

  1.   


    --p_year 是字符型的?  
    if p_quarter = '1' then
      str_month := p_year||'-01-01';
      end_month := p_year||'-04-01';
      elsif p_quarter = '2' then  
      str_month := p_year||'-04-01';
      end_month := p_year||'-07-01';  
      elsif p_quarter = '3' then
      str_month := p_year||'-07-01';
      end_month := p_year||'-10-01';  
      else
      str_month := p_year||'-10-01';
      end_month := to_char(to_number(p_year)+1)||'-01-01';  
      end if;
      

  2.   

    必须是:
    if ... then 
      ...
    elseif ... then 
      ...
    elseif ... then 
      ...
    end if
    或者
    if ... then
      ...
    end if
    if ... then
      ...
    end if
    形式、不能在前者里面混合else使用、如果是两种情况可以使用 if ... then ... else ... end if 这种形式
      

  3.   


    oralce 里面的elseif  必须写成elsif的 不然不识别的 
      

  4.   

    SQL> create or replace procedure proc_concat_time(p_year in varchar2,p_quarter in varchar2)
      2  as
      3  str_month varchar2(100);
      4  end_month varchar2(100);
      5  begin
      6  if p_quarter = '1' then
      7    str_month := p_year||'-01-01';
      8    end_month := p_year||'-04-01';
      9    elsif p_quarter = '2' then
     10    str_month := p_year||'-04-01';
     11    end_month := p_year||'-07-01';
     12    elsif p_quarter = '3' then
     13    str_month := p_year||'-07-01';
     14    end_month := p_year||'-10-01';
     15    else
     16    str_month := p_year||'-10-01';
     17    end_month := to_char(to_number(p_year)+1)||'-01-01';
     18    end if;
     19    dbms_output.put_line('str_month is '||str_month);
     20    dbms_output.put_line('end_month is '||end_month);
     21  end;
     22  /
     
    Procedure created
     
    SQL> set serveroutput on
    SQL> exec proc_concat_time('2010','1');
     
    str_month is 2010-01-01
    end_month is 2010-04-01
     
    PL/SQL procedure successfully completed
     
    SQL> exec proc_concat_time('2010','2');
     
    str_month is 2010-04-01
    end_month is 2010-07-01
     
    PL/SQL procedure successfully completed
     
    SQL> exec proc_concat_time('2010','3');
     
    str_month is 2010-07-01
    end_month is 2010-10-01
     
    PL/SQL procedure successfully completed
     
    SQL> exec proc_concat_time('2010','4');
     
    str_month is 2010-10-01
    end_month is 2011-01-01
     
    PL/SQL procedure successfully completed
     
    SQL> 
      

  5.   

    good good study,day day up