ORACLE拼接字符串

1、可以使用“||”来拼接字符串:

select
  b.province || '-' || b.city || '-' || b.Address as location_descr
FROM 
  elearning.Opt_User a 
JOIN 
    elearning.Opt_Training b ON a.Trainingid = b.Id 
JOIN 
    elearning.Core_Userprofile u ON a.Userid = u.Id 
WHERE 
    a.Orgid = '21d0b041-13d4-4670-a107-626443693182' 
AND 
    a.IS_DELETED = 0 
AND 
    b.Type = 0 
AND 
    to_char(a.Updatedate,'yyyy-MM-dd') = '2020-03-18';

2、通过concat()函数实现:

select
  concat(b.province,'@@@@@@') as location_descr
FROM 
  elearning.Opt_User a 
JOIN 
    elearning.Opt_Training b ON a.Trainingid = b.Id 
JOIN 
    elearning.Core_Userprofile u ON a.Userid = u.Id 
WHERE 
    a.Orgid = '21d0b041-13d4-4670-a107-626443693182' 
AND 
    a.IS_DELETED = 0 
AND 
    b.Type = 0 
AND 
    to_char(a.Updatedate,'yyyy-MM-dd') = '2020-03-18';

注意:

      oracle的concat函数只支持两个参数的方法,即只能拼接两个参数,如要拼接多个参数则嵌套使用concat可实现,如:

select
  concat(concat(concat(concat(b.province,'-'), b.city), '-'), b.Address) as location_descr
FROM 
  elearning.Opt_User a 
JOIN 
    elearning.Opt_Training b ON a.Trainingid = b.Id 
JOIN 
    elearning.Core_Userprofile u ON a.Userid = u.Id 
WHERE 
    a.Orgid = '21d0b041-13d4-4670-a107-626443693182' 
AND 
    a.IS_DELETED = 0 
AND 
    b.Type = 0 
AND 
    to_char(a.Updatedate,'yyyy-MM-dd') = '2020-03-18';

你可能感兴趣的:(ORACLE,oracle,数据库)