phoen08
asked on
Oracle create table based on multiple conditions
Hi,
I'm trying to figure out the best approach to creating an oracle table If a certain condition is true.
for example.
Create table1 if name <> ' ' and address <> ' '
Create table1 if name <> ' ' and address <> ' ' and phone = ' '
Should a case statement be used in this scenario?
I'm trying to figure out the best approach to creating an oracle table If a certain condition is true.
for example.
Create table1 if name <> ' ' and address <> ' '
Create table1 if name <> ' ' and address <> ' ' and phone = ' '
Should a case statement be used in this scenario?
Are you looking something like this?
File_1.sql
Set Serveroutput on
set echo off
.
.
.
spool &1
begin
if name <> '' and address <> '' then
DBMS_OUTPUT.PUT_LINE('CREA TE TABLE(col1 varchar2(2));');
end if;
if name <> '' and address <> '' then
DBMS_OUTPUT.PUT_LINE('CREA TE TABLE (col1 varchar2(2), col2 varchar(2)); ');
end if;
end;
spool off;
sqlplus -s username/password @File_1.sql my_spool.sql
sqlplus -s username/password @my_spool.sql
File_1.sql
Set Serveroutput on
set echo off
.
.
.
spool &1
begin
if name <> '' and address <> '' then
DBMS_OUTPUT.PUT_LINE('CREA
end if;
if name <> '' and address <> '' then
DBMS_OUTPUT.PUT_LINE('CREA
end if;
end;
spool off;
sqlplus -s username/password @File_1.sql my_spool.sql
sqlplus -s username/password @my_spool.sql
ASKER
I'm trying to convert an old process that would export output to a text file to a process that would store the data in oracle tables. One of the sections in the file process outputs columns based on whatever condition is presents. After further review, I believe this step in the process is only changing the column values based on the condition. So, I may just need multiple case statements to change the column data based on the condition. There would only be one table created from all of the condition statements.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you'll have to check your conditions first then issue whatever create is appropriate.
what is the intent here? It's not standard (and certainly not recommended) practice to create tables on the fly in Oracle.
Are you trying to create "temp" tables to work with? If so, doing it dynamically is the wrong approach