Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2849
  • Last Modified:

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

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
Dovberman
Asked:
Dovberman
2 Solutions
 
slightwv (䄆 Netminder) Commented:
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
 
Devinder Singh VirdiLead Oracle DBA TeamCommented:
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
 
slightwv (䄆 Netminder) Commented:
Don't use PL/SQL to do this.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
sdstuberCommented:
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
 
DovbermanAuthor Commented:
That helps.  Thanks,
0
 
sdstuberCommented:
looks like I was too late here on my cross post.
0

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now