pl sql在查询中获取字符串的x字符

时间:2019-05-19 07:55:43

标签: sql oracle split

  SELECT MR.MUSTERI_ROL_AD  AS ACENTE_AD  , ////HERE\\\\


    (SELECT  mrrt.musteri_rol_ad 
        FROM calisan ct, musteri_rol mrrt, musteri mmt
       where ct.bagli_rol_id = a.acente_id
         AND ct.calisan_rol_id = mrrt.musteri_rol_id
         AND mrrt.musteri_id = mmt.musteri_id 
         AND ct.teknik_personel='H'
         AND ct.calisan_rol_id is not null
        and rownum < 2)Bayi_Yetkili_Kisi,

            ( case when  M.TCK_NO is null then M.VKN_NO 
                  else null end)VKN_NO,

         (Select (SELECT taa.adresi
                FROM tobb_acente ta, tobb_acente_adres taa
               WHERE ta.levhano = a.levha_no
                 AND ta.tobb_acente_sorgu_id = taa.tobb_acente_sorgu_id
                 AND rownum < 2)       
        FROM musteri_adres mat, musteri_rol mrt, musteri mt, adres ad
       WHERE mrt.musteri_rol_id = a.acente_id
         AND mt.musteri_id = mrt.musteri_id
         AND mat.musteri_id(+) = mt.musteri_id
         AND ad.adres_id(+) = mat.adres_id AND rownum < 2) adress,

         (SELECT mi.aciklama
                FROM musteri_iletisim mi, musteri_rol_iletisim mri
               where mi.musteri_id = m.musteri_id
                 AND mi.iletisim_tip_kod =
                     pck_const_iletisim_tip.cep_telefon()
                 AND mri.musteri_rol_id = mr.musteri_rol_id
                 and mi.musteri_iletisim_id = mri.musteri_iletisim_id 
                 and rownum < 2) as CEpTELEFON  ////// HERE  \\\\\



       FROM MUSTERI_ROL MR, MUSTERI M, ACENTE A,SATIS_KANALI SK
       WHERE MR.MUSTERI_ID = M.MUSTERI_ID
         AND MR.MUSTERI_ROL_ID = A.ACENTE_ID
         AND A.SATIS_KANALI_ID = SK.SATIS_KANALI_ID
         AND MR.ROL_ID = 1
         AND A.Uretim_Kaynagi = 'E'
         AND A.UST_ACENTE_ID is null
         AND MR.Ust_Musteri_Rol_Id is null
         AND M.VKN_NO != 'x'
         AND TO_CHAR(TRUNC(MR.Bitis_Tarih), 'DD/MM/YYYY') is null or MR.Bitis_Tarih = SYSDATE 



嗨,我需要一些有关拆分Oracle SQL的帮助,我得到ACENTE_AD x字符,我只想看到前5个字符。我得到CEpTELEFON像012345678一样,我想在列中拆分前3个字符(012),在后一列中拆分最后6个字符(345678)。谢谢。

1 个答案:

答案 0 :(得分:0)

您可以使用substr()字符串操作功能,通过将原始查询视为子查询来在外部select语句中拆分电话值。

SELECT t.Bayi_Yetkili_Kisi, t.Vkn_No, t.Adres,
       substr(CepTelefonu,1,3) as AlanKodu, substr(CepTelefonu,-6) as CepTelefonu
  FROM
  (
    SELECT MR.MUSTERI_ROL_AD AS ACENTE_AD,       
            (SELECT mrrt.musteri_rol_ad
               FROM musteri_rol mrrt
               JOIN calisan ct ON ct.calisan_rol_id = mrrt.musteri_rol_id
               JOIN musteri mmt ON mmt.musteri_id = mrrt.musteri_id
              WHERE ct.bagli_rol_id = a.acente_id
                AND ct.teknik_personel = 'H'
                AND ct.calisan_rol_id is not null
                AND rownum < 2) as Bayi_Yetkili_Kisi,       
           (CASE
             WHEN M.TCK_NO is null THEN
              M.VKN_NO
             ELSE
              null
           END) as Vkn_No,       
           (SELECT (SELECT taa.adresi
                      FROM tobb_acente ta
                      JOIN tobb_acente_adres taa 
                       ON taa.tobb_acente_sorgu_id = ta.tobb_acente_sorgu_id
                     WHERE ta.levhano = a.levha_no
                       AND rownum < 2)
              FROM musteri mt 
              JOIN musteri_rol mrt ON mrt.musteri_id = mt.musteri_id
              LEFT JOIN musteri_adres mat ON mat.musteri_id = mt.musteri_id
              LEFT JOIN adres ad ON ad.adres_id = mat.adres_id
             WHERE mrt.musteri_rol_id = a.acente_id
               AND rownum < 2) as Adres,       
           (SELECT mi.aciklama
              FROM musteri_iletisim mi
              JOIN musteri_rol_iletisim mri ON mri.musteri_iletisim_id = mi.musteri_iletisim_id
             WHERE mi.musteri_id = m.musteri_id
               AND mi.iletisim_tip_kod = pck_const_iletisim_tip.cep_telefon() -- I think the right hand side implies a stored function, doesn't it?
               AND mri.musteri_rol_id = mr.musteri_rol_id
               AND rownum < 2) as CepTelefonu
      FROM MUSTERI_ROL MR
      JOIN MUSTERI M ON M.MUSTERI_ID = MR.MUSTERI_ID
      JOIN ACENTE A ON A.ACENTE_ID = MR.MUSTERI_ROL_ID
      JOIN SATIS_KANALI SK ON SK.SATIS_KANALI_ID = A.SATIS_KANALI_ID
     WHERE MR.ROL_ID = 1
       AND A.Uretim_Kaynagi = 'E'
       AND A.UST_ACENTE_ID is null
       AND MR.Ust_Musteri_Rol_Id is null
       AND M.VKN_NO != 'x'
       AND to_char(trunc(MR.Bitis_Tarih), 'dd/mm/yyyy') is null
        OR MR.Bitis_Tarih = sysdate
) t;

顺便说一句,请考虑使用ANSI-92样式的SQL,而不是使用以前的ANSI-89(上面写有逗号分隔的表)。更加容易编写,理解和维护。