- 締切済み
sqlについて
質問です! 今ビューでレポートを印字させているのですが、下記の一行の値の部分を (部品コード01)~(部品コード15)分行表示させたいのですがどうしたらよろしいでしょうか? このセレクト分にて取ってきたデータは下記のとうりです。 結果 (セット商品コード) SET01 健やかセット 400000 350000 300000 250000 (部品コード01) B01 ベッドB01 1 180000 200000 220000 240000 (部品コード02) A01 車椅子A01 1 30000 40000 50000 60000 (部品コード03) XYZF014E 四輪歩行補助車アバン 1 64000 48000 42000 0 *この後はトランの中にデータがあれば(部品コード15)まで表示します。 上記の値が一行で表示されているのを SET01 健やかセット 400000 350000 300000 250000 上記の部分だけ一緒にして項目に値が入っているものだけ 行表示したい訳です。 例) SET01 健やかセット 400000 350000 300000 250000 B01 ベッドB01 1 180000 200000 220000 240000 上記で一行 SET01 健やかセット 400000 350000 300000 250000 A01 車椅子A01 1 30000 40000 50000 60000 上記で二行のように よろしくお願いします。
- みんなの回答 (5)
- 専門家の回答
みんなの回答
- Mizyu
- ベストアンサー率41% (245/593)
アプリケーション側で制御を入れるのであれば、このような方法はいかがでしょう? ------------------------------------------------- dim i as Integer for i = 1 to 15 strSQL = "SELECT " strSQL = strSQL & "T_KUMIHIN.SHOHINCD, " strSQL = strSQL & "NVL(SHO.SHOHINNM,'') AS SHOHINNM00, " strSQL = strSQL & "NVL(SHO.BAIKA0,'') AS BAIKA00, " strSQL = strSQL & "NVL(SHO.BAIKA1,'') AS BAIKA10, " strSQL = strSQL & "NVL(SHO.BAIKA2,'') AS BAIKA20, " strSQL = strSQL & "NVL(SHO.BAIKA3,'') AS BAIKA30, " strSQL = strSQL & "NVL(KUMI.SHOHINCD,'') AS BUHINCD01, " strSQL = strSQL & "NVL(KUMI.SHOHINNM,'') AS SHOHINNM01, " strSQL = strSQL & "DECODE(T_KUMIHIN.KAZU0" & i & ",0,NULL,T_KUMIHIN.KAZU0" & i & ") AS KAZU, " strSQL = strSQL & "NVL(KUMI.BAIKA0,'') AS BAIKA01, " strSQL = strSQL & "NVL(KUMI.BAIKA1,'') AS BAIKA11, " strSQL = strSQL & "NVL(KUMI.BAIKA2,'') AS BAIKA21, " strSQL = strSQL & "NVL(KUMI.BAIKA3,'') AS BAIKA31 " strSQL = strSQL & "DECODE(T_KUMIHIN.RECFLG,'1','削除',' ') AS RECFLG " strSQL = strSQL & "FROM " strSQL = strSQL & "T_KUMIHIN, " strSQL = strSQL & "SHOHINMST SHO, " strSQL = strSQL & "SHOHINMST KUMI " strSQL = strSQL & "WHERE " strSQL = strSQL & "SHO.SHOHINCD (+) = T_KUMIHIN.SHOHINCD AND " strSQL = strSQL & "KUMI.SHOHINCD (+) = T_KUMIHIN.BUHINCD0" & i (strSQLの実行、結果取得) (配列へ格納) next ------------------------------------------------- このようにレコード一件に対し、SQLを発行し、取得するという手法も考えられます。 元のビューも外部結合をたくさん使っているのでパフォーマンスは無視して考えてよいと判断し、この案を提案させていただいてます。 (ようはパフォーマンスはものすごく悪いです。)
- Mizyu
- ベストアンサー率41% (245/593)
> DECODE(T_KUMIHIN.KAZU01,0,NULL,T_KUMIHIN.KAZU01) AS KAZU, > KAZU01の部分が一行に15項目あるのでこのままだとKAZU01の値しか取ってこれません。自分でも考えてみたのですが、ここが一番厄介なところかなと思っています。 気づきませんでした。そういうことですか。 テーブルレイアウト、拝見しました。 私のSQLスキルの範囲ではKAZUを振り分けるのは不可能だと思います。 もし、テーブルレイアウトの作り直しができるのであれば 下記のように直すことをお勧めします。 ・T_KUMIHINには部品コードに付随する情報のみ ・SHOHINMSTにはセット商品コードに付随する情報のみ ・もう一つテーブルを起こし、 ・セット商品コード ・部品コード ・数 のカラムを持つテーブルを作る。 最後に記載したテーブルには、どのセット商品にどの部品がいくつ入っているか、の情報のみを記載します。
お礼
大変ありがとうございました。 やはり不可能なんですね! とりあえず考えてみたんですが更新処理にまたこのテーブルを使いますので レコードレイアウトはこのままで行こうと思います。 ただ制御側で何とかしようと思うのですが、VBのアクティブレポートを使っていて 前のままのビューだと一行に全てのデータを持っているのでグループヘッダーでの ブレイクが必要になってきます。 もしその一行の部品コードがNULLだったらブレイクさせなければなりませんが 次の行フィールドへ印字させていかなければ毎回同じ所に上書きになってしまいます。 レイアウトのフィールドは一つでプレビュー時に下方向にネクストフィールドを出す関数をご存知であればよろしくお願いします。
- Mizyu
- ベストアンサー率41% (245/593)
すいません。 下記修正版です。 SELECT T_KUMIHIN.SHOHINCD, NVL(SHO.SHOHINNM,'') AS SHOHINNM00, NVL(SHO.BAIKA0,'') AS BAIKA00, NVL(SHO.BAIKA1,'') AS BAIKA10, NVL(SHO.BAIKA2,'') AS BAIKA20, NVL(SHO.BAIKA3,'') AS BAIKA30, NVL(KUMI.SHOHINCD,'') AS BUHINCD01, NVL(KUMI.SHOHINNM,'') AS SHOHINNM01, DECODE(T_KUMIHIN.KAZU01,0,NULL,T_KUMIHIN.KAZU01) AS KAZU, NVL(KUMI.BAIKA0,'') AS BAIKA01, NVL(KUMI.BAIKA1,'') AS BAIKA11, NVL(KUMI.BAIKA2,'') AS BAIKA21, NVL(KUMI.BAIKA3,'') AS BAIKA31 DECODE(T_KUMIHIN.RECFLG,'1','削除',' ') AS RECFLG FROM T_KUMIHIN, SHOHINMST SHO, SHOHINMST KUMI WHERE SHO.SHOHINCD (+) = T_KUMIHIN.SHOHINCD AND ( KUMI.SHOHINCD (+) = T_KUMIHIN.BUHINCD01 OR KUMI.SHOHINCD (+) = T_KUMIHIN.BUHINCD02 OR KUMI.SHOHINCD (+) = T_KUMIHIN.BUHINCD03 OR KUMI.SHOHINCD (+) = T_KUMIHIN.BUHINCD04 OR KUMI.SHOHINCD (+) = T_KUMIHIN.BUHINCD05 OR KUMI.SHOHINCD (+) = T_KUMIHIN.BUHINCD06 OR KUMI.SHOHINCD (+) = T_KUMIHIN.BUHINCD07 OR KUMI.SHOHINCD (+) = T_KUMIHIN.BUHINCD08 OR KUMI.SHOHINCD (+) = T_KUMIHIN.BUHINCD09 OR KUMI.SHOHINCD (+) = T_KUMIHIN.BUHINCD10 OR KUMI.SHOHINCD (+) = T_KUMIHIN.BUHINCD11 OR KUMI.SHOHINCD (+) = T_KUMIHIN.BUHINCD12 OR KUMI.SHOHINCD (+) = T_KUMIHIN.BUHINCD13 OR KUMI.SHOHINCD (+) = T_KUMIHIN.BUHINCD14 OR KUMI.SHOHINCD (+) = T_KUMIHIN.BUHINCD15 ) これもテストはしていないので、同様自己責任でお願いします。
- Mizyu
- ベストアンサー率41% (245/593)
やたら長いSQLですが、こんな感じでしょうか。 SELECT T_KUMIHIN.SHOHINCD, NVL(SHO.SHOHINNM,'') AS SHOHINNM00, NVL(SHO.BAIKA0,'') AS BAIKA00, NVL(SHO.BAIKA1,'') AS BAIKA10, NVL(SHO.BAIKA2,'') AS BAIKA20, NVL(SHO.BAIKA3,'') AS BAIKA30, NVL(KUMI.SHOHINCD,'') AS BUHINCD01, NVL(KUMI.SHOHINNM,'') AS SHOHINNM01, DECODE(T_KUMIHIN.KAZU01,0,NULL,T_KUMIHIN.KAZU01) AS KAZU, NVL(KUMI.BAIKA0,'') AS BAIKA01, NVL(KUMI.BAIKA1,'') AS BAIKA11, NVL(KUMI.BAIKA2,'') AS BAIKA21, NVL(KUMI.BAIKA3,'') AS BAIKA31 DECODE(T_KUMIHIN.RECFLG,'1','削除',' ') AS RECFLG FROM T_KUMIHIN, SHOHINMST SHO, SHOHINMST KUMI WHERE SHOHINMST.SHOHINCD (+) = T_KUMIHIN.SHOHINCD AND ( SHOHINMST.SHOHINCD (+) = T_KUMIHIN.BUHINCD01 OR SHOHINMST.SHOHINCD (+) = T_KUMIHIN.BUHINCD02 OR SHOHINMST.SHOHINCD (+) = T_KUMIHIN.BUHINCD03 OR SHOHINMST.SHOHINCD (+) = T_KUMIHIN.BUHINCD04 OR SHOHINMST.SHOHINCD (+) = T_KUMIHIN.BUHINCD05 OR SHOHINMST.SHOHINCD (+) = T_KUMIHIN.BUHINCD06 OR SHOHINMST.SHOHINCD (+) = T_KUMIHIN.BUHINCD07 OR SHOHINMST.SHOHINCD (+) = T_KUMIHIN.BUHINCD08 OR SHOHINMST.SHOHINCD (+) = T_KUMIHIN.BUHINCD09 OR SHOHINMST.SHOHINCD (+) = T_KUMIHIN.BUHINCD10 OR SHOHINMST.SHOHINCD (+) = T_KUMIHIN.BUHINCD11 OR SHOHINMST.SHOHINCD (+) = T_KUMIHIN.BUHINCD12 OR SHOHINMST.SHOHINCD (+) = T_KUMIHIN.BUHINCD13 OR SHOHINMST.SHOHINCD (+) = T_KUMIHIN.BUHINCD14 OR SHOHINMST.SHOHINCD (+) = T_KUMIHIN.BUHINCD15 ) テストしていないので自己責任でお願いします。
補足
大変ありがとうございます。 一応流してみたのですが下記の DECODE(T_KUMIHIN.KAZU01,0,NULL,T_KUMIHIN.KAZU01) AS KAZU, KAZU01の部分が一行に15項目あるのでこのままだとKAZU01の値しか取ってこれません。自分でも考えてみたのですが、ここが一番厄介なところかなと思っています。 T_KUMIHINマスタのレコードレイアウトを一応書きます。 SHOHINCD VARCHAR2(12) not NULL BUHINCD01 VARCHAR2(12) not NULL KAZU01 NUMBER(4,0) not NULL BUHINCD02 VARCHAR2(12) not NULL KAZU02 NUMBER(4,0) not NULL BUHINCD03 VARCHAR2(12) NULL KAZU03 NUMBER(4,0) NULL BUHINCD04 VARCHAR2(12) NULL KAZU04 NUMBER(4,0) NULL BUHINCD05 VARCHAR2(12) NULL KAZU05 NUMBER(4,0) NULL BUHINCD06 VARCHAR2(12) NULL KAZU06 NUMBER(4,0) NULL BUHINCD07 VARCHAR2(12) NULL KAZU07 NUMBER(4,0) NULL BUHINCD08 VARCHAR2(12) NULL KAZU08 NUMBER(4,0) NULL BUHINCD09 VARCHAR2(12) NULL KAZU09 NUMBER(4,0) NULL BUHINCD10 VARCHAR2(12) NULL KAZU10 NUMBER(4,0) NULL BUHINCD11 VARCHAR2(12) NULL KAZU11 NUMBER(4,0) NULL BUHINCD12 VARCHAR2(12) NULL KAZU12 NUMBER(4,0) NULL BUHINCD13 VARCHAR2(12) NULL KAZU13 NUMBER(4,0) NULL BUHINCD14 VARCHAR2(12) NULL KAZU14 NUMBER(4,0) NULL BUHINCD15 VARCHAR2(12) NULL KAZU15 NUMBER(4,0) NULL SAKUSEIYMD VARCHAR2(8) NULL SAKUSEISHACD VARCHAR2(3) NULL KOSINYMD VARCHAR2(8) NULL KOSINSYACD VARCHAR2(3) NULL RECFLG VARCHAR2(1) NULL PRIMARY KEY (SHOHINCD) SHOHINMSTのレコードレイアウト SHOHINCD VARCHAR2(12) not NULL SHOHINNM VARCHAR2(40) NULL MAKERCD VARCHAR2(15) NULL MAKERNM VARCHAR2(4) NULL BUNRUICD VARCHAR2(3) NULL ZAIKO1 NUMBER(4,0) NULL ZAIKO2 NUMBER(4,0) NULL ZAIKO3 NUMBER(4,0) NULL ZAIKO4 NUMBER(4,0) NULL ZAIKO5 NUMBER(4,0) NULL ZAIKO6 NUMBER(4,0) NULL ZAIKO1ZEN NUMBER(4,0) NULL ZAIKO2ZEN NUMBER(4,0) NULL ZAIKO3ZEN NUMBER(4,0) NULL ZAIKO4ZEN NUMBER(4,0) NULL ZAIKO5ZEN NUMBER(4,0) NULL ZAIKO6ZEN NUMBER(4,0) NULL CATALOGKBN VARCHAR2(1) NULL ZEIKBN VARCHAR2(1) NULL BAIKA0 NUMBER(7,0) NULL BAIKA1 NUMBER(7,0) NULL BAIKA2 NUMBER(7,0) NULL BAIKA3 NUMBER(7,0) NULL SIIREYMD VARCHAR2(8) NULL SIIRETANKA NUMBER(7,0) NULL ZEROKYOKA VARCHAR2(1) NULL SAKUSEIYMD VARCHAR2(8) NULL SAKUSEISHACD VARCHAR2(3) NULL KOSINYMD VARCHAR2(8) NULL KOSINSYACD VARCHAR2(3) NULL RECFLG VARCHAR2(1) NULL SERVICEKOMOKU VARCHAR2(2) NULL SKOMOKUSHUBETU VARCHAR2(2) NULL PRIMARY KEY (SHOHINCD) こんな感じです。 よろしくお願い致します
- Mizyu
- ベストアンサー率41% (245/593)
情報が少ないので回答が出せません。 少なくとも ・上記ビューを生成するSELECT文 ・テーブル構成(できればカラム名も) を記入してください。
補足
ビューのセレクト文です SELECT T_KUMIHIN.SHOHINCD, NVL(SHOHINMST00.SHOHINNM,'') AS SHOHINNM00, NVL(SHOHINMST00.BAIKA0,'') AS BAIKA00, NVL(SHOHINMST00.BAIKA1,'') AS BAIKA10, NVL(SHOHINMST00.BAIKA2,'') AS BAIKA20, NVL(SHOHINMST00.BAIKA3,'') AS BAIKA30, NVL(SHOHINMST01.SHOHINCD,'') AS BUHINCD01, NVL(SHOHINMST01.SHOHINNM,'') AS SHOHINNM01, DECODE(T_KUMIHIN.KAZU01,0,NULL,T_KUMIHIN.KAZU01) AS KAZU01, NVL(SHOHINMST01.BAIKA0,'') AS BAIKA01, NVL(SHOHINMST01.BAIKA1,'') AS BAIKA11, NVL(SHOHINMST01.BAIKA2,'') AS BAIKA21, NVL(SHOHINMST01.BAIKA3,'') AS BAIKA31, NVL(SHOHINMST02.SHOHINCD,'') AS BUHINCD02, NVL(SHOHINMST02.SHOHINNM,'') AS SHOHINNM02, DECODE(T_KUMIHIN.KAZU02,0,NULL,T_KUMIHIN.KAZU02) AS KAZU02, NVL(SHOHINMST02.BAIKA0,'') AS BAIKA02, NVL(SHOHINMST02.BAIKA1,'') AS BAIKA12, NVL(SHOHINMST02.BAIKA2,'') AS BAIKA22, NVL(SHOHINMST02.BAIKA3,'') AS BAIKA32, NVL(SHOHINMST03.SHOHINCD,'') AS BUHINCD03, NVL(SHOHINMST03.SHOHINNM,'') AS SHOHINNM03, DECODE(T_KUMIHIN.KAZU03,0,NULL,T_KUMIHIN.KAZU03) AS KAZU03, NVL(SHOHINMST03.BAIKA0,'') AS BAIKA03, NVL(SHOHINMST03.BAIKA1,'') AS BAIKA13, NVL(SHOHINMST03.BAIKA2,'') AS BAIKA23, NVL(SHOHINMST03.BAIKA3,'') AS BAIKA33, NVL(SHOHINMST04.SHOHINCD,'') AS BUHINCD04, NVL(SHOHINMST04.SHOHINNM,'') AS SHOHINNM04, DECODE(T_KUMIHIN.KAZU04,0,NULL,T_KUMIHIN.KAZU04) AS KAZU04, NVL(SHOHINMST04.BAIKA0,'') AS BAIKA04, NVL(SHOHINMST04.BAIKA1,'') AS BAIKA14, NVL(SHOHINMST04.BAIKA2,'') AS BAIKA24, NVL(SHOHINMST04.BAIKA3,'') AS BAIKA34, NVL(SHOHINMST05.SHOHINCD,'') AS BUHINCD05, NVL(SHOHINMST05.SHOHINNM,'') AS SHOHINNM05, DECODE(T_KUMIHIN.KAZU05,0,NULL,T_KUMIHIN.KAZU05) AS KAZU05, NVL(SHOHINMST05.BAIKA0,'') AS BAIKA05, NVL(SHOHINMST05.BAIKA1,'') AS BAIKA15, NVL(SHOHINMST05.BAIKA2,'') AS BAIKA25, NVL(SHOHINMST05.BAIKA3,'') AS BAIKA35, NVL(SHOHINMST06.SHOHINCD,'') AS BUHINCD06, NVL(SHOHINMST06.SHOHINNM,'') AS SHOHINNM06, DECODE(T_KUMIHIN.KAZU06,0,NULL,T_KUMIHIN.KAZU06) AS KAZU06, NVL(SHOHINMST06.BAIKA0,'') AS BAIKA06, NVL(SHOHINMST06.BAIKA1,'') AS BAIKA16, NVL(SHOHINMST06.BAIKA2,'') AS BAIKA26, NVL(SHOHINMST06.BAIKA3,'') AS BAIKA36, NVL(SHOHINMST07.SHOHINCD,'') AS BUHINCD07, NVL(SHOHINMST07.SHOHINNM,'') AS SHOHINNM07, DECODE(T_KUMIHIN.KAZU07,0,NULL,T_KUMIHIN.KAZU07) AS KAZU07, NVL(SHOHINMST07.BAIKA0,'') AS BAIKA07, NVL(SHOHINMST07.BAIKA1,'') AS BAIKA17, NVL(SHOHINMST07.BAIKA2,'') AS BAIKA27, NVL(SHOHINMST07.BAIKA3,'') AS BAIKA37, NVL(SHOHINMST08.SHOHINCD,'') AS BUHINCD08, NVL(SHOHINMST08.SHOHINNM,'') AS SHOHINNM08, DECODE(T_KUMIHIN.KAZU08,0,NULL,T_KUMIHIN.KAZU08) AS KAZU08, NVL(SHOHINMST08.BAIKA0,'') AS BAIKA08, NVL(SHOHINMST08.BAIKA1,'') AS BAIKA18, NVL(SHOHINMST08.BAIKA2,'') AS BAIKA28, NVL(SHOHINMST08.BAIKA3,'') AS BAIKA38, NVL(SHOHINMST09.SHOHINCD,'') AS BUHINCD09, NVL(SHOHINMST09.SHOHINNM,'') AS SHOHINNM09, DECODE(T_KUMIHIN.KAZU09,0,NULL,T_KUMIHIN.KAZU09) AS KAZU09, NVL(SHOHINMST09.BAIKA0,'') AS BAIKA09, NVL(SHOHINMST09.BAIKA1,'') AS BAIKA19, NVL(SHOHINMST09.BAIKA2,'') AS BAIKA29, NVL(SHOHINMST09.BAIKA3,'') AS BAIKA39, NVL(SHOHINMST10.SHOHINCD,'') AS BUHINCD10, NVL(SHOHINMST10.SHOHINNM,'') AS SHOHINNM10, DECODE(T_KUMIHIN.KAZU10,0,NULL,T_KUMIHIN.KAZU10) AS KAZU10, NVL(SHOHINMST10.BAIKA0,'') AS BAIKA010, NVL(SHOHINMST10.BAIKA1,'') AS BAIKA110, NVL(SHOHINMST10.BAIKA2,'') AS BAIKA210, NVL(SHOHINMST10.BAIKA3,'') AS BAIKA310, NVL(SHOHINMST11.SHOHINCD,'') AS BUHINCD11, NVL(SHOHINMST11.SHOHINNM,'') AS SHOHINNM11, DECODE(T_KUMIHIN.KAZU11,0,NULL,T_KUMIHIN.KAZU11) AS KAZU11, NVL(SHOHINMST11.BAIKA0,'') AS BAIKA011, NVL(SHOHINMST11.BAIKA1,'') AS BAIKA111, NVL(SHOHINMST11.BAIKA2,'') AS BAIKA211, NVL(SHOHINMST11.BAIKA3,'') AS BAIKA311, NVL(SHOHINMST12.SHOHINCD,'') AS BUHINCD12, NVL(SHOHINMST12.SHOHINNM,'') AS SHOHINNM12, DECODE(T_KUMIHIN.KAZU12,0,NULL,T_KUMIHIN.KAZU12) AS KAZU12, NVL(SHOHINMST12.BAIKA0,'') AS BAIKA012, NVL(SHOHINMST12.BAIKA1,'') AS BAIKA112, NVL(SHOHINMST12.BAIKA2,'') AS BAIKA212, NVL(SHOHINMST12.BAIKA3,'') AS BAIKA312, NVL(SHOHINMST13.SHOHINCD,'') AS BUHINCD13, NVL(SHOHINMST13.SHOHINNM,'') AS SHOHINNM13, DECODE(T_KUMIHIN.KAZU13,0,NULL,T_KUMIHIN.KAZU13) AS KAZU13, NVL(SHOHINMST13.BAIKA0,'') AS BAIKA013, NVL(SHOHINMST13.BAIKA1,'') AS BAIKA113, NVL(SHOHINMST13.BAIKA2,'') AS BAIKA213, NVL(SHOHINMST13.BAIKA3,'') AS BAIKA313, NVL(SHOHINMST14.SHOHINCD,'') AS BUHINCD14, NVL(SHOHINMST14.SHOHINNM,'') AS SHOHINNM14, DECODE(T_KUMIHIN.KAZU14,0,NULL,T_KUMIHIN.KAZU14) AS KAZU14, NVL(SHOHINMST14.BAIKA0,'') AS BAIKA014, NVL(SHOHINMST14.BAIKA1,'') AS BAIKA114, NVL(SHOHINMST14.BAIKA2,'') AS BAIKA214, NVL(SHOHINMST14.BAIKA3,'') AS BAIKA314, NVL(SHOHINMST15.SHOHINCD,'') AS BUHINCD15, NVL(SHOHINMST15.SHOHINNM,'') AS SHOHINNM15, DECODE(T_KUMIHIN.KAZU15,0,NULL,T_KUMIHIN.KAZU15) AS KAZU15, NVL(SHOHINMST15.BAIKA0,'') AS BAIKA015, NVL(SHOHINMST15.BAIKA1,'') AS BAIKA115, NVL(SHOHINMST15.BAIKA2,'') AS BAIKA215, NVL(SHOHINMST15.BAIKA3,'') AS BAIKA315, DECODE(T_KUMIHIN.RECFLG,'1','削除',' ') AS RECFLG FROM T_KUMIHIN, SHOHINMST SHOHINMST00, SHOHINMST SHOHINMST01, SHOHINMST SHOHINMST02, SHOHINMST SHOHINMST03, SHOHINMST SHOHINMST04, SHOHINMST SHOHINMST05, SHOHINMST SHOHINMST06, SHOHINMST SHOHINMST07, SHOHINMST SHOHINMST08, SHOHINMST SHOHINMST09, SHOHINMST SHOHINMST10, SHOHINMST SHOHINMST11, SHOHINMST SHOHINMST12, SHOHINMST SHOHINMST13, SHOHINMST SHOHINMST14, SHOHINMST SHOHINMST15 WHERE SHOHINMST00.SHOHINCD (+) = T_KUMIHIN.SHOHINCD AND SHOHINMST01.SHOHINCD (+) = T_KUMIHIN.BUHINCD01 AND SHOHINMST02.SHOHINCD (+) = T_KUMIHIN.BUHINCD02 AND SHOHINMST03.SHOHINCD (+) = T_KUMIHIN.BUHINCD03 AND SHOHINMST04.SHOHINCD (+) = T_KUMIHIN.BUHINCD04 AND SHOHINMST05.SHOHINCD (+) = T_KUMIHIN.BUHINCD05 AND SHOHINMST06.SHOHINCD (+) = T_KUMIHIN.BUHINCD06 AND SHOHINMST07.SHOHINCD (+) = T_KUMIHIN.BUHINCD07 AND SHOHINMST08.SHOHINCD (+) = T_KUMIHIN.BUHINCD08 AND SHOHINMST09.SHOHINCD (+) = T_KUMIHIN.BUHINCD09 AND SHOHINMST10.SHOHINCD (+) = T_KUMIHIN.BUHINCD10 AND SHOHINMST11.SHOHINCD (+) = T_KUMIHIN.BUHINCD11 AND SHOHINMST12.SHOHINCD (+) = T_KUMIHIN.BUHINCD12 AND SHOHINMST13.SHOHINCD (+) = T_KUMIHIN.BUHINCD13 AND SHOHINMST14.SHOHINCD (+) = T_KUMIHIN.BUHINCD14 AND SHOHINMST15.SHOHINCD (+) = T_KUMIHIN.BUHINCD15
お礼
何度もありがとうございました。 とりあえず本などを読みあさりUNIONを使ってできました。 こんな感じです! CREATE VIEW VKAIF20 AS SELECT SHOHINMST0.SHOHINCD, NVL(SHOHINMST0.SHOHINNM,'') AS SHOHINNM, NVL(SHOHINMST0.BAIKA0,'') AS BAIKA00, NVL(SHOHINMST0.BAIKA1,'') AS BAIKA10, NVL(SHOHINMST0.BAIKA2,'') AS BAIKA20, NVL(SHOHINMST0.BAIKA3,'') AS BAIKA30, '01' AS GYO, NVL(T_KUMIHIN.BUHINCD01,'') AS BUHINCD, NVL(SHOHINMST1.SHOHINNM,'') AS BUHINNM, DECODE(T_KUMIHIN.KAZU01,0,NULL,T_KUMIHIN.KAZU01) AS KAZU, NVL(SHOHINMST1.BAIKA0,'') AS BAIKA01, NVL(SHOHINMST1.BAIKA1,'') AS BAIKA11, NVL(SHOHINMST1.BAIKA2,'') AS BAIKA21, NVL(SHOHINMST1.BAIKA3,'') AS BAIKA31, DECODE(T_KUMIHIN.RECFLG,'1','削除',' ') AS RECFLG FROM T_KUMIHIN, SHOHINMST SHOHINMST0, SHOHINMST SHOHINMST1 WHERE SHOHINMST0.SHOHINCD = T_KUMIHIN.SHOHINCD AND SHOHINMST1.SHOHINCD = T_KUMIHIN.BUHINCD01 UNION SELECT SHOHINMST0.SHOHINCD, NVL(SHOHINMST0.SHOHINNM,'') AS SHOHINNM, NVL(SHOHINMST0.BAIKA0,'') AS BAIKA00, NVL(SHOHINMST0.BAIKA1,'') AS BAIKA10, NVL(SHOHINMST0.BAIKA2,'') AS BAIKA20, NVL(SHOHINMST0.BAIKA3,'') AS BAIKA30, '02' AS GYO, NVL(T_KUMIHIN.BUHINCD02,'') AS BUHINCD, NVL(SHOHINMST1.SHOHINNM,'') AS BUHINNM, DECODE(T_KUMIHIN.KAZU02,0,NULL,T_KUMIHIN.KAZU02) AS KAZU, NVL(SHOHINMST1.BAIKA0,'') AS BAIKA01, NVL(SHOHINMST1.BAIKA1,'') AS BAIKA11, NVL(SHOHINMST1.BAIKA2,'') AS BAIKA21, NVL(SHOHINMST1.BAIKA3,'') AS BAIKA31, DECODE(T_KUMIHIN.RECFLG,'1','削除',' ') AS RECFLG FROM T_KUMIHIN, SHOHINMST SHOHINMST0, SHOHINMST SHOHINMST1 WHERE SHOHINMST0.SHOHINCD = T_KUMIHIN.SHOHINCD AND SHOHINMST1.SHOHINCD = T_KUMIHIN.BUHINCD02 ~省略~ UNION SELECT SHOHINMST0.SHOHINCD, NVL(SHOHINMST0.SHOHINNM,'') AS SHOHINNM, NVL(SHOHINMST0.BAIKA0,'') AS BAIKA00, NVL(SHOHINMST0.BAIKA1,'') AS BAIKA10, NVL(SHOHINMST0.BAIKA2,'') AS BAIKA20, NVL(SHOHINMST0.BAIKA3,'') AS BAIKA30, '15' AS GYO, NVL(T_KUMIHIN.BUHINCD15,'') AS BUHINCD, NVL(SHOHINMST1.SHOHINNM,'') AS BUHINNM, DECODE(T_KUMIHIN.KAZU15,0,NULL,T_KUMIHIN.KAZU15) AS KAZU, NVL(SHOHINMST1.BAIKA0,'') AS BAIKA01, NVL(SHOHINMST1.BAIKA1,'') AS BAIKA11, NVL(SHOHINMST1.BAIKA2,'') AS BAIKA21, NVL(SHOHINMST1.BAIKA3,'') AS BAIKA31, DECODE(T_KUMIHIN.RECFLG,'1','削除',' ') AS RECFLG FROM T_KUMIHIN, SHOHINMST SHOHINMST0, SHOHINMST SHOHINMST1 WHERE SHOHINMST0.SHOHINCD = T_KUMIHIN.SHOHINCD AND SHOHINMST1.SHOHINCD = T_KUMIHIN.BUHINCD15 WITH READ ONLY 難しいですね!SQLって 又、困った時はお願いします。