Operation Procedure: Open PLSQLDeveloper and execute the following statement to obtain the string declaremytablenameVARCHAR (255): STAFFDOC corresponding to all field names of the specified data table using a cursor in Oracle; -- defines the variable of the name of the data table to be queried. STAFFDOC is the name of the data table used for my test. Please change it to your data
Procedure: Open PLSQL Developer and execute the following statement to obtain the string declare mytablename VARCHAR (255) corresponding to all field names of the specified data table using a cursor in Oracle ): = 'staffdoc '; -- defines the variable of the name of the data table to be queried. STAFFDOC is the name of the data table used for testing. Please change it to your data
Procedure: Open PLSQL Developer and execute the following statement.
-- Use a cursor in Oracle to obtain the string corresponding to all field names of a specified data table
Declare
Mytablename VARCHAR (255): = 'staffdoc '; -- defines the name variable of the data table to be queried. STAFFDOC is the name of the data table used for my test. Change it to the name of the corresponding data table in your database.
Mystring NVARCHAR2 (4000): = ''; -- defines the string variable to be output
Cursor mycursor is -- defines the cursor
Select * from all_tab_columns where TABLE_NAME = mytablename order by column_id;
Myrecord mycursor % rowtype; -- defines the cursor record type
Counter int: = 0;
Begin
Open mycursor; -- open the cursor
If mycursor % isopen then -- determines whether the open is successful
Loop -- Obtain Record Sets cyclically
Fetch mycursor into myrecord; -- get records in the cursor
If mycursor % found then -- the cursor's found attribute determines whether a record exists
Begin
If length (mystring)> 0 then
Mystring: = mystring | ',' | myrecord. column_name;
Else
Mystring: = myrecord. column_name;
End if;
End;
Else
Exit;
End if;
End loop;
Else
Dbms_output.put_line ('cursor not opened ');
End if;
Dbms_output.put_line (mystring );
Close mycursor;
End;