Oracle 11g stored procedure with datacheck and parameters

I want to create an Oracle Stored procedure. I will pass in the database name and the parameters name. I want to check the datatype of the field and if it is a CLOB already, I don't want to do the stored procedure.

Can someone help me?

COLNAME and xxx will be passed in.
They are the field column name and the table name.

I want to check if the column name of this table is a varchar2, and not already a clob, and if not, run it...
if COLNAME = varchar2(4000) then

alter table xxx add y_copy varchar2(4000);
update xxx set y_copy = COLNAME;
update xxx set COLNAME = null;
commit;
alter table xxx modify COLNAME long;
end if

if colname type = long then
alter table xxx modify COLNAME clob;

if colname type = clob then
update xxx set COLNAME = y_copy;
commit;

if exists y_copy
alter table xxx drop column y_copy;
commit;

I may not need to do all the if statements, but I want it to take up where it left off if it fails in the middle.

thanks!
LVL 2
Starr DuskkASP.NET VB.NET DeveloperAsked:
Who is Participating?
 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
I figured out how to do what I need to do.
 
0
 
Devinder Singh VirdiLead Oracle DBA TeamCommented:
In short you need to use
user_tab_columns OR all_tab_columns
make dynamic sql
and need to include execute immediate to run that.
0
 
slightwv (䄆 Netminder) Commented:
What is the real goal here?

You typically don't dynamically add/change/drop columns in a table.  Let alone change between varchar2 and longs.

What about a varchar(2) column?

You can loop through the views as posted above but I think you're going down the wrong path.

0
 
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
goal is to call a stored procedure and pass in the table name and the column name to be converted and convert that column to a CLOB.
And I want a stored procedure because there are so many fields that need converted, that I don't want to mess up by doing each script manually, one at a time.
And no, it is a varchar2(4000) column. I am converting it to long, and then clob, because that's the only way to convert it using the same field name in the same position within the table.
So far neither comments given have been useful.
 
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.