循环遍历 PL/SQL 行
我花了很长时间寻找某种方法来迭代 PL/SQL 行,但没有得到任何合适的结果。
例如,如果我有一个类似于 row(first_name,last_name)
的 PL/SQL 行,并且我想在不了解该行的情况下使用 PL/SQL 打印名字和姓氏,即我不知道该行是什么样子,所以我需要某种类似这样的代码
FOR column IN My_Row --some way to iterate through the row.
LOOP
PRINT column... --do my stuff, in this example
END LOOP;
I'm searching for a long time for some way to iterate through PL/SQL row, but I did not get any appropriate results.
For example, if I have a PL/SQL row that looks like this row(first_name,last_name)
and I want to print the first name and the last name using PL/SQL without knowledge about the row i.e. I don't know how the row looks like so I need some kind of code that looks like this
FOR column IN My_Row --some way to iterate through the row.
LOOP
PRINT column... --do my stuff, in this example
END LOOP;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您知道该行所在的表的名称,则可以从
ALL_TAB_COLUMNS
获取列的名称。您可以围绕它构建动态 SQL。请参阅有关询问 Tom 的文章,了解以下内容:引用 %rowtype 变量而不使用列名。根据您的评论,您将浏览所有表格,以便可以使用
ALL_TABLES
获取它们的所有名称。但请记住,ALL_TABLES
是您的登录名有权访问的所有表,而DBA_TABLES
是数据库中的每个表,USER_TABLES
是您的用户拥有的表。If you know the name of the table the row is from then you can get the names of the columns from
ALL_TAB_COLUMNS
. You can build a dynamic SQL around that. See this Ask Tom article regarding something like this: Referencing %rowtype variables without using column names.Based upon your comment you'll be going through all your tables so you can use
ALL_TABLES
to get all their names. Though remember thatALL_TABLES
is all tables your login has access to whileDBA_TABLES
is every table in the database andUSER_TABLES
is those that your user owns.