Solved

Execute a PL/SQL Database Modification function

Posted on 2014-10-02
5
238 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

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

Suggested Solutions

Title # Comments Views Activity
Oracle SQL queries -- Challenging question 13 65
Oracle PL/SQL syntax 4 52
Oracle regular expression 6 30
sql for Oracle views 8 38
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…
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
Via a live example, show how to take different types of Oracle backups using RMAN.

743 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