Regular Expression Query for SQL
Hi,
I am working on SQL server and there is a requirement of separating street name and street number.
I tried using regexp_substr but not able to do it perfectly.
Here are some sample names which need cleansing
Full name
street name
street no
Bahnhofplatz 1 / Werkstatt
Bahnhofplatz
1 / Werkstatt
Reinacherstr. 149/151
Reinacherstr.
149/151
Kosuth UCA 7/A
Kosuth UCA
7/A
Route des Jeunes 9 / 6 ème
Route des Jeunes
9 / 6 ème
L'Arcadie / Route de Moudon
L'Arcadie / Route de Moudon
null
Hofstetten 206
Hofstetten
206
Rgds
Amitabh
try this
DECLARE @test TABLE (address VARCHAR(50))
INSERT INTO @test values ('Bahnhofplatz 1 / Werkstatt')
,('Reinacherstr.149 / 151')
,('Kosuth UCA 7 / A')
,('Moudon')
,('L''Arcadie / Route de')
SELECT
Address,
CASE
WHEN patindex('%[0-9]%',address) = 0 then address else substring(address,0,patindex('%[0-9]%',address)) end col1,
CASE WHEN patindex('%[0-9]%',address) >0 then SUBSTRING(address,patindex('%[0-9]%',address),LEN(address)) end col2
from @test
Address col1
col2
Bahnhofplatz 1 / Werkstatt
Bahnhofplatz 1 / Werkstatt
Reinacherstr.149 / 151
Reinacherstr. 149 / 151
Kosuth UCA 7 / A
Kosuth UCA 7 / A
Moudon Moudon
NULL
L'Arcadie / Route de
L'Arcadie / Route de
NULL
--Prashanth
Similar Messages
-
Regular Expression and PL/SQL help
I am using Oracle 9i, does 9i support regular expression? What functions are there?
My problem is the birth_date column in my database comes from teleform ( a scan program that reads what people wrote on paper), so the format is all jacked up.... 50% of them are 01/01/1981, 10% are 5/14/1995, 10% are 12/5/1993, 10% are 1/1/1983, 10% are 24-JUL-98. I have never really used regular expression and pl/sql, can anybody help me convert all of them to 01/01/1998?
Does Oralce 9i support regular expression? What can I do if oralce 9i does not support regular expression? Thank you very much in advance.9i doesn't support regular expressions (at least not in the 10g regular expressions sense. There is an OWA_PATTERN_MATCH package that has some facilities for regular expressions). But it doesn't look like this is a regular expressions problem.
Instead, this is probably a case where you need to
- enumerate the format masks you want to try
- determine the order you want to try them
- write a small function that tries each format mask in succession until one matches.
Of course, there is no guarantee that you'll ever be able to convert the data to the date that the user intended because some values will be ambiguous. For example, 01/02/03 could mean Feb 1, 2003 or Jan 2, 2003 or Feb 3, 2001 depending on the person who entered the data.
Assuming you can define the order, your function would just try each format mask in turn until one generated a valid date, i.e.
BEGIN
BEGIN
l_date := TO_DATE( p_string_value, format_mask_1 );
RETURN l_date;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
BEGIN
l_date := TO_DATE( p_string_value, format_mask_2 );
RETURN l_date;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
BEGIN
l_date := TO_DATE( p_string_value, format_mask_3 );
RETURN l_date;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
BEGIN
l_date := TO_DATE( p_string_value, format_mask_N );
RETURN l_date;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
RETURN NULL;
END;Justin -
Hi,
I'm trying to execute some SQL queries and I just don't understand what's wrong.
I�m using Tomcat and SQL Server in order to do this, but when I�m try to execute a query with a INNER JOIN statements Tomcat raise a SQL exception... at the very first time I thought there was a problem with database connection but I realize that a simple query to a table works pretty well. then I found out some problems with JDBC:ODBC.... so I install JDBC for SQL Server 2000 and test with the same simple query and works..... so, I come to a conclusion.... INNER JOIN or JOIN statements can't be used in JDBC..... please... somebody tell I�m wrong and give me a hand...
I'm using TOMCAT 4 and JDK 1.4 SQL Server 2000
Error occurs when executeQuery() is called.... not prepareStatement().... ??????
Driver DriverRecResult = (Driver)Class.forName(driver).newInstance();
Connection ConnRecResult = DriverManager.getConnection(DSN,user,password);
PreparedStatement StatementRecResult = ConnRecResult.prepareStatement(query);
ResultSet RecResult = StatementRecResult.executeQuery(); <---- Exception raise here
So much tahnks in advance,That's exactly what I think, driver it's raising the exception, but I don't know why.... i test the same query with INNER JOIN directly from SQL Query Analyser and it's works perfectly, my problem ain't SQL, but JSP and JDBC 'cause i'm a newbie about these issues.
Common sense tell me possible problems lie in SQLServer drivers 'cause i run the same pages on JRUN through jdbc:odbc and do works well, but by now i just depend on Tomcat.....
I've installed SQL Server drivers for JDBC but i just find it doesn't work fully... could be the version of JDK i've installed? what version do i need?
( I'm running Tomcat 4 with JDK 1.4 & SQL Server 2000 W2K )
thanks for reply. -
Outer join query for SQL server from Oracle
Hi All,
My question is regarding making queries from Oracle to SQL Server database thorugh DBLink.
In my oracle database I have a DBLink emp.world for SQL Server database.
I need to query SQL Server data from oracle (so that this query can be combined with other oracle tables).
Query is given below:
SELECT
a."EmpID" as "Employee ID",
a."EmpStatus" "Employee Status"
b."EmpSub" as "Employee Subjects"
FROM
[email protected] a
left outer join [email protected] b on a."EmpID" = b."suEmpID"
ORDER BY a."EmpID";My problem is when I run the same query from oracle, it does not show the EmpID that does not exist in Subjects table, but when run from actual SQL Server database, it shows all the records.
Samples are given below:
Run from Oracle
Employee ID Employee Status Employee Subjects
101 Active Maths
102 Active Maths
102 Active Physics
104 Inactive Chemistry
Run form SQL Server
Employee ID Employee Status Employee Subjects
101 Active Maths
102 Active Maths
102 Active Physics
103 Active NULL
104 Inactive ChemistryI am not sure why in oracle outer join for SQL server tables is not working. What is the right way for outer join in this case.
I am using oracle database 10gR2 and SQL Server 2005.
Please Help.
Thanks.SELECT
a."EmpID" as "Employee ID",
a."EmpStatus" "Employee Status"
b."EmpSub" as "Employee Subjects"
FROM
[email protected] a
left outer join [email protected] b on a."EmpID" = b."suEmpID"
ORDER BY a."EmpID";
http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm#sthref3175
From your description, it appears you may need a right outer join. You want to get back all the rows from 'B', not from 'A'. Try a right join and let us know. -
Error on Expression Query - java.sql.SQLException: DSRA9420E
We are getting the below error when we execute an Expression query. Other queries seem to be working fine.
Has anyone seen this error?
Any help or suggestions are welcome.
Thanks
ERROR -
java.sql.SQLException: DSRA9420E: Connection cannot be reassociated because child objects are still open.
at com.ibm.ws.rsadapter.AdapterUtil.toSQLException(AdapterUtil.java:1376)
at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.reactivate(WSJdbcConnection.java:2201)
at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.prepareStatement(WSJdbcConnection.java:2070)
at com.ibm.ws.rsadapter.jdbc.WSJdbcConnection.prepareStatement(WSJdbcConnection.java:2039)
at oracle.toplink.internal.databaseaccess.DatabaseAccessor.prepareStatement(DatabaseAccessor.java:1295)
at oracle.toplink.queryframework.SQLCall.prepareStatement(SQLCall.java:185)
at oracle.toplink.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:635)
at oracle.toplink.threetier.ServerSession.executeCall(ServerSession.java:506)
at oracle.toplink.internal.queryframework.CallQueryMechanism.executeCall(CallQueryMechanism.java:134)
at oracle.toplink.internal.queryframework.CallQueryMechanism.executeCall(CallQueryMechanism.java:115)
at oracle.toplink.internal.queryframework.CallQueryMechanism.executeSelectCall(CallQueryMechanism.java:197)
at oracle.toplink.internal.queryframework.CallQueryMechanism.selectAllRows(CallQueryMechanism.java:567)
at oracle.toplink.internal.queryframework.ExpressionQueryMechanism.selectAllRowsFromTable(ExpressionQueryMechanism.java:732)
at oracle.toplink.internal.queryframework.ExpressionQueryMechanism.selectAllRows(ExpressionQueryMechanism.java:707)
at oracle.toplink.queryframework.ReadAllQuery.execute(ReadAllQuery.java:447)
Edited by: amehta5 on Apr 12, 2012 12:13 PMIt seems like your connection pool is having issues. How have you configured your connections?
It seems that WebSphere connection pool is performing some sort of statement cache, and the cache statement it is trying to use is still in use. -
Regular Expression Search for Case Statement in VBA
Hi,
I'm having trouble trying to use regular expressions in a case statement. I have a CSV spreadsheet of a server's netstat output and am trying to plot everything into Visio. I have been able to do that, however I'm not trying to expand this capability and
resuse the same code for many different servers.
I have the mainServer variable set as a Variant and in my current example it is set as "INTPXY001" (internal proxy server 001). I have tried different regex statements for the potential to have INTPXY001 - INTPXY999, EXTPXY001 - EXTPXY999, and
SVCPXY001 - SVCPXY999 in place of the Case "INTPXY001", but nothing I have tried seems to work.
'========================================
Set mainServer As Variant
Set AppVisio = CreateObject("visio.application")
AppVisio.Visible = True
AppVisio.Documents.AddEx "", visMSDefault, 0
AppVisio.Documents.OpenEx "server_u.vss", visOpenRO + visOpenDocked
mainServer = ActiveSheet.Cells(1, 2) 'sets mainServer to INTPXY001
With AppVisio.ActiveWindow.Page
Select Case mainServer
Case "INTPXY001"
.Drop AppVisio.Documents.Item("SERVER_U.VSS").Masters.ItemU("Proxy server"), 2.25, 9.25
Case Else
.Drop AppVisio.Documents.Item("SERVER_U.VSS").Masters.Item(("Server"), 2.25, 9.25
End Select
End With
'========================================You cannot declare variables As Variant in VBScript. All variables in VBScript are implicitly variants.
If you are asking about VBA (Visual Basic for Applications), then you're not asking in the correct forum.
-- Bill Stewart [Bill_Stewart] -
Indexing on regular expression seach for dynamic pattern
Hello All,
Would it be possible to create any index for regular expression search (REGEXP_LIKE) for 'dynamic' pattern?
If the pattern is static, then we can create FBI, but is there any way for dynamic patterns? Please advise.
Regards,
HariThanks Dom, I have never used Oracle Text. Would it be possible to provide some sample code for above requirement.
Regards,
Hari -
Regular expression: check for the presence of special characters.
I have the following requirement:
I need to check for the presence of the following characters in a keyword: @, #, > if any of these characters are present, then they need to be stripped off, before going further. Please let me know the regular expression to check for these characters.I am trying to extend the same logic for the following characters:
.,?!@#%^&*()-~<>[]{}\+=`©® . here is the code fragment:
Pattern kValidator = Pattern.compile("[\\.,\\\\?!@#%^&*()-~<>[]{}\\+=\\`©®]");
Matcher kMatcher = kValidator.matcher(keyWord);
if (kMatcher.find(0)) {
keyWord = keyWord.replaceAll("[.,\\\\?!@#%^&*()-~<>[]{}\\+=\\`©®]", " ");
}I get the following error. This error is from the weblogic command window. I dont understand these special characters.
Error:
28 Oct 2008 12:27:48 | INFO | SearchController | Exception while fetching search results in controller:Unclosed character class near index
39
[\.,\‘\“?!@#%^&*()-~<>[]{}\+=\`©®]
^
java.util.regex.PatternSyntaxException: Unclosed character class near index 39
[\.,\‘\“?!@#%^&*()-~<>[]{}\+=\`©®]
^
at java.util.regex.Pattern.error(Pattern.java:1650)
at java.util.regex.Pattern.clazz(Pattern.java:2199)
at java.util.regex.Pattern.sequence(Pattern.java:1727)
at java.util.regex.Pattern.expr(Pattern.java:1687)
at java.util.regex.Pattern.compile(Pattern.java:1397)
at java.util.regex.Pattern.<init>(Pattern.java:1124)
at java.util.regex.Pattern.compile(Pattern.java:817) -
Passing regular expression backreference to SQL function
Does anyone know if it is possible to pass a regular expression backreference to an SQL function?
When I try this:
SELECT REGEXP_REPLACE('/abc/23468/xyz1/10/', '(/)([[:digit:]]+)', '\1'||LENGTH('\2')) FROM dual;
I am getting this back:
/abc/2/xyz1/2/
Here LENGTH function takes backreference '\2' literally as a string and does not replace it with the actual value.
Hence, it always returns length of 2 instead of the correct value.
However, if do this
SELECT REGEXP_REPLACE('/abc/23468/xyz1/10/', '(/)([[:digit:]]+)', '\1'||SUBSTR('\2',0)) FROM dual;
I get the right result back
/abc/23468/xyz1/10/
So, SUBSTR works correctly.
Why do LENGTH and SUBSTR handle backreference diffrently?
I am using Oracle 10.2.
Appreciate any help on this.How about this?
CREATE OR REPLACE FUNCTION fmt_string(
p_Source IN VARCHAR2,
P_Delim IN VARCHAR2 DEFAULT '/'
) RETURN VARCHAR2
IS
v_Start PLS_INTEGER;
v_Pos PLS_INTEGER;
v_Len PLS_INTEGER;
v_String VARCHAR2(4000);
v_Result VARCHAR2(4000);
BEGIN
v_Len := LENGTH(p_Source);
v_Start := 1;
WHILE v_Start <= LENGTH(p_Source)
LOOP
v_Pos := INSTR(p_Source, p_Delim, v_Start);
IF v_Pos = 0 THEN
v_Pos := v_Len;
END IF;
v_String := SUBSTR(p_Source, v_Start, v_Pos - v_Start);
IF REGEXP_LIKE(v_String, '^[0-9]+$') THEN
v_String := TO_CHAR(TO_NUMBER(v_String), 'fm0000000000');
END IF;
v_Result := v_Result || v_string || p_Delim;
v_Start := v_Pos + 1;
END LOOP;
RETURN v_Result;
END fmt_string;
/using it this way:
SELECT fmt_string('/abc/23468/xyz1/10/')
FROM dual;You could put that function also into a PACKAGE.
C. -
How about the statement of regular expression like for this
I what to get varians String array by one regular express for the statement like:
${user} like play ${game} in ${date}
I want to get String[] as {"user","game","date"} by one regex, by str.split(regex). I tried many times but always fail to get the result I expected. May it be possible to meet the destination?
thanks in advance
Frederickwhy StringBuffer was using here?So one could split the pattern into multiple lines. But it just occurred to me that one could just use string concatenation, which would look better. I don't know why I bothered to use StringBuffefer.
e.g.:
String pattern =
"^" + // the start of a string
"(dog)|(cat)" + // match either "dog" or "cat" at the start of the line
"\\s*" + // match an arbitrary amount of whitespace
"$"; // but don't allow anything other than whitespace after dog or cat
Pattern p = Pattern.compile(pattern);
Pattern p = Pattern.compile("^(dog)|(cat)\\s*$");> isn't this look more simpler and better?
In this case, yes. I was looking for a way to make regexps more explicit, with whitespace and comments, for more complicated cases.
But those double quotes and plus signs add ugliness of their own, so a regexp would have to be pretty complex before it would be an improvement. -
Regular Expression query help.
Hi, your help will be appreciated,
I need to replace the a string's pattern with some special characters.
Input String := 'mytext*% align="quot;leftquot;><font face="quot;Arialquot;"> *% align="quot;leftquot;"><this is text><p this to replace >'
Output String := 'mytext@ align="quot;leftquot;$<font face="quot;Arialquot;"> @ align="quot;leftquot;"$<this is text><p this to replace >'
Replacing Rules:
1) '*%' should be replaced by '@'
2) '>' should be replaced by $ (only the EVERY FIRST occurrence after the character @ )
Tried with REGEXP but looks like need your help!
Thx
DJ.Hi, DJ,
DeeJay wrote:
Perfect Frank. Thanks for your help.
Could you please explain how it is working? you know, these Regexps are hurdle for me always in understanding.Not just you; regular expression can be very cryptic.
We're saying "replace '*%x>' with '@x$', where x is 0 or more characters from the set of all characters except '>'.
{code}
SELECT REGEXP_REPLACE ( 'mytext*% align="quot;leftquot;> *% align="quot;leftquot;"><this is text>'
, '\*' || -- aserisk (special character, must be escaped)
'%' || -- percent sign
'(' || -- begin \1 definition
'[' || -- begin set definition
'^' || -- "The set consiting of all characters EXCEPT ...
'>' || -- ... the greater-than sign"
']' || -- end set definition
'*' || -- 0 or more characters from the preceding set
')' || -- end \1 definition
'>' -- greater-than sign
, '@\1$'
) AS txt
FROM dual; -
How to use regular expression replace for this special characters?
hi,
I need to replace the below string, but i couldnt able to do if we use the special charaters '+', '$' . can anyone suggest a way to do this?
select REGEXP_REPLACE('jan + feb 2008','jan + feb 2008', 'feb',1,0,'i') from dual
anwers should be :- febyou should use escape character \.
the regular expression will look like as follows:
select REGEXP_REPLACE('jan + feb 2008','jan \+ feb 2008', 'feb',1,0,'i') from dual
hope this is what you needed.
cheers,
Davide -
Regular Expression Required for Checksum variable
I am wanting to create a regular expression that extracts a variable checksum value (cs=) which is unique to a given server response string.
The issue I am having is that a simple regex being name="cs" value="(.+?)" just does not work because there are 18 different checksum values being returned per session id/server response.
So a simple regex just picks up any "cs" value and I guess gets confused since there are 18 different ones contained within the server response (all user related)
What i need is a regex to use say this value from the server response (JONHONEYMAN%40YAHOO.COM) or any other unique value which is contained within the string response from the server then extract the cs (Checksum) value from that string and make it variable :)
Here is the server response string:-
"fp=220:1200:2977638312763704:: NO::P1200_EMAIL_ADDRESS,P1200_ORGANISATION_NAME,P1200_UCRN,P1200_ORG_ID,P1200_CALLING_PAGE:JONHONEYMAN%40YAHOO.COM%2C john%20Honeyman%2C260%2C220%2C1190&cs=336788D01EC6E80B1877B3EE982E8B2D8" >Select</td></tr
can anyone help?
ThanksYou need an XML Parser.
-
We will have below data in one column
++77++
++34_
--9--
98
999
+00_
My requirement is to fetch only number from above data. please find output i want from each data
++77++ -> 77
++34_ -> 34
--9-- -> 9
98 -> 98
999 -> 999
+00_ -> 00
Please provide the query for the same.
ThanksWorks on 10g or higher:
with data as
select '++77++' col from dual union all
select '++34_' col from dual union all
select '--9--' col from dual union all
select '98' col from dual union all
select '999' col from dual union all
select '+00_' col from dual
select col, regexp_substr(col, '[[:digit:]]+') col
from data;
COL COL
++77++ 77
++34_ 34
--9-- 9
98 98
999 999
+00_ 00 -
Regular Expressions Query!! -- Help
Hi,
I'm writing a SQL query using Regualar Expressions in Oracle 10g.
select entry_id,entry_value, from entry_logbook where REGEXP_LIKE(entry_value,'^[a-z]|[0-9]|[A-Z]')
I expect the result contains only records with values starting with alphabets or integers.
But I'm getting values like '** Something **', '#123445' etc.
Please let me know what I'm missing here.
Regards,
VenkatSQL> with sample as
2 (select '##@Sarma123%$%$' col from dual
3 union all
4 select 'sarma' from dual
5 union all
6 select '123SARMA' from dual
7 union all
8 select 'RADHA' from dual
9 )
10 select col
11 from sample
12 where regexp_like (col, '^[a-z0-9A-Z]')
13 /
COL
sarma
123SARMA
RADHA
SQL>Cheers
Sarma.
Maybe you are looking for
-
Error 00-341 RAISE_EXCEPTION when using Call Transaction for VA01 in backgr
Hi, I am getting this message when I use call transaction to create a sales order using VA01. Following is the statement I have used. Note that when i execute the program online, I am not getting any errors. I could create sales order without any pr
-
We have 2 load balanced application servers that map drives with programs on them for users from a central server that are giving the warning "We can't verify who created this file. Are you sure you want to run this file?". Basically how it works is
-
Give me some Cool link for forms 6i designing
Can any body give me cool links for forms 6i sample forms.I need cosmetics samples (for look and feel) not functional samples. Khurram
-
Hello i have installed above CC and without my knowledge the machine has now adobe cc and cc 2014 how can i remove the CC and move the lug ins to the new CC 2014
-
Report of projects across cost centers and vice versa
Hi friends, Do we have any standard report of Projects across Cost Centers and vice versa? In our case, it is statistical cost center postings and real project postings. How can we get a standard report of Projects across Cost centers ? thanks in adv