1.oracle中的decode是什么?2.如果回答是函数,那么我可不可以这样写:declare
v_test number :=3;
v_mes varchar2(10);
beginv_mes :=decode(v_test,3,'aaa','fafa');
dbms_output.put_line(v_mes);
end;请给出比较详细的解答,谢谢各位!

解决方案 »

  1.   

    1.decode是oracle中特有的函数
    2.你的用法也是对的可以参考http://xindongyinfu.javaeye.com/blog/564450
      

  2.   

    DECODE相当于IF THEN  ELSE
    decode(v_test,3,'aaa','fafa')可以理解为
    IF V_TEST=3 THEN
    v_mes='aaa'
    ELSE
    v_mes='fafa'
    end if
      

  3.   

    decode语句可以理解为一种简化版的IF语句
    Decode(column_name,comparison,action,comparison,action,. . .else action)
     --把column_name的内容与每一个comparison进行比较.如果相等, decode就执行action动作.如果没有任何一项与comparsion匹配,程序就执行else action动作
      

  4.   


    我的那种写法是不正确的。
    oracle 11g下已经验证。
      

  5.   

    DECODE 跟 CASE WHEN 的应用一样..........就代替所谓的IF ELSE吧..............
      

  6.   

    2,3楼,你们得意思是decode不是一个函数了?我想知道得是在oarcle下decode是什么,就是说oracle把decode定义为什么?
      

  7.   

    declare
    v_test number :=3;
    v_mes varchar2(10);
    begin
    select decode(v_test,3,'aaa','fafa') into v_mes from dual;
    dbms_output.put_line(v_mes);
    end;
    这样用,DECODE肯定是函数
    In Oracle/PLSQL, the decode function has the functionality of an IF-THEN-ELSE statement.The syntax for the decode function is:decode( expression , search , result [, search , result]... [, default] )expression is the value to compare.search is the value that is compared against expression.result is the value returned, if expression is equal to search.default is optional. If no matches are found, the decode will return default. If default is omitted, then the decode statement will return null (if no matches are found).Applies To:Oracle 9i, Oracle 10g, Oracle 11g 
      

  8.   


    SQL和PL/SQL中自带很多类型的函数,有字符、数字、日期、转换、和混合型等多种函数用于处理单行数据,因此这些都可被统称为单行函数。这些函数均可用于SELECT,WHERE、ORDER BY等子句中;
    decode 函数属于单行函数,需要配合SELECT,WHERE、ORDER BY等子句使用。
      

  9.   

    那我调用function来返回数据给变量为什么不行呢?
      

  10.   

    declare
    v_mes varchar2(10);
    begin
    v_mes :=to_char(12312);
    dbms_output.put_line(v_mes);
    end;
    to_char()也是函数单行函数吧。我可以像我上边的那样写。为什么decode这个函数不能赋值给变量呢?
      

  11.   

    想要把decode()函数返回值赋值给变量,必须使用select decode(..,..) into v_?? from ???? 这种方式赋值