Solved

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

Posted on 2014-10-02
6
1,548 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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Encryption Decryption in Oracle 12 122
EXECUTE IMMEDIATE 5 73
Error executing command from server 6 52
PL/SQL More than one element associated with another element 7 27
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

803 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