我有一个简单的问题。我有一条sql,它应该使用子选择插入值,但其中一个插入null,但这是错误的。如果仅运行 subselect,则 sql 返回正确的日期。知道出了什么问题吗?谢谢你的建议。
列 dt01_dt 和子查询 (select (indi.dt02_dt) from h_indivparam indi, t_intervenants i where indi.refindividu = '&i' and indi.str1 = 'DCD' and i.refindividu = indi.refindividu and i.reftype ='DB'和 i.refdoss = '&d')
INSERT
INTO g_piece (refdoss,
refpiece,
typpiece,
gpidate1_dt,
createur,
DT01_01,
mt01,
mt02,
mt03,
mt04,
mt05,
nb01,
nb02,
nb03,
nb04)
SELECT '&d',
'&N',
'INHERITANCE PROCEEDING CU',
SYSDATE,
'SE',
(SELECT (indi.dt02_dt)
FROM h_indivparam indi,
t_intervenants i
WHERE indi.refindividu = '&i'
AND indi.str1 = 'DCD'
AND i.refindividu = indi.refindividu
AND i.reftype ='DB'
AND i.refdoss = '&d'),
(SELECT dos.TOTAL_DUE_AMT
FROM csob_buf_doss dos,
g_dossier d
WHERE d.refdoss = '&d'
AND dos.ancrefdoss = d.ancrefdoss
AND dos.current_variant IN ('1','15','2','25',
'3','35','357','37',
'4','45','6','57',
'47','157','56','456',
'457','17','4567')),
(SELECT dos.DUE_PRIN_AMT
FROM csob_buf_doss dos,
g_dossier d
WHERE d.refdoss = '&d'
AND dos.ancrefdoss = d.ancrefdoss
AND dos.current_variant IN ('1','15','2','25',
'3','35','357','37',
'4','45','6','57',
'47','157','56','456',
'457','17','4567')),
(SELECT dos.DUE_INTER_AMT
FROM csob_buf_doss dos,
g_dossier d
WHERE d.refdoss = '&d'
AND dos.ancrefdoss = d.ancrefdoss
AND dos.current_variant IN ('1','15','2','25',
'3','35','357','37',
'4','45','6','57',
'47','157','56','456',
'457','17','4567')),
(SELECT dos.LATE_CHARGES_AMT
FROM csob_buf_doss dos,
g_dossier d
WHERE d.refdoss = '&d'
AND dos.ancrefdoss = d.ancrefdoss
AND dos.current_variant IN ('1','15','2','25',
'3','35','357','37',
'4','45','6','57',
'47','157','56','456',
'457','17','4567')),
(SELECT dos.DUE_FEES_AMT
FROM csob_buf_doss dos,
g_dossier d
WHERE d.refdoss = '&d'
AND dos.ancrefdoss = d.ancrefdoss
AND dos.current_variant IN ('1','15','2','25',
'3','35','357','37',
'4','45','6','57',
'47','157','56','456',
'457','17','4567')),
(SELECT dos.CURRENT_VARIANT
FROM csob_buf_doss dos,
g_dossier d
WHERE d.refdoss = '&d'
AND dos.ancrefdoss = d.ancrefdoss
AND dos.current_variant IN ('1','15','2','25',
'3','35','357','37',
'4','45','6','57',
'47','157','56','456',
'457','17','4567')),
(SELECT dos.NEW_LOAN_INSURANCE
FROM csob_buf_doss dos,
g_dossier d
WHERE d.refdoss = '&d'
AND dos.ancrefdoss = d.ancrefdoss
AND dos.current_variant IN ('1','15','2','25',
'3','35','357','37',
'4','45','6','57',
'47','157','56','456',
'457','17','4567')),
(SELECT COUNT(*)
FROM t_intervenants
WHERE refdoss = '&d'
AND reftype LIKE 'CE%'),
(SELECT COUNT(*)
FROM t_intervenants
WHERE refdoss = '&d'
AND reftype LIKE 'CA%')
FROM dual
如何获得正确结果的建议
您在
SELECT
中使用的 INSERT
查询可以简化为:
SELECT '&d',
'&N',
'INHERITANCE PROCEEDING CU',
SYSDATE,
'SE',
( SELECT indi.dt02_dt
FROM h_indivparam indi
INNER JOIN t_intervenants i
ON i.refindividu = indi.refindividu
WHERE indi.refindividu = '&i'
AND indi.str1 = 'DCD'
AND i.reftype ='DB'
AND i.refdoss = '&d'
),
dos.TOTAL_DUE_AMT,
dos.DUE_PRIN_AMT,
dos.DUE_INTER_AMT,
dos.LATE_CHARGES_AMT,
dos.DUE_FEES_AMT,
dos.CURRENT_VARIANT,
dos.NEW_LOAN_INSURANCE,
ti.cnt,
ti.cnt
FROM DUAL
LEFT OUTER JOIN (
csob_buf_doss dos
INNER JOIN g_dossier d
ON ( d.refdoss = '&d'
AND dos.ancrefdoss = d.ancrefdoss
AND dos.current_variant IN ('1','15','2','25',
'3','35','357','37',
'4','45','6','57',
'47','157','56','456',
'457','17','4567')
)
) ON (1 = 1)
CROSS JOIN (
SELECT COUNT(*) AS cnt
FROM t_intervenants
WHERE refdoss = '&d'
AND reftype LIKE 'CE%'
) ti
注意:未经测试,因为我们没有您的桌子。
如果内部
SELECT
子查询匹配零行,那么它将引发 NO_DATA_FOUND
异常,外部查询将其解释为 NULL
。匹配零行的实际原因可能是您的表不包含任何匹配数据,也可能是替换变量无效、为空或其他不正确,并且“正确”行被过滤掉。
但是,我们无法告诉您输出
NULL
的哪些可能原因是实际原因,因为我们无权访问:
您需要自己调试问题的其余部分,或者提供一个最小代表性示例,以便我们复制该问题。