Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Recursively build a string

Recursively build a string

Scheduled Pinned Locked Moved Database
oracletutorial
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lash20
    wrote on last edited by
    #1

    Hi all, How do you recursively remove the last character from a string in Oracle e.g for string 'HPN12345', I would like to build the following: HPN12345 HPN1234 HPN123 HPN12 HPN1 HPN I know how to do this in Oracle 11 using a recursive common table expression (CTE), but I need to implement this in Oracle 10g (without using a user function). Thanks

    J N 2 Replies Last reply
    0
    • L Lash20

      Hi all, How do you recursively remove the last character from a string in Oracle e.g for string 'HPN12345', I would like to build the following: HPN12345 HPN1234 HPN123 HPN12 HPN1 HPN I know how to do this in Oracle 11 using a recursive common table expression (CTE), but I need to implement this in Oracle 10g (without using a user function). Thanks

      J Offline
      J Offline
      jschell
      wrote on last edited by
      #2

      A while loop based on the length would work.

      1 Reply Last reply
      0
      • L Lash20

        Hi all, How do you recursively remove the last character from a string in Oracle e.g for string 'HPN12345', I would like to build the following: HPN12345 HPN1234 HPN123 HPN12 HPN1 HPN I know how to do this in Oracle 11 using a recursive common table expression (CTE), but I need to implement this in Oracle 10g (without using a user function). Thanks

        N Offline
        N Offline
        Niral Soni
        wrote on last edited by
        #3

        Try this one... Change value of MIN_DEPTH and CHAR_STR as required.

        SELECT SUBSTR(A.CHAR_STR, 0, LENGTH(A.CHAR_STR) - LEVEL + 1) OUTPUT
        FROM (SELECT 'HPN12345' CHAR_STR, 3 MIN_DEPTH FROM DUAL) A
        CONNECT BY LENGTH(A.CHAR_STR) - LEVEL + 1 >= A.MIN_DEPTH;

        Thanks & Regards, Niral Soni

        L 1 Reply Last reply
        0
        • N Niral Soni

          Try this one... Change value of MIN_DEPTH and CHAR_STR as required.

          SELECT SUBSTR(A.CHAR_STR, 0, LENGTH(A.CHAR_STR) - LEVEL + 1) OUTPUT
          FROM (SELECT 'HPN12345' CHAR_STR, 3 MIN_DEPTH FROM DUAL) A
          CONNECT BY LENGTH(A.CHAR_STR) - LEVEL + 1 >= A.MIN_DEPTH;

          Thanks & Regards, Niral Soni

          L Offline
          L Offline
          Lash20
          wrote on last edited by
          #4

          Thanks Niral.. Your code was very helpful. It helped point me in the right direction. Much appreciated!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups