Solved

Execute a PL/SQL Database Modification function

Posted on 2014-10-02
5
244 Views
Last Modified: 2014-10-02
I know that
COMMENT on table EMPLOYEE is 'This is the employee table';
will embed a table comment.  

How can this be executed in a function or stored procedure?

Thanks,
0
Comment
Question by:Dovberman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 200 total points
ID: 40358052
This was answered in your other question:
http://www.experts-exchange.com/Database/Oracle/Q_28529930.html#a40357466

I suggested there that DDL inside Pl/SQL is typically frowned upon.

Why do you want to perform DDL that should only be executed once inside a procedure?
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 300 total points
ID: 40358058
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;
0
 

Author Comment

by:Dovberman
ID: 40358146
There are no table or column comments at my current workplace.  I will create a form that populates table names in a list box.   The user selects a table. Then the selected table's columns are listed. A textbox accepts a comment entry. The save button triggers the action to add or update the comment.

I am new to Oracle and needed to know the best technique to use.

Thanks
0
 

Author Closing Comment

by:Dovberman
ID: 40358156
Thanks,
0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40358273
>> The user selects a table. Then the selected table's columns are listed. A textbox accepts a comment entry. The save button triggers the action to add or update the comment.

You already accepted this before I could comment on this.

I believe you are over complicating the process with the one exception below:  Security.

Personally I wouldn't create an application for this.  The 'Users' of it would likely need to be the DBA's or developers that created the schema since they know what the tables and columns actually mean.

They should be able to provide you a simple SQL script with the correct COMMENT commands.  Then just execute the script.

It would be just as easy to create an Excel spreadsheet with the tables and columns then turn that into a script.

That said:
The only reason to create a procedure to do this is for security purposes.  The app connects to the database with a username that has only been granted execute on the procedure above.

If the app connects to the database as the owner of the tables, no need for the procedure.  ALL programming languages can execute native SQL.  No need for Pl/SQL.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
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…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

734 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