如:
cursor c_columns(t_table_name varchar) is select column_name from user_tab_columns where table_name = t_table_name order by table_name,column_id;
v_txt1:='';
for v_col in c_columns(v_tablename) loop --使用for循环 遍历游标内容 (for简单)
v_column := v_col.column_name;
if v_column = 'STATDATE' THEN
v_txt1:=v_txt1||' ''20161130'' as '||v_column;
else
v_txt1:=v_txt1||','||v_column;
end if;
end loop;
游标中有ORDER BY,是按排序后的顺序读取
不加order by 就按默认排序,最好加order by,至于ordey by随机看你的字段唯一性了,一般是加个主键来排序的。