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 59243
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 tMyTable VALUES("xxlk", "lkjlkjlkjljk")
I want to insert into a table but only if the table exists.
How does one, in general, from PHP, test for the existence of a table,
without getting an error message?
|
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 that??
Please help me
|
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 = '';
|
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 = '';
|
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.
- Pete
| |
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 means the id is not exist in my Booking1 table. How should i express this " if empty " concept in python?
def confirmUp(request):
q=request.session
b=Booking1.objects.filter(id__exact=q)
if b=empty
|
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 last row and no row exists; the routine just hangs:
var checkNext = obj.parentNode.parentNode.nextSibling.id;
Any ideas how I can get this to return "null" or "false" is there isn't a subsequent row in the table?
|
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
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |