Home > Database > Mysql Tutorial > body text

Oracle 函数用法之decode

WBOY
Release: 2016-06-07 16:56:07
Original
1025 people have browsed it

Oracle数据库: DECODE函数将该数值与一系列的序偶相比较,以决定最后的返回结果 。序偶序偶,就是成对出现;我们将这个函

  Oracle数据库:

  DECODE函数将该数值与一系列的序偶相比较,以决定最后的返回结果 。序偶序偶,就是成对出现;我们将这个函数与switch比较,我们发现他们基本相似,唯一不同的是switch将要比较的值放在case后面都加上了break中。

  以下一个例子:(我直接从网上找的)

  SELECT id,

  DECODE(flag,’Y’,'Yes’,'N’,’No’,NULL,’None’,'Yes’)

  FROM t_test;

  当t_test的flag字段为Y时返回Yes,为N时返回No,为NULL时返回None,默认返回Yes。

  看看我遇到的问题:

  SELECT a.id,

  a.user_name,

  a.oper_time time2,

  a.oper_type,

  a.description,

  a.oper_flag,

  decode(a.oper_flag, '1', '成功', '失败') oper_flag,

  a.ip,

  b.true_name

  FROM SEC_LOG_OPERATION a

  left join sec_user b on a.user_name = b.user_name

  where 1 = 1

  order by oper_time desc

  原来这红线部分是: decode(a.oper_flag, 1, '成功', '失败')

  我在查询的时候会报错,,原因是oper_flag这个字段数据中有非数字类型,也就是这个字段不仅有1、0,还有“失败”,这样数据!=字符。所以我们把1当字符处理就可以了。

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!