sql - 如何在 nvl() 中使用 to_char
问题描述
V_MAX:=NVL(CREAR_DEPART(V_NOMB),TO_CHAR('the value is null'));
DBMS_OUTPUT.PUT_LINE(V_MAX);
该函数给了我一个类型号
我如何使用nvl
来获得价值varchar2
?
解决方案
那个字符串已经是一个......好吧,字符串,你不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
. 或者 - 为了用 a 捕获它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>
推荐阅读
- python - 当原始变量更新时,如何设置依赖于另一个变量的变量来更新?
- python - CommandInvokeError:命令引发异常:RuntimeError:在另一个循环正在运行时无法运行事件循环嗅探数据包时
- javascript - 如何修复与获取的数据不同的 Postman 数据
- flask - 有什么方法可以将 Flask 会话存储在本地存储中而不是 cookie 中?
- windows - Apache Cassandra 进程在 Windows 上是如何命名的?
- r - 如何更改R中矩阵中列的顺序
- java - 尝试使用 Java (Android Studio) 从 String 创建 JSONObject
- javascript - 如何在while循环中串联promise
- sql-server - 使用 Docker 连接的 SQL Server 的物理文件夹
- swift - 如何在 Swift 中使用变量编写 SQL Select Query?