我编写了一个存储过程来从表中检索数据集。
表中提供了数据,用于存储过程的输入,但它没有返回任何内容。
以下是我的存储过程。
CREATE PROCEDURE admin_lookup_qry (p_apn char(10), p_cbsa_code integer)
RETURNING varchar(50);
--Client Number 526586
--Client Name Direct Connect Inc.
--Client Abbrev dircon
--Tables admin_lookup
DEFINE ringto_num char(10);
DEFINE overflow_flag char(3);
DEFINE overflow_ring_to_num char(10);
DEFINE num_rings_overflow integer;
DEFINE cnt_ringto_num integer;
DEFINE return_string char(50);
DEFINE sql_err integer;
DEFINE isam_err integer;
-- Begin Error Handling
ON EXCEPTION SET sql_err, isam_err
LET return_string = 'ERROR'||','||sql_err||','||isam_err;
RETURN return_string;
END EXCEPTION
SET DEBUG FILE TO '/tmp/trace/admin_lookup_qry.trace';
TRACE ON;
-- Initialize Variables
LET return_string = "NONE";
LET cnt_ringto_num = 0;
LET ringto_num = " ";
LET overflow_flag = " ";
LET num_rings_overflow = 0;
LET overflow_ring_to_num = " ";
SELECT count(ringto_number)
INTO cnt_ringto_num
FROM admin_lookup
WHERE apn = p_apn
AND cbsa_code = p_cbsa_code;
IF cnt_ringto_num > 0 THEN
SELECT ringto_number, overflow_busy_flag, no_of_rings_to_overflow,overflow_ringto_number
INTO ringto_num, overflow_flag,num_rings_overflow,overflow_ring_to_num
FROM admin_lookup
WHERE apn = p_apn
AND cbsa_code = p_cbsa_code;
LET return_string = 'OK'||','||ringto_num||','||TRIM(overflow_flag)||','||num_rings_overflow||','||overflow_ring_to_num;
RETURN return_string;
ELSE
RETURN return_string;
END IF;
END PROCEDURE;
下面是表格架构,
create table admin_lookup
(
toll_free_number char(10),
apn char(10),
client_number integer,
cbsa_code char(6),
ringto_number char(10),
overflow_busy_flag char(3),
no_of_rings_to_overflow smallint,
overflow_ringto_number char(10),
primary key (apn,cbsa_code)
);
这是样本数据
toll_free_number 8885337800
apn 8117472815
client_number 10015
cbsa_code 36540
ringto_number 4022096303
overflow_busy_flag No
no_of_rings_to_ov+
overflow_ringto_n+
当我传递有效的apn和cbsa_code作为输入时,它返回1行检索但屏幕上没有数据显示。但是,如果我传递无效参数,则返回NONE。
答案 0 :(得分:1)
如果连接结果中的任何字段为NULL
,则整个字符串将为NULL
。根据您的示例数据,num_rings_overflow
字段似乎是罪魁祸首。
尝试在NULL
来电中包装NVL()
的每个字段,即:
SELECT ringto_number, overflow_busy_flag,
NVL(no_of_rings_to_overflow, ""), NVL(overflow_ringto_number, "")
要将NULL
值转换为空字符串,或者根据需要将特定字符串转换为特定字符串,即
NVL(field, "Not Applicable")