我有以下代码:
WHILE (v_Count > 0)
LOOP
Select v_Columns || CHR(10) || CHR(9) || ColumnName || ',' ,
v_Values || CHR(10) || CHR(9) ||
CASE ISNUMERIC(Val)
WHEN 1 THEN Val
WHEN 0 THEN '''' || REPLACE(LTRIM(RTRIM(Val)), '''','''''') || ''''
END
|| ',' into v_Columns,v_Values
FROM
(
SELECT D.TableName, D.ColumnName, D.Val
FROM
(
SELECT ID, TableName, ColumnName, Val
FROM tblTemplates_Load_OtherObjects_Raw OO
JOIN tblTemplates_Fields F ON OO.OtherObjectsField = F.FieldName
WHERE TemplateType IN ('All', v_TemplateType)
AND OO.Val IS NOT NULL
AND (TemplateVersion = p_TemplateVersion or (TemplateVersion is null
and p_TemplateVersion <> 'V8'))
UNION
SELECT FieldID, TableName, ColumnName, Val
FROM tblTemplates_Fields_OtherDestinations OD
JOIN
(
SELECT ID, Val
FROM tblTemplates_Load_OtherObjects_Raw OO
JOIN tblTemplates_Fields F ON OO.OtherObjectsField = F.FieldName
WHERE TemplateType IN ('All', v_TemplateType)
AND OO.Val IS NOT NULL
AND (TemplateVersion = p_TemplateVersion or (TemplateVersion is
null and p_TemplateVersion <> 'V8'))
) UsedIDs
ON OD.FieldID = UsedIDs.ID
) D
JOIN USER_TAB_COLS C ON upper(D.TableName) = upper(C.TABLE_NAME) AND
upper(D.ColumnName) = upper(C.COLUMN_NAME)
WHERE (v_UpdateComp = 0 OR D.TableName <> 'tblComp')
AND (v_UpdateCompInd = 0 OR D.TableName <> 'tblCompInd')
ORDER BY D.TableName, D.ColumnName
)
WHERE TableName = v_TableName ;
v_Count := v_Count -1;
end loop;
其中v_count是一个数字,范围可以从5到6。
这里的问题是,由于循环的原因,试图将多个值存储到v_Columns和v_Values中,并且获得 exact精确提取将返回比请求的行数更多的错误。 我无法弄清楚如何重写这段代码,以使其正常工作。
我该如何重写此代码?
答案 0 :(得分:0)
对我来说,最可疑的是df.var1=df.var1.map(df_new.set_index('df2')['val1'])
print(df)
var1
0 1
1 2
2 1
3 2
,如果两个UNION
都返回至少一行,则会产生两行。您不能将两行放入这些变量中并得到错误。
该怎么办?如果可能,请将其重写到游标SELECT
循环中,该循环将逐行返回。