Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Building create statement in procedure, and alter table in procedure

662880Oct 16 2008 — edited Oct 16 2008
Hi i have a procedure, inside my procedure i have variabel called V_create...

I will give the V_create
column_name
data_type
data_length
data_precision
data_scale
data_default
nullable

v_CREATE :='Create table ' ||v_p|| ' ( ';

FOR I IN 1..t_cols.count loop
V_CREATE:= V_CREATE || ' ' ||t_cols(i).column_name;
V_CREATE:= V_CREATE || ' ' || t_cols(i).data_type||'';
-----vid datatype------
if t_cols(i).data_type = 'VARCHAR2' THEN
V_CREATE:= V_CREATE || ' (' || t_cols(i).data_length||')';
end if;
if t_cols(i).data_type = 'CHAR' THEN
V_CREATE:= V_CREATE || ' (' || t_cols(i).data_length||')';
end if;
if t_cols(i).data_type = 'NUMBER' AND t_cols(i).data_precision IS NULL
AND t_cols(i).data_scale IS NULL
THEN V_CREATE:=V_CREATE || ' ';
end if;
if t_cols(i).data_type = 'NUMBER' AND t_cols(i).data_precision IS NOT NULL
AND t_cols(i).data_scale IS NULL
THEN V_CREATE:= V_CREATE || ' (' || t_cols(i).data_precision||')';
end if;
if t_cols(i).data_type = 'NUMBER' AND t_cols(i).data_precision IS NOT NULL
AND t_cols(i).data_scale IS NOT NULL
THEN V_CREATE:= V_CREATE || ' (' || t_cols(i).data_precision||','||t_cols(i).data_scale||')';
end if;
----default----
if t_cols(i).data_default IS NOT NULL THEN
V_CREATE:= V_CREATE || ' default ' || t_cols(i).data_default;
end if;
----nullable?-----
if t_cols(i).nullable ='Y'
THEN
V_CREATE:= V_CREATE || ',';
ELSE
V_CREATE:= V_CREATE || ' not null ' ||',';
end if;
END LOOP;
V_CREATE:= RTRIM(V_CREATE, ',') || ')';

DBMS_OUTPUT.PUT_LINE(V_CREATE);

the output looks like this (its not create statement its just output)
---------------------------------------------------------------------------------------------
Create table CHEF_NEW ( CID NUMBER (10,0), NAMN VARCHAR2 (10), TOK VARCHAR2 (40), YOWYOW VARCHAR2 (38), NUM2 NUMBER default 7 not null )
---------------------------------------------------------------------------------------------

Now I will do the samething whit another variabel

V_alter

It will get this;


constraint_name
constraint_type *
search_condition *

the variabel output will look like alter table "tablename"add "constraint_name","constraint_type","search_condition"

how do i DO THIS?+_



(MY procedure will change something from existing table...)
I know what 2 do, but i realy dont know how 2 do this....
can someone helpme whit this please...
/Lars

Edited by: user10382291 on 2008-okt-16 01:19

Edited by: user10382291 on 2008-okt-16 01:20
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 13 2008
Added on Oct 16 2008
16 comments
359 views