Solved

How to use Oracle  PL/SQL to Comment a Table Or column

Posted on 2014-10-02
6
1,330 Views
Last Modified: 2014-10-02
Our database is uncommented. I would like to embed table and column comments.

What is the syntax?

is it something like ALTER Table MyTable comment = "my table comment" ?

is it something like ALTER Table MyTable, Column MyColumn comment = "my column comment" ?

Thanks,
0
Comment
Question by:Dovberman
6 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 400 total points
ID: 40356989
PL/SQL is the procedural language.

What you want is regular SQL.

The online docs have everything you need:
http://docs.oracle.com/cd/E11882_01/server.112/e41084/statements_4009.htm#i2119719

COMMENT ON COLUMN employees.job_id
   IS 'abbreviated job title';

The TABLE one is the same:
COMMENT ON TABLE employees
   IS 'some table comment';
0
 
LVL 15

Assisted Solution

by:Devinder Singh Virdi
Devinder Singh Virdi earned 100 total points
ID: 40357466
From PL/SQL, you need to use
execute immediate '.... DDL Command...'

Ex.
begin
  execute immediate 'comment on table temp_dev is ''This is Temp''';
end;
/
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40357481
Don't use PL/SQL to do this.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 73

Expert Comment

by:sdstuber
ID: 40358103
I see you've opened a similar question in another thread.  Here's the same code I posted there.

You can/should delete that other thread now

CREATE OR REPLACE PROCEDURE set_comment(
    p_owner     IN VARCHAR2,
    p_table     IN VARCHAR2,
    p_comment   IN VARCHAR2
)
IS
BEGIN
    EXECUTE IMMEDIATE
        'comment on table "' || p_owner || '"."' || p_table || '" is ''' || p_comment || '''';
END;

You might note I'm putting double quotes around the owner and table name.
That's to support mixed-cased object names and names with non-standard characters.

It's generally considered bad practice to have such names, but it's a good idea to support them.   If you don't need that you can either remove the double-quotes, or call the procedure with upper case names,  or wrap the parameters in UPPER() function in the concatenation
0
 

Author Closing Comment

by:Dovberman
ID: 40358104
That helps.  Thanks,
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 40358126
looks like I was too late here on my cross post.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now