Skip to content
Advertisement

Pl sql get x character of a string in a query

  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 



Hi guys i need some help about split in Oracle’s SQL i get ACENTE_AD x character and i wanna see only first 5 character. and i get CEpTELEFON like 012345678 and i wanna split first 3 character(012) in a column and last 6 character(345678) the in other column. thanks.

Advertisement

Answer

You can use substr() string manipulation function to split your phone value in the outer select statement by considering your original query as a subquery.

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;

Btw, Consider using ANSI-92 style SQL rather than former ANSI-89 with comma-seperated tables written like the above one. It’s easier to write, understand and maintain.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement