472,122 Members | 1,415 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,122 software developers and data experts.

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
Jul 31 '12 #1

✓ answered by Rabbit

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.

5 2177
Rabbit
12,516 Expert Mod 8TB
There's no need for a cursor. Just use the length function to return how long the string is.
Jul 31 '12 #2
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
Aug 1 '12 #3
Rabbit
12,516 Expert Mod 8TB
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.
Aug 1 '12 #4
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
Aug 2 '12 #5
Rabbit
12,516 Expert Mod 8TB
The answer is in my previous post.
Aug 2 '12 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

3 posts views Thread by robert | last post: by
2 posts views Thread by A.M | last post: by
kiss07
2 posts views Thread by kiss07 | last post: by
kiss07
2 posts views Thread by kiss07 | last post: by
reply views Thread by sybrandb | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.