Oracle uses cursors to query all datasheet notes __oracle

Source: Internet
Author: User

Function: The application of the corresponding SQL statements, can be convenient and quick query Oracle database specified users of all user table description, quickly know what each data table is to do, easy to write documents and programs.

Operating Environment: Build Oracle Database and use the Pq/sql developer software and the specified database account password to connect to the database you are querying.

Detailed contents are as follows:

1, the use of SQL query script is as follows:---------------------------------------------------------------------------------------------- -----------------
--oracle use cursors to query all datasheet comments

Declare
Mytablename NVARCHAR2 (200): = '; --Define the data table name variable to query
Mytablecomment NVARCHAR2 (200): = '; --Define the datasheet annotation variable to query
Commentsql VARCHAR2 (2000): = '; --Define the annotation result variable to output
Cursor MyCursor1 is select * to User_tab_comments ORDER by table_name;--define Cursors

Myrecord1 Mycursor1%rowtype; --Define Cursor record type


Begin
Open MyCursor1; --Open cursor
If Mycursor1%isopen then--judgment opened successfully
Loop--Looping to get recordsets
Fetch MyCursor1 into myrecord1;

If Mycursor1%found then--the found property of the cursor determines whether there is a record
Begin

Mytablename:=myrecord1.table_name;
mytablecomment:=myrecord1.comments;

--commentsql:= ' table name ' | |    mytablename| | ' Comments as ' | | Mytablecomment;
commentsql:=mytablename| | ' '|| Mytablecomment;
Dbms_output.put_line (Commentsql);

End

Else
Exit --Get the records in the cursor

End If;


End Loop;
Else
Dbms_output.put_line (' Cursors not open ');
End If;


Close MyCursor1;

End

---------------------------------------------------------------------------------------------------------------


2, Pl/sql Developer in the operation of a: Copy the above query script to the "SQL" tab, and execute the query, screenshot as follows:



3, Pl/sql developer Operation Two: switch to the "Output" tab, view the results, screenshot as follows:


---------------------------------------------------------------------------------------------------------------

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.