Solved

Execute a PL/SQL Database Modification function

Posted on 2014-10-02
5
239 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
  • 2
  • 2
5 Comments
 
LVL 76

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 73

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 76

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

867 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

12 Experts available now in Live!

Get 1:1 Help Now