do_test()
{
i<<!
declare
do_date varchar(6);
begin
select to_char(sysdate,'yyyymm') into do_date from dual;
if do_date > 200902 and do_date < 200909 then
select 'flag','aaa' from dual;
elsif do_date >= 200909 and do_date < 201003 then
select 'flag','bbb' from dual;
else
select 'flag','ccc' from dual;
end if;
end;
!
}
##########
do_test | grep -i flag |read xxx flag
echo ${flag} 

解决方案 »

  1.   

    到底报错什么内容?看看里面好象是字符串比较有问题?do_test() 

    i < <! 
    declare 
    do_date varchar(6); 
    begin 
    select to_char(sysdate,'yyyymm') into do_date from dual; 
    if do_date > '200902' and do_date < '200909' then 
    select 'flag','aaa' from dual; 
    elsif do_date >= '200909' and do_date < '201003' then 
    select 'flag','bbb' from dual; 
    else 
    select 'flag','ccc' from dual; 
    end if; 
    end; 


    ########## 
    do_test | grep -i flag |read xxx flag 
    echo ${flag} 这样试试
      

  2.   

    执行了,报这个错 :select 'flag','aaa' from dual;
    *
    ERROR at line 6:
    ORA-06550: line 6, column 1:
    PLS-00428: an INTO clause is expected in this SELECT statement
    ORA-06550: line 8, column 1:
    PLS-00428: an INTO clause is expected in this SELECT statement
    ORA-06550: line 10, column 1:
    PLS-00428: an INTO clause is expected in this SELECT statement
      

  3.   


    意思是在select语句里要有传入一个变量里
    如:
    a varchar2(10);
    b varchar2(10);
    select 'flag','aaa' into a,b from dual; 
      

  4.   


    select 要和 into搭配起来用啊,
    就像你上面的这样:
    select to_char(sysdate,'yyyymm') into do_date from dual; 
    只有select就报这个错
      

  5.   


    select 'flag','aaa' from dual; 是单列,不能写2个列的!
      

  6.   

    写一个列 如select 'aaa' from dual; 
    也报错的阿
      

  7.   


    do_test() 

    i < <! 
    declare 
    do_date varchar(6); 
    flag varchar(50);
    bbb varchar(50);
    begin 
    select to_char(sysdate,'yyyymm') into do_date from dual; 
    if do_date > '200902' and do_date < '200909' then 
    select 'flag','aaa' into flag,bbb from dual; 
    elsif do_date >= '200909' and do_date < '201003' then 
    select 'flag','bbb' from dual; 
    else 
    select 'flag','ccc' from dual; 
    end if; 
    end; 


    ########## 
    do_test | grep -i flag |read xxx flag 
    echo ${flag} 
      

  8.   

    do_test() 

    i < <! 
    declare 
        do_date varchar(6); 
        flag varchar(50);
        bbb varchar(50);
    begin 
        select to_char(sysdate,'yyyymm') into do_date from dual; 
        if do_date > '200902' and do_date < '200909' then 
            select 'flag','aaa' into flag,bbb from dual; 
        elsif do_date >= '200909' and do_date < '201003' then 
            select 'flag','bbb' into flag,bbb from dual; 
        else 
            select 'flag','ccc' into flag,bbb from dual; 
        end if; 
    end; 


    ########## 
    do_test | grep -i flag |read xxx flag 
    echo ${flag} 
      

  9.   

    declare 
    do_date varchar(6); 
    v_flag  varchar2(20);
    v_aaa   varchar2(20);
    begin 
    select to_char(sysdate,'yyyymm') into do_date from dual; 
    if do_date > '200902' and do_date < '200909' then 
    select 'flag','aaa' into v_flag,v_aaa  from dual; 
    elsif do_date >= '200909' and do_date < '201003' then 
    select 'flag','bbb' into v_flag,v_aaa from dual; 
    else 
    select 'flag','ccc'  into v_flag,v_aaa  from dual; 
    end if; 
    end;在語句塊中 單獨 用select 后面一定得要 into 對應的變量