質問編集履歴
1
パターンCを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,7 +18,7 @@
|
|
18
18
|
|
19
19
|
|
20
20
|
|
21
|
-
この場合に思いつく方法は
|
21
|
+
この場合に思いつく方法は3パターンあるのですが、出来る事ならAパターンのように計算式をSALARY列に書くのは手間・不具合を招きそうですし、Bパターンだと更新処理を2回走らせるのでコスト増と考えています。パターンCは書く量が多くなりますが、やりたい事は満たせています。
|
22
22
|
|
23
23
|
|
24
24
|
|
@@ -134,6 +134,116 @@
|
|
134
134
|
|
135
135
|
|
136
136
|
|
137
|
+
-- <<パターンC>>
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
DECLARE
|
142
|
+
|
143
|
+
CURSOR C_SALARY IS
|
144
|
+
|
145
|
+
SELECT *
|
146
|
+
|
147
|
+
FROM TBL_SALARY
|
148
|
+
|
149
|
+
;
|
150
|
+
|
151
|
+
TYPE TY_SALARY IS TABLE OF TBL_SALARY%ROWTYPE ;
|
152
|
+
|
153
|
+
RC_SALARY TY_SALARY;
|
154
|
+
|
155
|
+
WK_PRICE TBL_SALARY.PRICE%TYPE;
|
156
|
+
|
157
|
+
WK_TIME TBL_SALARY.TIME%TYPE;
|
158
|
+
|
159
|
+
WK_SALARY TBL_SALARY.SALARY%TYPE;
|
160
|
+
|
161
|
+
BEGIN
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
OPEN C_SALARY;
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
LOOP
|
170
|
+
|
171
|
+
FETCH C_SALARY BULK COLLECT INTO RC_SALARY LIMIT 1000;
|
172
|
+
|
173
|
+
EXIT WHEN RC_SALARY.COUNT = 0;
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
FOR i IN 1..RC_SALARY.COUNT LOOP
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
IF (RC_SALARY(i).HIRE_DATE <= 20051299) THEN
|
182
|
+
|
183
|
+
WK_PRICE := 800;
|
184
|
+
|
185
|
+
ELSE
|
186
|
+
|
187
|
+
WK_PRICE := 750;
|
188
|
+
|
189
|
+
END IF;
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
WK_TIME := 90;
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
WK_SALARY := WK_PRICE * WK_TIME;
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
UPDATE TBL_SALARY TBL
|
202
|
+
|
203
|
+
SET
|
204
|
+
|
205
|
+
PRICE = WK_PRICE
|
206
|
+
|
207
|
+
,TIME = WK_TIME
|
208
|
+
|
209
|
+
,SALARY = WK_SALARY
|
210
|
+
|
211
|
+
WHERE TBL.EMP_ID = RC_SALARY(i).EMP_ID
|
212
|
+
|
213
|
+
;
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
END LOOP;
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
END LOOP;
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
CLOSE C_SALARY;
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
DBMS_OUTPUT.PUT_LINE('COMMIT');
|
230
|
+
|
231
|
+
COMMIT;
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
EXCEPTION
|
236
|
+
|
237
|
+
WHEN OTHERS THEN
|
238
|
+
|
239
|
+
DBMS_OUTPUT.PUT_LINE(SQLERRM);
|
240
|
+
|
241
|
+
ROLLBACK;
|
242
|
+
|
243
|
+
END;
|
244
|
+
|
245
|
+
/
|
246
|
+
|
137
247
|
|
138
248
|
|
139
249
|
|