表名和字段名作为参数传入存储过程
表名和字段名作为参数传入存储过程或函数
帮忙举个例子
------解决方案--------------------网上搜索一下,大把多啊
create or replace function getcloumns(
index_owner1 in varchar2,
index_name1 in varchar2,
column_nums1 in number) return varchar2
is
all_columns varchar2(512);
total_num number;
i number;
cursor c1 is select column_name from dba_ind_columns where index_owner=index_owner1 and
index_name=index_name1 order by column_position;
dummy c1%rowtype;
begin
total_num:=column_nums1;
open c1;
fetch c1 into dummy;
i:=0;
while c1%found loop
i:=i+1;
if (i=total_num) then
all_columns:= all_columns||dummy.column_name;
else
all_columns:= all_columns||dummy.column_name||',';
end if;
fetch c1 into dummy;
end loop;
close c1;
return all_columns;
exception
when no_data_found then
return all_columns;
end;
/
过程select_index_columns:
create or replace procedure select_index_columns
is
all_columns varchar2(2000);
cursor c1 is select * from index_nouniq_column_num where column_num>=2;
dummy c1%rowtype;
begin
open c1;
fetch c1 into dummy;
while c1%found loop
select getcloumns(dummy.owner,dummy.index_name,dummy.column_num) into all_columns from dual;
insert into index_columns values(dummy.owner,dummy.index_name,all_columns);
fetch c1 into dummy;
end loop;
commit;
close c1;
exception
when others then
rollback;
end;
/
------解决方案--------------------SQL code
CREATE OR REPLACE PROCEDURE TEST100(TABLENAME IN VARCHAR2,COLNAME IN VARCHAR2)
IS
STRSQL VARCHAR2(4000);
BEGIN
STRSQL:='DELETE FROM '||TABLENAME||' WHERE '||COLNAME||'=7';
EXECUTE IMMEDIATE STRSQL ;
COMMIT;
END;