您好,欢迎访问一九零五行业门户网

Oracle中使用游标获取指定数据表的所有字段名对应的字符串

操作步骤:打开plsql developer后,直接执行下面的语句就可以出来 --oracle中使用游标获取指定数据表的所有字段名对应的字符串 declare mytablename varchar(255):='staffdoc'; --定义要查询的数据表名变量,staffdoc为我测试用的数据表名,请修改成您的数据
操作步骤:打开plsql developer后,直接执行下面的语句就可以出来
--oracle中使用游标获取指定数据表的所有字段名对应的字符串
declare
mytablename varchar(255):='staffdoc'; --定义要查询的数据表名变量,staffdoc为我测试用的数据表名,请修改成您的数据库中的对应数据表名字
mystring nvarchar2(4000):=''; --定义要输出的字符串变量
cursor mycursor is --定义游标          
select * from all_tab_columns where table_name=mytablename order by column_id;  
myrecord mycursor%rowtype;  --定义游标记录类型   
counter int :=0;   
begin   
open mycursor;  --打开游标   
if mycursor%isopen  then  --判断打开成功   
loop --循环获取记录集     
fetch mycursor into myrecord; --获取游标中的记录
if mycursor%found then  --游标的found属性判断是否有记录  
begin
if length(mystring)>0 then
mystring:=mystring||','||myrecord.column_name;
else
mystring:=myrecord.column_name;
end if;
end;
else            
exit;
end if;
end loop;   
else     
dbms_output.put_line('游标没有打开');   
end if;  
dbms_output.put_line(mystring);    
close mycursor;
end;
其它类似信息

推荐信息