有没有办法让 SQL 语句从以整数作为键的映射返回字符串值?
例如:
在数据库中,我们有与应用程序中的字符串相对应的字段的数字表示。出于大小和速度的原因,我们将数据存储为整数。在测试过程中,我们将应用程序中的内容与 SQL 语句结果进行比较。问题是我们在结果中看到数字,但应用程序中有字符串。代码中有一个枚举定义了这些数字在字符串中的含义。不必每次想要比较时都查看枚举...有没有办法让 SQL 结果显示我放入 SQL select 语句中的映射中的字符串,而不是数据库中实际的整数值?
For example:
In the database we have number representations of fields that correspond to strings in the app. We store the data as an integer for size and speed reasons. During testing we compare what's in the app with SQL statement results. The problem is that we see the numbers in the results but there are strings in the app. There is an enum in the code that defines what those numbers mean in terms of a string. Instead of having to look at the enum everytime I want to compare ... is there a way to make the SQL results show the string in a map that I put in the SQL select statement instead of the integer value that's actually in the database?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用如下所示的
CASE
语句在 SQL 中重新创建Enum
:更好的方法是将 Enum 存储为查找表。然后你就可以加入反对它:
You can recreate your
Enum
in SQL using aCASE
statement like this:Even better is to store the Enum as a lookup table. Then you can just join against it: