473,325 Members | 2,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Creating a table in Oracle DB if it does not exist, using SQL

Hi,

I need to create a table in Oracle DB using SQL before which I need to
check if it exists or not, where the dbuser will have CONNECT and
RESOURCE privileges granted.

All this needs to be in a .sql file so that it can be included in the
release.

I tried writing a Stored Procedure using DBMS_SQL.parse etc., but
looks like, the above stated privileges are not enough.
Is there a way that serves my purpose without anymore privileges given
?

If someone can take time to write a running sample and send me, I
would be Grateful.

Thanks,
Chaitanya.
Jul 19 '05 #1
2 25919
rob
> If someone can take time to write a running sample and send me, I
would be Grateful.

Thanks,
Chaitanya.


Something like this?
=== create_test123.sql ===
DECLARE
c_table_name varchar2(50) := upper('test123');
cursor c1 is
select table_name
from user_tables
where table_name = c_table_name;
BEGIN
open c1;
fetch c1 into v_table_name;
if c1%NOTFOUND
then
execute immediate 'create table test123 (n number
,b varchar2(20)) ' ;
end if;
close c1;
END;
/

=== end create_test123.sql ===
Jul 19 '05 #2
1. Create a file with your table definition. Your could call it
anything you want with a SQL extention. EXAMPLE mynewtable.sql:

create table &1..new_table (
col1 char(1),
col2 char(1),
col3 char(1),
col4 char(1)
);

2. Logon to database with DBA rights and call mynewtable.sql with
user name as parameter.

sqlplus dba/password

SQL> @mynewtable scott

3. Repeat #2 for every user. This will create the table for each
user. There is no need to check if the table already exists since
trying to create the table will error out and not harm the existing
table.
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
2
by: Ralph Snart | last post by:
Is there a way to alternate table row colors without using the position() mod 2 trick? I'm in a series of nested xsl:for-each elements, about 3 deep, and I want to alternate the table row color...
2
by: Rajesh Tammana | last post by:
Hi, I am trying to create an SMS package using GetPDFData method. When I call this method it returns the PackageData object instance with C# object type ManagementBaseObject. Usually I call...
4
by: GRenard | last post by:
Hi, I'm trying just to display a table on a webpage using DOM elements created dynamically. I really don't understand why IE doesn't display the document successfully... If I make a...
3
by: --[zainy]-- | last post by:
AA! I am having problems on creating table through Enterprise Manager. It gives me Error 1038 i.e. is as follows Unexpected Error ODBC error: Cannot use empty object or column names. Use...
2
by: KGP | last post by:
I have written one procedure into which I am creating table(Oracle 10g) While executing procedure I get error as:ORA-01031: insufficient privileges where as this user has DBA rights and the same...
2
by: Guy Moseley | last post by:
Hi all, Could someone please point me in the right direction! I am in the process of creating an Ms Access db and as part of this use VBA in a form to create a table based on the input to the...
1
by: Ankit | last post by:
Hi guys i need to make a table to store a certain data using Tkinter..I have searched on the group but i have not been able to find a solution that would work for me..The thing is that i want my...
1
by: ramansharma95 | last post by:
Hello , I m Raman and new to theScripts I m going to drop a table of ms access using vb.net but i could not find the code which checks the table is already existing or not Plz help me related to...
1
by: Shun | last post by:
Hello, I am trying to extract the data from my Oracle 10g database using Java. First, I tried to connect Oracle to Java using this code and it works. import java.util.*; import java.sql.*;...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.