How to return records where the value in column is less than 4 digits using cursor

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • radhekrsna
    New Member
    • Jul 2012
    • 3

    How to return records where the value in column is less than 4 digits using cursor

    Hi!

    I need to right write a query for a cursor that will return records where the value in a certain column is less than 4 digits.

    eg if the value is 0001 or 1234 it will be ignored
    but in case the value is 01 or 123 the record will be returned or stored as per the query.

    please guide me with this.

    thanks in advance

    radhekrsna
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    There's no need for a cursor. Just use the length function to return how long the string is.

    Comment

    • radhekrsna
      New Member
      • Jul 2012
      • 3

      #3
      Hi Rabbit!
      Thank you so much for your reply!

      actually multiple records need to be checked for this condition, so i figured that use of cursor would be required.

      is it possible to acheive this without cursor.

      also i am cofused how can i differentiate between a purely numeric string from one that is alphanumeric? could you please help?

      eg 1234 is fine
      but 12ab or ab12 is returned etc

      thanks in advance!

      radhekrsna

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Cursors are only needed if you need to work between records. If you only need to work within a record, there's no need to use a cursor. Cursors are performance killers, they should be avoided whenever possible. In your case, you've said nothing to indicate that your goal is to work between records so you don't need a cursor.

        You also said nothing before about there being non-numeric data. What you want, in this case, is to use the REGEXP_LIKE operator to look only for 4 consecutive digits.

        Comment

        • radhekrsna
          New Member
          • Jul 2012
          • 3

          #5
          hmm ... let me specify my goal
          I want to perform separate actions on the table when the values in a certain column fall in the following criteria:
          1. when the value is purely alphabetic
          2. when the value is purely numeric and upto 4 digits
          3. when the value is less than 4 digits/characters
          4. when the value is longer than 4 digits/characters


          pls guide me on the best approach to achieve this if not via cursors.

          radhekrsna

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            The answer is in my previous post.

            Comment

            Working...