Oracle的字符串转数组以及数组转字符串
字符串转数组:
(SELECT REGEXP_SUBSTR('34,56,-23', '[^,]+', 1, LEVEL, 'i') AS STR
FROM DUAL
CONNECT BY LEVEL <=
LENGTH('34,56,-23') - LENGTH(REGEXP_REPLACE('34,56,-23', ',', '')) + 1)
针对上⾯语法进⾏解析(转载⾃):
ruby 字符串转数组regexp_substr详解:
regexp_substr函数格式如下:
function regexp_substr(String, pattern, position, occurrence, modifier)
__srcstr :要操作的字符串
__pattern :正则匹配规则字符串
__position :起始位置,1表⽰从第⼀个字符开始匹配
__occurrence :标识第⼏个匹配组,默认为1
__modifier :模式('i’不区分⼤⼩写进⾏检索;‘c’区分⼤⼩写进⾏检索。默认为’c’。)
level解释:
参数level是oracle的关键字,是⼀个伪列,伪劣的数据是oracle⾃动⽣成的,⼀般就是1、2、3等等这样。
⼀般配合connect by⼀起使⽤。
connect by解释:
connect by相当于查询条件,在查询字段中使⽤了level伪列时,必须使⽤connect by作为替代where来筛选伪列的值。
数组转字符串
select wmsys.wm_concat(cityname) from sys_city
where provinceid='29'
 ⼯作中的例⼦:sql如下
<!--查询年级专业所做的⽅案的基本信息:
查专业⽅向码,专业⽅向名称,年级,学位授予,最短修业年限,最长修业年限,学制,国标专业名称以及码,⽅案简介
-->
<select id="querySchemeBasicInfo" parameterType="java.lang.String" resultType="com.ly.education.cultivation.plan.api.vo.SchemeBasicInfoVo">  select
nj.nj as gradeMajorYear,
nj.ZDXYNX as gradeMajorShortStudyLength,
nj.ZCXYNX as gradeMajorLongStudyLength,
nj.XZ as gradeMajorStudyLength,
gbzy.gbzymc as standardMajorName,
gbzy.gbzydm as standardMajorCode,
zyfa.FAJJ as schemeIntroduce,
(
<!-- 根据年级专业⽅向ID查询对应的年级与学⽣类别码从培养⽅案的版本信息表查询版本名称 -->
select
FABBMC
from T_PYFA_BBXX
where SYNF = (
select
NJ
from T_GGZY_NJZYFX@hxsj
where njzyfx_id = #{gradeMajorId,jdbcType=VARCHAR}
)
and XSLBM = (
select
XSLBM
from T_GGZY_NJZYFX@hxsj
where njzyfx_id = #{gradeMajorId,jdbcType=VARCHAR}
)
)as schemeVersionName,
<!-- 因为学位授予门类吗这个字段可能是⼀个以逗号连接的字符串,即⼀个年级专业⽅向可以对应多个学位授予门类,需要t.DMH in⼀个数组 -->
(
select
wm_concat(t.DMMC)
from T_DMK_DMZ@Hxsj t
where t.DMBH='XWSYMLM'
and t.DMH in
(
SELECT
REGEXP_SUBSTR(nj.XWSYMLM, '[^,]+', 1, LEVEL, 'i') AS STR
FROM DUAL
CONNECT BY LEVEL <=
LENGTH(nj.XWSYMLM) - LENGTH(REGEXP_REPLACE(nj.XWSYMLM, ',', '')) + 1)
) as gradeMajorDegreeCategoryName
from T_GGZY_NJZYFX@hxsj nj
left join T_GGZY_ZYFX@hxsj zyfx
on zyfx.ZYFX_ID = nj.ZYFX_ID
left join T_GGZY_GBZY@hxsj gbzy
on gbzy.GBZY_ID = zyfx.GBZY_ID
left join T_PYFA_ZYFAJBXX zyfa
on zyfa.njzyfx_id = nj.njzyfx_id
where nj.njzyfx_id = #{gradeMajorId,jdbcType=VARCHAR} </select>

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。