--获取系统的当前时间的函数,以字符形式返回(这样写为什么创建失败?????????)
create or replace function get_current_string_date return char(100)
is
current_date char(100);
begin
  select to_char(sysdate,'yyyy-mm-dd  hh24:mi:ss') into current_date  from dual;
  return current_date;
exception
  when others
    return 'error';
end get_current_string_date;
--但是采用这样测试又可以
declare
current_date char(100);
begin
  select to_char(sysdate,'yyyy-mm-dd  hh24:mi:ss') into current_date  from dual;
  dbms_output.put_line(current_date);
exception
  when others then
   dbms_output.put_line('error');
end;

解决方案 »

  1.   

    create or replace function get_current_string_date return CHAR is
    current_date char(100);
    begin
      select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') into current_date from dual;
      return current_date;
    exception
      when OTHERS THEN return 'error';
    end get_current_string_date;
      

  2.   


    create or replace function get_current_string_date
    return char-- 这里不需要指定大小
    is
    current_date char(100);
    begin
      select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') into current_date from dual;
      return current_date;
    exception
      when others then --少了关键字then
      return 'error';
    end get_current_string_date;select get_current_string_date from dual;GET_CURRENT_STRING_DATE
    ------------------------------
    2011-03-25 10:06:27