如何在nvl()中使用字符

b4lqfgs4  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(349)
V_MAX:=NVL(CREAR_DEPART(V_NOMB),TO_CHAR('the value is null'));

DBMS_OUTPUT.PUT_LINE(V_MAX);

函数给我一个类型号
我怎么用 nvl 获得价值 varchar2 ?

llew8vvj

llew8vvj1#

那个字符串已经是。。。嗯,弦,你没有 to_char 是的。

SQL> with test (v_nomb) as
  2    (select to_number(null) from dual)
  3  select nvl(to_char(v_nomb), 'the value is null') result
  4  from test;

RESULT
-----------------
the value is null

SQL>

或者,对你来说,

V_MAX := NVL(to_char(CREAR_DEPART(V_NOMB)), 'the value is null');

正如您所评论的,函数返回 number . 或者-为了用一个 NVL -让它回来吧 null .

SQL> create or replace function crear_depart(par_nomb in number)
  2  return number is
  3  begin
  4    return null;
  5  end;
  6  /

Function created.

SQL> set serveroutput on;
SQL> declare
  2    v_max  varchar2(20);
  3    v_nomb number := 2;
  4  begin
  5    v_max := nvl(to_char(crear_depart(v_nomb)), 'the value is null');
  6    dbms_output.put_line('v_max = ' || v_max);
  7  end;
  8  /
v_max = the value is null

PL/SQL procedure successfully completed.

SQL>

相关问题