え~と・・・時間ができたので(笑)SQL版をば
-- keyの設定(SQL*Plusでの実行を想定)
VARIABLE v_key NUMBER
EXECUTE :v_key := 1
-- なんか…無理矢理だな~、DB設計が悪いんだよな(笑)版
SELECT
MAX(CASE WHEN A.fno = 1 THEN B.fvalue END) AS field1,
MAX(CASE WHEN A.fno = 2 THEN B.fvalue END) AS field2,
MAX(CASE WHEN A.fno = 3 THEN B.fvalue END) AS field3
FROM
(
SELECT 1 AS fno, field1 AS fname FROM テーブルA WHERE key = :v_key
UNION ALL
SELECT 2 AS fno, field2 AS fname FROM テーブルA WHERE key = :v_key
UNION ALL
SELECT 3 AS fno, field3 AS fname FROM テーブルA WHERE key = :v_key
) A,
(
SELECT 'item1' AS fname, item1 AS fvalue FROM テーブルB WHERE key = :v_key
UNION ALL
SELECT 'item2' AS fname, item2 AS fvalue FROM テーブルB WHERE key = :v_key
UNION ALL
SELECT 'item3' AS fname, item3 AS fvalue FROM テーブルB WHERE key = :v_key
UNION ALL
SELECT 'item4' AS fname, item4 AS fvalue FROM テーブルB WHERE key = :v_key
UNION ALL
SELECT 'item5' AS fname, item5 AS fvalue FROM テーブルB WHERE key = :v_key
) B
WHERE A.fname = B.fname
/
「動的SQL」をオススメします。
お礼
お返事が遅くなりました。 解決しました。 どうも、ありがとうございます。