Oracle 10g-快速查询
我想对我的 oracle 数据库中的表执行特殊查询。
我希望结果根据我拥有的枚举进行排序。
枚举如下:
private enum days
{
Saturday = 1,
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
}
我希望根据此枚举对结果进行排序。
I want to perform a special query on a table in my oracle database.
I want the result to be sorted according to an enum that I have.
the enum goes as follows:
private enum days
{
Saturday = 1,
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
}
I want the result to be sorted according to this enum.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这听起来更像是一个
SQL
问题;以下参考可能会有所帮助:http://www.techonthenet.com/oracle/functions/ to_date.php
暴力破解方法是在 SQL 中使用 case 语句;与您的代码片段等效的是:
DECODE
SQL 函数也可以工作,但我喜欢CASE
因为它更容易阅读并避免拼写错误或错误。如果您从日期值中获得更多信息,我建议将数据库字段中的日期值完整保留为 DATE 数据类型。如果您需要找出星期几,使用上面的参考,您可以简单地将日期值转换为表示正确的、对应的星期几值的字符串。
测试:
产量:
请记住,从 to_char 函数返回的任何内容都是区分大小写的。这应该适用于所有版本的 Oracle,包括 Oracle-XE。
This sounds more like a
SQL
question; The following reference may be helpful:http://www.techonthenet.com/oracle/functions/to_date.php
The brute-force method is to use a case statement in your SQL; the equivallent to your snippet of code is:
The
DECODE
SQL function also works as well, but I likeCASE
because it's easier to read and avoid typos or mistakes.If you have more information from your date values, I suggest to keep your date values intact in your database fields as a DATE data type. If you need to find out the day of the week, using the reference above, you can simply cast your date value as a character string representing the correct, corresponding day of the week value.
to test:
yields:
Keep in mind that whatever is returned from the to_char function is case sensitive. This should work on all editions of Oracle, including Oracle-XE.