可以呀!
CREATE OR REPLACE FUNCTION create_table (I_NAME VARCHAR2)
IS
cursor c_table is select *
from user_tab_columns
where TABLE_NAME=UPPER(I_NAME);
v_table user_tab_columns%rowtype;
begin
dbms_output.put_line('CREATE TABLE'||' '||'I_NAME'||'(');
open c_table;
loop
fetch C_table into v_table;
exit when C_table%notfound;
dbms_output.put_line(v_table.COLUMN_NAME||' ' ||v_table.DATA_TYPE||'('||v_table.DATA_LENGTH||')');
end loop;
dbms_output.put_line(');');
close c_table;
end create_table;
/
CREATE OR REPLACE FUNCTION create_table (I_NAME VARCHAR2)
IS
cursor c_table is select *
from user_tab_columns
where TABLE_NAME=UPPER(I_NAME);
v_table user_tab_columns%rowtype;
begin
dbms_output.put_line('CREATE TABLE'||' '||'I_NAME'||'(');
open c_table;
loop
fetch C_table into v_table;
exit when C_table%notfound;
dbms_output.put_line(v_table.COLUMN_NAME||' ' ||v_table.DATA_TYPE||'('||v_table.DATA_LENGTH||')');
end loop;
dbms_output.put_line(');');
close c_table;
end create_table;
/
return varchar2
as
cursor c_table is select *
from user_tab_columns
where TABLE_NAME=upper(p_table);
str varchar2(200);
begin
str:='CREATE TABLE '||p_table||'(';
for v_table in c_table loop;
str:=str||v_table.COLUMN_NAME||' '||v_table.DATA_TYPE||'('||v_table.DATA_LENGTH||'),';
end loop;
str:=substr(str,1,length(str)-1)||')';
return str;
end;
/