我有一张包含这些结构的表格:
Field A FieldB FieldC
material clay,rush
material air
metal iron
metal gold,silver,aluminium
我需要做的是填写C字段。为此,我必须进行如下查询:
select xxxxx from yyyyy where jjjjj in (material, clay, rush)
select xxxxx from yyyyy where jjjjj in (material, air)
select xxxxx from yyyyy where jjjjj in (metal, iron)
select xxxxx from yyyyy where jjjjj in (metal, gold, silver, aluminum)
yyyy是另一张桌子。
可以使用pl / sql Oracle制作这些吗?我一直在尝试,但我没有能力,似乎有点混乱。谢谢和问候,
答案 0 :(得分:0)
这对你有用
DECLARE
l_query VARCHAR(500);
BEGIN
FOR i in (SELECT FiledA, FiledB, FiledA||','||FiledB AS FiledC FROM test)
LOOP
l_query := 'SELECT xxxxx FROM yyyyy WHERE jjjjj IN ';
l_query := l_query||'('||i.FiledC||')';
UPDATE test
SET FiledC = l_query
WHERE FiledA = i.FiledA
AND FiledB = i.FiledB;
l_query := NULL;
END LOOP;
COMMIT;
END;
/