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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
I figured out how to do what I need to do.
 
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.