質問編集履歴
1
しゅうs
test
CHANGED
File without changes
|
test
CHANGED
@@ -33,3 +33,45 @@
|
|
33
33
|
`create procedure loop_insert(in x int, in y int, in z string)`のような形で引数を取り`insert into db.m_table`の部分を`insert into z`のような形でdb名.テーブル名のようにテーブル名を与えたいのですがどうすればよいでしょうか。
|
34
34
|
|
35
35
|
宜しくお願い致します。
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
___
|
40
|
+
|
41
|
+
#### 変更後
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
```ここに言語を入力
|
46
|
+
|
47
|
+
delimiter //
|
48
|
+
|
49
|
+
create procedure loop_insert_data(in x int, in y int, in z varchar(60))
|
50
|
+
|
51
|
+
begin
|
52
|
+
|
53
|
+
declare max_id int;
|
54
|
+
|
55
|
+
declare i int;
|
56
|
+
|
57
|
+
declare tablename varchar(60);
|
58
|
+
|
59
|
+
set i = 0;
|
60
|
+
|
61
|
+
set max_id = y;
|
62
|
+
|
63
|
+
set @tablename = z;
|
64
|
+
|
65
|
+
while i < x do
|
66
|
+
|
67
|
+
set i = i + 1;
|
68
|
+
|
69
|
+
insert into tablename(ProductID, LastUpdatedBy)
|
70
|
+
|
71
|
+
values(max_id + i , '2068');
|
72
|
+
|
73
|
+
end while;
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
```
|