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.
7 59102
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
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: -
declare
-
CURSOR C1 is SELECT table_name FROM all_tables where table_name = 'EMP';
-
BEGIN
-
FOR I IN c1 LOOP
-
EXECUTE IMMEDIATE 'DROP TABLE '||I.table_name;
-
END LOOP;
-
--After dropping all the tables you can recreate then like this:
-
EXECUTE IMMEDIATE 'CREATE TABLE EMP(emp_no NUMBER,empname VARCHAR2(100),salary NUMBER,hire_date DATE,deptno NUMBER)';
-
END;
-
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, - 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.
Which oracle version you are using?
And are you going to us DDL statement manually or from any other program?
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.
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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
...
|
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
...
|
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...
|
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...
|
by: Yansky |
last post by:
If I have the following code:
var abc;
if(!abc){
alert('test');
}
|
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...
|
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...
|
by: concettolabs |
last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
|
by: better678 |
last post by:
Question:
Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct?
Answer:
Java is an object-oriented...
|
by: teenabhardwaj |
last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: CD Tom |
last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
|
by: antdb |
last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine
In the overall architecture, a new "hyper-convergence" concept was...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
| |