SELECT
SUBSTR(B.C_TYP, 1, 4)
,SUBSTR(B.X_DESC, 1, 25)
,SUBSTR(A.C_TYP, 5, 4)
,SUBSTR(A.X_DESC, 1, 25)
,SUBSTR(A.X_DESC, 82, 11) FROM M.MASCTAB A, M.MASCTAB B WHERE
A.I_PLT = ?
AND A.N_TBL = ?
AND A.C_TYP LIKE ?
AND A.I_PLT = B.I_PLT
AND SUBSTR(A.C_TYP, 1, 4) = SUBSTR(B.C_TYP, 1, 4)
AND SUBSTR(A.X_DESC, 81, 1) = 'W'
AND B.N_TBL = 'DEPTC'
ORDER BY A.C_TYP
SELECT
(SELECT SUBSTR(C_TYP, 1, 4)
FROM M.MASCTAB
WHERE I_PLT = A.I_PLT
AND N_TBL = 'DEPTC'
AND LEFT(C_TYP, 4) = LEFT(A.C_TYP, 4)
)
,(SELECT SUBSTR(X_DESC, 1, 25)
FROM M.MASCTAB
WHERE I_PLT = A.I_PLT
AND N_TBL = 'DEPTC'
AND LEFT(C_TYP, 4) = LEFT(A.C_TYP, 4)
),SUBSTR(A.C_TYP, 5, 4)
,SUBSTR(A.X_DESC,1, 25)
,SUBSTR(A.X_DESC, 82, 11)
FROM M.MASCTAB A
WHERE A.I_PLT = ?
AND A.N_TBL = ?
AND A.C_TYP LIKE ?
AND SUBSTR(A.X_DESC, 81, 1) = 'W'
ORDER BY A.C_TYP
WITH UR
优化查询后,使用精确的结果集,在部署代码后面临问题。 错误_jspService错误类java.lang.NullPointerException
会有什么问题?请帮忙。
答案 0 :(得分:0)
我认为您的select (select ...), (select ...), .... From ....)
存在问题。只要您的两个子查询返回1或0个结果,查询就会成功。
查看您的初始查询,它看起来非常简单或无辜。但是,您可以优化一些内容。
A.C_TYP LIKE ?
- 类似的操作符很危险。这可以提高查询的性能。从您的程序提供该查询尝试避免'%'位于字符串开头的构造。 with temp_table as
(select C_TYP, X_DESC, I_PLT, N_TBL, SUBSTR(C_TYP, 1, 4) as join_key
from M.MASCTAB)
select B.join_key,
SUBSTR(B.X_DESC, 1, 25),
SUBSTR(A.C_TYP, 5, 4),
SUBSTR(A.X_DESC, 1, 25),
SUBSTR(A.X_DESC, 82, 11)
FROM temp_table A inner join temp_table B on A.join_key=B.join_key
WHERE A.I_PLT = ?
AND A.N_TBL = ?
AND A.C_TYP LIKE ?
AND A.I_PLT = B.I_PLT
AND SUBSTR(A.X_DESC, 81, 1) = 'W'
AND B.N_TBL = 'DEPTC'
ORDER BY A.C_TYP
答案 1 :(得分:0)
您似乎正在尝试使用公用表表达式,但是语法不完整。根据您的原始查询所说的内容,并保留修改后的查询的结构,看起来您的修改后的查询应该是这样的:
with A as
( SELECT I_PLT
,N_TBL
,SUBSTR(C_TYP, 1, 4) MAIN_TYPE
,SUBSTR(C_TYP, 5, 4) SUB_TYPE
,SUBSTR(X_DESC, 1, 25) X_DESC_PT1
,SUBSTR(X_DESC,82, 11) X_DESC_PT2
FROM M.MASCTAB
WHERE I_PLT = ?
AND N_TBL = ?
AND C_TYP LIKE ?
AND SUBSTR(A.X_DESC, 81, 1) = 'W'
), B as
( SELECT I_PLT
,SUBSTR(C_TYP, 1, 4) MAIN_TYPE
,SUBSTR(X_DESC, 1, 25) DESC_PT1
FROM M.MASCTAB
WHERE N_TBL = 'DEPTC'
)
SELECT B.MAIN_TYPE
,B.DESC_1
,A.SUB_TYPE
,A.DESC_1
,A.DESC_2
FROM A
JOIN B
ON A.I_PLT = B.I_PLT
AND A.MAIN_TYPE = B.MAIN_TYPE
ORDER BY MAIN_TYPE,SUB_TYPE
WITH UR