×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Can procedure support CREATE TABLE and CREATE INDEX?

Can procedure support CREATE TABLE and CREATE INDEX?

Can procedure support CREATE TABLE and CREATE INDEX?

(OP)
I have ORACLE 8i running on Linux and NT.  

I try to create a procedure including CREATE TABLE or CREATE INDEX statemants,  they always fail, but the same CREATE TABLE or CREATE INDEX statements are running fine outside of the procedure or BEGIN...END.

Following is my sample code. It doesn't work.
CREATE PROCEDURE CreateTiesTable
IS
begin
CREATE TABLE TiesTable_New (
ID NUMBER(10),
  TieStateID NUMBER(4)
);
END CreateTiesTable ;

So how can I create a table or index in a procedure?  Does ORACLE support this?

Thanks very much your help in advance!

Mary

RE: Can procedure support CREATE TABLE and CREATE INDEX?

Mary,

You need to use dynamic sql in order to execute DDL within
a procedure.  If you review the DBMS_SQL package it should give you some examples.

Hope this helps,
--tl

RE: Can procedure support CREATE TABLE and CREATE INDEX?

(OP)
tl,

Thanks very much!  Your information is very helpful and it works.

Mary

RE: Can procedure support CREATE TABLE and CREATE INDEX?

Look for "Execute Immediate" command in Oracle8i.
This is better than dbms_sql package.
U just have to prepare the command string.

For example
sql_stmt varchar2(256);
sql_stmt = 'Create Table .....'
Execute immediate sql_stmt;

This will do the job
This is a new addition in Oracle8i

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close