oracle - substr() & instr()

1. substr()

Syntax:

SUBSTR (string,start_position,[length_of_substring])

eg:

substr('This is a test',6,2)     would return 'is'

remarks:

  • The original string is assumed to start at position one (1).
  • If substring_length is omitted,then Oracle returns all characters to the end of char.
  • If substring_length is less than 1,then Oracle returns null.

2. instr()

Syntax:

instr(string,substring,[position],[occurrence])

eg:

select instr('corporate floor','or',3,2) from dual;  would return '14'

remarks:

  • The default values of both position and occurrence are 1,meaning Oracle begins searching at the first character of string for the first occurrence of substring.
  • The return value is relative to the beginning of string,regardless of the value of position.

我的用例:

CASE UPPER(T1.COLUMN_TYPE)
    WHEN SUBSTR(RF1.ParaM_VALUE,1,INSTR(RF1.ParaM_VALUE,'~')-1) THEN SUBSTR(RF1.ParaM_VALUE,'~')+1)
    ELSE T1.PRODUCT_TYPE_DESC
END AS PRODUCT_TYPE

COLUMN_TYPE: AN APPLE ParaM_VALUE: AN APPLE~FRUITSUBSTR(RF1.ParaM_VALUE,'~')-1): AN APPLE INSTR(RF1.ParaM_VALUE,'~')+1: 10这里用于字段参数化,从一个参数表的某个相应字段中对比取值,对比~前的值,如果一致,那么取~后的值。

相关文章

Java Oracle 结果集是Java语言中处理数据库查询结果的一种方...
Java AES和Oracle AES是现代加密技术中最常使用的两种AES加密...
Java是一种广泛应用的编程语言,具备可靠性、安全性、跨平台...
随着移动互联网的发展,抽奖活动成为了营销活动中不可或缺的...
Java和Oracle都是在计算机领域应用非常广泛的技术,他们经常...
Java 是一门非常流行的编程语言,它可以运行于各种操作系统上...