oracle基础:怎样把查询的null转换为0、打印、定义变量

https://blog.csdn.net/xuxile/article/details/49943665 oracle怎样把查询的null转换为0

 1、查询的null转换为0

NVL(Expr1,Expr2)如果Expr1为NULL,返回Expr2的值,否则返回Expr1的值

例如:select NVL(SUM(MONEY) ,0) from tb全都在NVL这儿起作用

select NVL(max(id),0) into id_num from NSTM_SYSTEM;

2、定义变量:

declare org_code VARCHAR2(50):='01';--创建并直接赋值
sysm1_id VARCHAR2(50):='HIS0311';
sysm2_id VARCHAR2(50):='HIS0120';
sysm3_id VARCHAR2(50):='HIP0104';
sysm4_id VARCHAR2(50):='HIP0105';
count1 int(1):=0;id_num int(1):=0;--直接创建变量
select count(*) into count1 from NSTM_ORGANIZATION where  code=org_code;--select语句打印

3、打印:

dbms_output.put_line('组织结构为空,增加该组织结构');--打印

4、if...end if;     bengin...end;

注;一个语句后需要加分号;块结束句后也要加分号;

 

原文地址:https://www.cnblogs.com/xyao1/p/10899267.html