MySQL 使用另一个表中的列名
我想知道是否可以返回一个结果集,其列名存储在单独的表中。这是可能的还是我需要一个带有变量的存储过程。请参阅 mysql_dump 的链接和所需结果集的描述:
I'm wondering if it is possible to return a result set with column names which are stored in a separate table. Is this possible or do I need a stored_procedure with variables. See link for mysql_dump and description of required resultset:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须使用动态生成 SQL 然后运行它的存储过程。列名在 SQL 中并不是真正的一流数据,因此您不能用它们做任何事情。它们是在执行查询或获取任何数据之前在查询解析时确定的。
我建议在您的应用程序中执行此操作。只需让您的应用程序显示/保存/任何正确的名称而不是数据库列名称。
PS:您严重滥用关系模型。请仔细考虑您是否真的想要该架构。 您的架构不符合第一个范式。
worksheet_type_lookup
的用途是什么?worksheets
没有告诉您哪种类型吗?You'd have to use a stored procedure that'd generate SQL dynamically and then run it. Column names aren't really first-class data in SQL, so you can't do much anything with them. They are determined at query parse time, before executing the query or fetching any data.
I suggest doing it in your app instead. Just have your app display/save/whatever the correct names instead of the database column names.
PS: You are abusing the relational model horribly. Please very carefully consider if you really want that schema. Your schema fails the first normal form. And what is
worksheet_type_lookup
for? Doesn'tworksheets
tell you which type?