【发布时间】:2020-06-06 09:56:37
【问题描述】:
V_MAX:=NVL(CREAR_DEPART(V_NOMB),TO_CHAR('the value is null'));
DBMS_OUTPUT.PUT_LINE(V_MAX);
函数给了我一个型号
如何使用nvl 获取varchar2 中的值?
【问题讨论】:
标签: sql oracle plsql oracle-sqldeveloper
V_MAX:=NVL(CREAR_DEPART(V_NOMB),TO_CHAR('the value is null'));
DBMS_OUTPUT.PUT_LINE(V_MAX);
函数给了我一个型号
如何使用nvl 获取varchar2 中的值?
【问题讨论】:
标签: sql oracle plsql oracle-sqldeveloper
那个字符串已经是一个......好吧,字符串,你不要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>
【讨论】: