Oracle query with field filter


 
Thread Tools Search this Thread
Top Forums Programming Oracle query with field filter
# 1  
Old 11-26-2014
Oracle query with field filter

Dear community,
I have to make a query from a database and apply the following filter:

Code:
select filed1,field2,field3 
from database 
where (field1 contains only alphanumeric chars and NOT only numbers)

Let me explain better what I Need:
Code:
21test ==> OK
test ==> OK
test21 ==> OK
te21st ==> OK
12345 ==> Exclude it

So in other words, I need every value that contains:
- letters
- letters + number
- NOT ONLY numbers

I believe REG_EXP can help me, something like:
Code:
where REGEXP_LIKE (field1,'^[a-zA-Z]*$')

But in this case I believe only letters will be filtered.

Thanks
Lucas
# 2  
Old 11-26-2014
To have at least one letter somewhere in your field, try
Code:
"^.*[A-Za-z].*$"

EDIT: Sorry, misread your post. Try
Code:
"^[[:alnum:]]*[A-Za-z][[:alnum:]]*$"

but remove the windows style <CR> line terminators first!
This User Gave Thanks to RudiC For This Post:
# 3  
Old 11-26-2014
Hello Lord Spectre,

Following may help you in same. It is just an example.

Code:
echo "121221qdsdwd dejcw23132c" | awk '{if($1 ~ /^[[:digit:]]*$/){next} else {print $0}}'

Output will be as follows.
Code:
121221qdsdwd dejcw23132c

So it is printing only those lines whose 1st field not have only digits.


Thanks,
R. Singh

Last edited by RavinderSingh13; 11-26-2014 at 06:56 AM..
This User Gave Thanks to RavinderSingh13 For This Post:
# 4  
Old 11-26-2014
Thanks both, but I have to implement the expression directly on query and not in post processing. Anyway since I have a large ammount of data, I'll try:
Code:
REGEXP_LIKE (field1,^[[:alnum:]]*[A-Za-z][[:alnum:]]*$)

And the reporting back when the query has finished.

---------- Post updated at 07:04 AM ---------- Previous update was at 05:53 AM ----------

This works perfect
Code:
REGEXP_LIKE (field1,^[[:alnum:]]*[A-Za-z][[:alnum:]]*$)

Thanks RudiC Smilie
# 5  
Old 11-26-2014
Not sure if that would work, but ain't it better (in terms of readability and simplicity) to invert the whole thing and use RavinderSingh13's regex Smilie E.g.
Code:
NOT REGEXP_LIKE (field1,^[[:digit:]]*$)

# 6  
Old 11-26-2014
That would allow for e.g. punctuation or whitespace chars, which are unwanted (see post#1).
# 7  
Old 11-26-2014
Now if going with classes, chase away the A-Za-z in favor of [:alpha:]?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grok filter to extract substring from path and add to host field in logstash

Hii, I am reading data from files by defining path as *.log etc, Files names are like app1a_test2_heep.log , cdc2a_test3_heep.log etc How to configure logstash so that the part of string that is string before underscore (app1a, cdc2a..) should be grepped and added to host field and... (7 Replies)
Discussion started by: Ravi Kishore
7 Replies

2. Shell Programming and Scripting

Shell Script (ksh) - SQLPlus query filter using a string variable

Using ksh, I am using SQLPlus to execute a query with a filter using a string variable. REPO_DB=DEV1 FOLDER_NM='U_nmalencia' FOLDER_CHECK=$(sqlplus -s /nolog <<EOF CONNECT user/pswd_select@${REPO_DB} set echo off heading off feedback off select subj_name from subject where... (5 Replies)
Discussion started by: nkm0brm
5 Replies

3. Shell Programming and Scripting

Filter uniq field values (non-substring)

Hello, I want to filter column based on string value. All substring matches are filtered out and only unique master strings are picked up. infile: 1 abcd 2 abc 3 abcd 4 cdef 5 efgh 6 efgh 7 efx 8 fgh Outfile: 1 abcd 4 cdef 5 efgh 7 efxI have tried awk '!a++; match(a, $2)>0'... (32 Replies)
Discussion started by: yifangt
32 Replies

4. Shell Programming and Scripting

awk : Filter a set of data to parse header line and last field of multiple same match.

Hi Experts, I have a data with multiple entry , I want to filter PKG= & the last column "00060110" or "00088150" in the output file: ############################################################################################### PKG= P8SDB :: VGS = vgP8SOra vgP8SDB1 vgP8S001... (5 Replies)
Discussion started by: rveri
5 Replies

5. Shell Programming and Scripting

Shell Script to execute Oracle query taking input from a file to form query

Hi, I need to query Oracle database for 100 users. I have these 100 users in a file. I need a shell script which would read this User file (one user at a time) & query database. For instance: USER CITY --------- ---------- A CITY_A B CITY_B C ... (2 Replies)
Discussion started by: DevendraG
2 Replies

6. Shell Programming and Scripting

perl- oracle sql query

Hi, I am new to perl.How to query oracle database with perl??? Thanks (1 Reply)
Discussion started by: tdev457
1 Replies

7. Programming

Oracle Database Query

How can i modify the below to search for the things i'm looking for during a certain time frame? select Node, NodeAlias, Summary, Tally, AlertKey, AlertGroup, Manager, Agent from mrtg_alerts where LastOccurrence > '5-Dec-2010' order by Manager desc; In this particular case, this query is... (3 Replies)
Discussion started by: SkySmart
3 Replies

8. Shell Programming and Scripting

Query Oracle tables and return values to shell script that calls the query

Hi, I have a requirement as below which needs to be done viz UNIX shell script (1) I have to connect to an Oracle database (2) Exexute "SELECT field_status from table 1" query on one of the tables. (3) Based on the result that I get from point (2), I have to update another table in the... (6 Replies)
Discussion started by: balaeswari
6 Replies

9. Shell Programming and Scripting

Query regarding date field in shell script

Hi, I wrote a simple shell script which accepts the input value yearmonth in the format YYYYMM and displays the date as YYYY-MM-DD.Day will be 01 always.Please find the code below #!/bin/ksh export yearmonth_date=$1 print_usage() { echo "usage: ${0##*/} <yearmonth_date> \n" \ ... (1 Reply)
Discussion started by: kavithakuttyk
1 Replies

10. UNIX for Advanced & Expert Users

oracle process query !

This query is For HP-UX 11i server. I have certain oracle process that are running on my system as below :- rotmgr 3986 1 0 07:49:33 ? 0:00 oracleedjlive (DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq))) rotmgr 26356 1 0 08:14:32 ? 0:00 oracleedjlive... (4 Replies)
Discussion started by: kpatel786
4 Replies
Login or Register to Ask a Question