获取选择查询返回的结果的架构
问题描述
我们可以得到 SELECT Query 返回的结果的模式吗?下面的代码:
Can we get schema of the result returned by SELECT Query? Below code:
此代码返回列名以及指定表的数据类型.我的要求是从选择查询中获取列名和数据类型,而不是直接指定表名.喜欢
This code returns column names along with datatype for specified table. My requirement is to get column names along with datatype from a select query rather than directly specifying table name. like
虽然这行不通.
推荐答案
您可以将查询结果 SELECT 到一个临时表中,并从该表中获取元数据.如果您选择这样的解决方案,您需要确保临时表的名称每次调用都是唯一的,否则 information_schema 视图中的元数据将在会话之间共享.
You can SELECT the query result INTO a temporary table, and from that table get the metadata. If you choose a solution like this you will need to make sure that the name of the temporary table is UNIQUE per call, otherwise meta-data in information_schema views will be shared across the sessions.
或者,如果您愿意,您可以在 C# 中更轻松地执行此操作,这可能不太容易出错.获取查询结果集的元数据非常容易:
Or, if you want you can do it easier In C# which will probably less error prone. It is very easy to get the meta-data for a result set of a query:
输出:
这篇关于获取选择查询返回的结果的架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!