在 Oracle PL/SQL 中获取具有索引而不是列名称的字段

Get fields with index instead name of column in Oracle PL/SQL

有人知道如何通过索引访问 plsql oracle 游标字段。

是否可以通过索引而不是列名获取table的字段?

提前致谢。

declare
  cursor c_user is 
    select * 
      from users
     where age > 20;
begin
    for u in c_user loop
        dbms_output.put_line(u.lastname||' '||u.firstname);
    end loop; 
end;

示例

declare
  cursor c_user is 
    select * 
      from users
     where age > 20;
begin
    for u in c_user loop
        dbms_output.put_line(u.1||' '||u.2);
    end loop; 
end;

如果您问是否可以按位置引用 PL/SQL 记录中的字段,答案是否定的。您只能按名称引用它们。

顺便说一下,在数据库世界中,index 通常指的是一个数据库对象,它存储来自 table 的键值以及它们组织的物理位置快速检索,table 哦,没关系,所以 "get the fields of the table through an index" 让我有点困惑,因为我不知道'认为你的意思是存储数据的优化查找。如果我有错,请道歉。

尝试这样的事情:

declare
cursor Inx_Cur(P_Indx Number) is select 
decode(P_Indx,1,ACCOUNTNO,2,ACCOUNTNAME,3,ACCOUNTTYPE) My_field
from accounts;
begin
for Rec in Inx_Cur(3) -- pass the required index as 
parameter
loop
 dbms_output.put_line('My_field : '||Rec.My_field);
end loop;
end;