Home Database Mysql Tutorial Oracle 函数用法之decode

Oracle 函数用法之decode

Jun 07, 2016 pm 04:56 PM
oracle database

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

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How long will Oracle database logs be kept? How long will Oracle database logs be kept? May 10, 2024 am 03:27 AM

How long will Oracle database logs be kept?

Oracle database server hardware configuration requirements Oracle database server hardware configuration requirements May 10, 2024 am 04:00 AM

Oracle database server hardware configuration requirements

How much memory does oracle require? How much memory does oracle require? May 10, 2024 am 04:12 AM

How much memory does oracle require?

How much memory is needed to use oracle database How much memory is needed to use oracle database May 10, 2024 am 03:42 AM

How much memory is needed to use oracle database

Oracle scheduled tasks execute the creation step once a day Oracle scheduled tasks execute the creation step once a day May 10, 2024 am 03:03 AM

Oracle scheduled tasks execute the creation step once a day

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

Detailed tutorial on establishing a database connection using MySQLi in PHP

How much memory does an oracle database require? How much memory does an oracle database require? May 10, 2024 am 02:09 AM

How much memory does an oracle database require?

How to start the listening program in oracle How to start the listening program in oracle May 10, 2024 am 03:12 AM

How to start the listening program in oracle

See all articles