Oracle uses a cursor to query a string that combines the names of all fields in a specified data table.
Application Scenario: refer to the Code for querying all field names of a data table on the Internet, and use a cursor to generate a list of field names separated by select commas (,) consisting of all field names and commas (,) of a specified table.
The query result is output as follows:
The field list string of the current data table TB_UD_USER is
The detailed script code is as follows:
Declare
Cursor mycursor is -- defines the cursor
Select distinct TABLE_COLUMN. *, TABLE_NALLABLE.DATA_TYPE, TABLE_NALLABLE.NULLABLE from (select distinct utc. table_name, utc. comments table_comments, ucc. column_name, ucc. comments column_comments from user_tab_comments utc, user_col_comments ucc where utc. table_name = ucc. table_name and utc. table_name not like '% _ B' and utc. table_name not like '% _ Z' and utc. table_name not like '% 1%') TABLE_COLUMN, (select distinct table_name, column_name, nullable, DATA_TYPE from user_tab_cols where table_name not like '% _ B' and table_name not like '% _ Z' and table_name not like' % 100 ') TABLE_NALLABLE where TABLE_COLUMN.column_name = tables and TABLE_COLUMN.TABLE_NAME = TABLE_NALLABLE.table_name and TABLE_COLUMN.TABLE_NAME = mytablename order by TABLE_COLUMN.TABLE_NAME, TABLE_COLUMN.column_name;
If mycursor % found then -- the cursor's found attribute determines whether a record exists
End;
Else
Begin
Selstring: = 'select' | mystring | 'from' | mytablename;
Dbms_output.put_line ('current data table '| mytablename | 'Statement for querying all records is ');
Exit;
End;
End if;
Close mycursor;
End;