1DECLARE col_names CURSOR FOR
2 SELECT column_name
3 FROM INFORMATION_SCHEMA.COLUMNS
4 WHERE table_name = 'tbl_name'
5 ORDER BY ordinal_position;
6
7
8select FOUND_ROWS() into num_rows;
9
10SET i = 1;
11the_loop: LOOP
12
13 IF i > num_rows THEN
14 CLOSE col_names;
15 LEAVE the_loop;
16 END IF;
17
18
19 FETCH col_names
20 INTO col_name;
21
22 //do whatever else you need to do with the col name
23
24 SET i = i + 1;
25END LOOP the_loop;