質問編集履歴

3

書式を修正しました。

2021/01/08 04:46

投稿

Qingxuan
Qingxuan

スコア7

test CHANGED
File without changes
test CHANGED
@@ -92,15 +92,15 @@
92
92
 
93
93
  RETURN NUMBER
94
94
 
95
- IS
95
+ IS
96
96
 
97
- total NUMBER;
97
+ total NUMBER;
98
98
 
99
- BEGIN
99
+ BEGIN
100
100
 
101
- SELECT SUM (col3) INTO total from test6 group by col1 having col1 =f_col1 ;
101
+ SELECT SUM (col3) INTO total from test6 group by col1 having col1 =f_col1 ;
102
102
 
103
- RETURN total;
103
+ RETURN total;
104
104
 
105
105
  END sumfunction;
106
106
 
@@ -114,17 +114,17 @@
114
114
 
115
115
  BEGIN
116
116
 
117
- FOR v_table IN
117
+ FOR v_table IN
118
118
 
119
- (SELECT * from test6)
119
+ (SELECT * from test6)
120
120
 
121
121
  LOOP
122
122
 
123
- DBMS_OUTPUT.PUT_LINE(v_table.col1||' '|| v_table.col2||
123
+ DBMS_OUTPUT.PUT_LINE(v_table.col1||' '|| v_table.col2||
124
124
 
125
125
             ' '||v_table.col3);
126
126
 
127
- DBMS_OUTPUT.PUT_LINE('合計 '||sumfunction(v_table.col1));
127
+ DBMS_OUTPUT.PUT_LINE('合計 '||sumfunction(v_table.col1));
128
128
 
129
129
  END LOOP;
130
130
 
@@ -146,29 +146,31 @@
146
146
 
147
147
  試しにネストしてみたのですが、イメージと結構違っています。
148
148
 
149
+ ```ここに言語を入力
150
+
149
151
  FOR v_table IN
150
152
 
151
- (SELECT * from test6)
153
+ (SELECT * from test6)
152
154
 
153
155
  LOOP
154
156
 
155
- FOR v_cnt IN 1..2 LOOP
157
+ FOR v_cnt IN 1..2 LOOP
156
158
 
157
- DBMS_OUTPUT.PUT_LINE(v_table.col1||' '|| v_table.col2||
159
+ DBMS_OUTPUT.PUT_LINE(v_table.col1||' '|| v_table.col2||
158
160
 
159
- ' '||v_table.col3);
161
+ ' '||v_table.col3);
160
162
 
161
- END LOOP;
163
+ END LOOP;
162
164
 
163
- DBMS_OUTPUT.PUT_LINE('合計 '||sumfunction(v_table.col1));
165
+ DBMS_OUTPUT.PUT_LINE('合計 '||sumfunction(v_table.col1));
164
166
 
165
167
  END LOOP;
166
168
 
167
- END;
168
-
169
- /
170
169
 
171
170
 
171
+
172
+
173
+ ```
172
174
 
173
175
  ループをネストか、それともブロックをネストか、ぜひ助言をお願いします。
174
176
 

2

col3 をNUMBER型に修正しました

2021/01/08 04:45

投稿

Qingxuan
Qingxuan

スコア7

test CHANGED
File without changes
test CHANGED
@@ -64,23 +64,23 @@
64
64
 
65
65
  --create table
66
66
 
67
- CREATE TABLE test6 (col1 VARCHAR2(10),col2 VARCHAR2(10), col3 VARCHAR2(10));
67
+ CREATE TABLE test6 (col1 VARCHAR2(10),col2 VARCHAR2(10), col3 NUMBER);
68
68
 
69
69
 
70
70
 
71
- INSERT INTO test6 VALUES('AAAAA','ああああ','1000');
71
+ INSERT INTO test6 VALUES('AAAAA','ああああ',1000);
72
72
 
73
- INSERT INTO test6 VALUES('AAAAA','いいいい','2000');
73
+ INSERT INTO test6 VALUES('AAAAA','いいいい',2000);
74
74
 
75
- INSERT INTO test6 VALUES('BBBBB','ああああ','1500');
75
+ INSERT INTO test6 VALUES('BBBBB','ああああ',1500);
76
76
 
77
- INSERT INTO test6 VALUES('BBBBB','いいいい','4000');
77
+ INSERT INTO test6 VALUES('BBBBB','いいいい',4000);
78
78
 
79
- INSERT INTO test6 VALUES('BBBBB','うううう','3000');
79
+ INSERT INTO test6 VALUES('BBBBB','うううう',3000);
80
80
 
81
- INSERT INTO test6 VALUES('CCCCC','ああああ','1400');
81
+ INSERT INTO test6 VALUES('CCCCC','ああああ',1400);
82
82
 
83
- INSERT INTO test6 VALUES('CCCCC','うううう','1500');
83
+ INSERT INTO test6 VALUES('CCCCC','うううう',1500);
84
84
 
85
85
 
86
86
 

1

create tableのソースを追加しました

2021/01/08 04:41

投稿

Qingxuan
Qingxuan

スコア7

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,8 @@
1
1
  ### 前提・実現したいこと
2
2
 
3
3
  テーブルは以下の感じです。
4
+
5
+
4
6
 
5
7
  test6
6
8
 
@@ -59,6 +61,28 @@
59
61
 
60
62
 
61
63
  ```
64
+
65
+ --create table
66
+
67
+ CREATE TABLE test6 (col1 VARCHAR2(10),col2 VARCHAR2(10), col3 VARCHAR2(10));
68
+
69
+
70
+
71
+ INSERT INTO test6 VALUES('AAAAA','ああああ','1000');
72
+
73
+ INSERT INTO test6 VALUES('AAAAA','いいいい','2000');
74
+
75
+ INSERT INTO test6 VALUES('BBBBB','ああああ','1500');
76
+
77
+ INSERT INTO test6 VALUES('BBBBB','いいいい','4000');
78
+
79
+ INSERT INTO test6 VALUES('BBBBB','うううう','3000');
80
+
81
+ INSERT INTO test6 VALUES('CCCCC','ああああ','1400');
82
+
83
+ INSERT INTO test6 VALUES('CCCCC','うううう','1500');
84
+
85
+
62
86
 
63
87
  --合計を求めるFUNCTION
64
88