473,513 Members | 2,559 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Does an "IF Exists" clause exist in Oracle?

127 New Member
Hello All,

I remember in MySQL we do have "IF EXISTS", 'IF NOT EXISTS" clause/keyword in the DDL statements (CREATE,DROP etc.,) to avoid unnecessary bombing.

Do we have such facility in Oracle? If not is there any other easy way to achieve it? I am using Oracle 10g. I have been searching through google and also in oracle.com but unable to get it out.

Thanks,
Raghavan alias Saravanan M.
Nov 19 '08 #1
7 59228
Pilgrim333
127 New Member
Hi,

In Oracle you can use exists in the where clause. Other options are the IN and NOT IN in the where clause.

You can find more info on this topic over here conditions

Pilgrim
Nov 19 '08 #2
amitpatel66
2,367 Recognized Expert Top Contributor
Hi,

In Oracle you can use exists in the where clause. Other options are the IN and NOT IN in the where clause.

You can find more info on this topic over here conditions

Pilgrim

One CANNOT USE EXISTS and IN and NOT IN in DDL statements (CREATE, DROP)

@OP,

If you want to check whether the particular object exist or not before creating the new one or before dropping the old one, then you can do so using a PLSQL way. Just check the sample code below:

Expand|Select|Wrap|Line Numbers
  1. declare
  2. CURSOR C1 is SELECT table_name FROM all_tables where table_name = 'EMP';
  3. BEGIN
  4. FOR I IN c1 LOOP
  5. EXECUTE IMMEDIATE 'DROP TABLE '||I.table_name;
  6. END LOOP;
  7. --After dropping all the tables you can recreate then like this:
  8. EXECUTE IMMEDIATE 'CREATE TABLE EMP(emp_no NUMBER,empname VARCHAR2(100),salary NUMBER,hire_date DATE,deptno NUMBER)';
  9. END;
  10.  
Nov 19 '08 #3
itsraghz
127 New Member
Thank you Pilgrim33 and amitpatel for having replied immediately.

I do agree with the alternatives for "really checking" before you do with your DDL statements. But it should be at the cost of this quite-lengthy-and-expensive operation?

In MySQL, we have,

Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE IF EXISTS MyTable (..);
Don't we have a similar-and-easy way to accomplish the same in Oracle?

Thanks,
Raghavan alias Saravanan M.
Nov 19 '08 #4
amitpatel66
2,367 Recognized Expert Top Contributor
Which oracle version you are using?

And are you going to us DDL statement manually or from any other program?
Nov 19 '08 #5
Pilgrim333
127 New Member
Oooops, replied a bit too soon, without reading, thought OP meant the SQL version of IF EXISTS.

But anyhoo Raghavan, you can't accomplish it with a statement, you'll have to write some pl/sql code. And writing the code takes you more time then manually checking if the table exists and creating a new table.

Pilgrim.
Nov 19 '08 #6
itsraghz
127 New Member
Which oracle version you are using?

And are you going to us DDL statement manually or from any other program?
Thanks amit. It was for writing a SQL Script when setting up the new module for the existing database instance. There are times/situations wherein we need to atler the existing tables according to the new module. That's the reason I just had a thought compared to what MySQL gives this facility.
Nov 19 '08 #7
itsraghz
127 New Member
Oooops, replied a bit too soon, without reading, thought OP meant the SQL version of IF EXISTS.

But anyhoo Raghavan, you can't accomplish it with a statement, you'll have to write some pl/sql code. And writing the code takes you more time then manually checking if the table exists and creating a new table.

Pilgrim.
Thank you very much Pilgrim.

You are absolutley right and I do agree with the complexity its gonna take than the manual verification. Anyways, I just have to go with the plain, non-conditional version of sql script by bearing the overheads.
Nov 19 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

4
11102
by: lawrence | last post by:
Google can't find me a good example of how to use the "if exists" syntax in MySql. Is it right that to use it this way: INSERT INTO IF EXISTS tMyTable VALUES("xxlk", "lkjlkjlkjljk") I want...
1
11485
by: Rajeshwar_ts | last post by:
Hi, I am new to this group and new to PostGreSql. i am changing from MySql to PostGresql. I am unable to work with "Drop table if exists tablename" query. Is there any alternate query for...
2
3597
by: naughtybynature | last post by:
<html> <head> <title>Search Questions</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php $query = '';
1
2011
by: naughtybynature | last post by:
<html> <head> <title>Search Questions</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php $query = '';
3
5297
by: Pete | last post by:
I successfully use "My.Computer.Network.DownloadFile", including the authentication data, but I would appreciate learning how to first test whether the file exists on the remote computer. Thanks....
4
2358
by: kang jia | last post by:
hi currently i am getting an array from database,the code is in the following, if id do not exist variable b will render an empty array. at this time, i would like to check if this array is empty...
3
2002
by: Yansky | last post by:
If I have the following code: var abc; if(!abc){ alert('test'); }
3
7279
by: phub11 | last post by:
Hi all, I have a routine that checks to see if an ID has been set for the next row down in a table. Everything works fine except if I'm on the last row and no row exists; the routine just hangs: ...
3
2152
by: moshe koren | last post by:
Hi, i'd like to have code blocks A and B if AB is defined and B and C block if BC is defined. is the writing below correct ? void func(...) { #if defined AB A
0
7384
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7099
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
5086
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4746
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3233
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3222
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1594
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
799
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
456
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.