Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Introduction to regular expressions part4

Aketi JyuuzouJul 6 2010 — edited Jul 22 2010
from 437109

Hi cd_2.
You has not introduced 11gR1 regex new features.
Therefore I will introduce it B-)

***********************************************************************************
RegExp_Count
http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/functions145.htm

Since Oracle11gR1 There is new function RegExp_Count
RegExp_Count counts how many strings which has match pattern.

sampleSQL
select
RegExp_Count('abc','[a-cas cnt1,
RegExp_Count('abc','[ac as cnt2,
RegExp_Count('abc','[0-9as cnt3
from dual;

cnt1  cnt2  cnt3
----  ----  ----
   3     2     0
***********************************************************************************
6th parameter of RegExp_SubStr
http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/functions148.htm

Since Oracle11gR1 There is new 6th parameter at RegExp_SubStr.
This 6th parameter can emulate regex Lookahead and lookbehind.
but This can emulate easy case only.
for ex (?=.*abc)ghi can emulate.
But (?=.*abc)(?=.*def)ghi cannot emulate.

sampleSQL
select
RegExp_Substr('abc1def2','([a-z])[0-9]',1,1,null,1)
as "emulate [a-z](?=[0-9])",
RegExp_Substr('1def2','[a-z]([0-9])',1,1,null,1)
as "emulate (?<=[a-z])[0-9]"
from dual;

e  e
-  -
c  2

Comments

abillconsl
Because Comparator is an interface, not a class. What you did the second time around was flesh it out.

Edited by: abillconsl on Mar 29, 2011 2:35 PM

IOW: compare must be implemented.
796440
abillconsl wrote:
Because Comparator is an interface, not a class. What you did the second time around was flesh it out.
More precisely, it's because Comparator is abstract (as are all interfaces), and the anonymous inner class is concrete, with implementations for all of Comparator's abstract methods. The exact same behavior occurs with abstract classes, and for the exact same reason. :-)
840446
abillconsl wrote:
Because Comparator is an interface, not a class. What you did the second time around was flesh it out.
Oh ok. That makes sense. Just curious. The second block that I wrote is an anon class???
796440
Answer
SquareBox wrote:
The second block that I wrote is an anon class???
Yes.
Marked as Answer by 840446 · Sep 27 2020
abillconsl
Not exactly anon with the named variable SENIORITY_ORDER that you can use as a handle to call compare on it though.
EJP
The 'second block that he wrote' is indeed an anonymous class. Please don't just create confusion.
796440
abillconsl wrote:
Not exactly anon with the named variable SENIORITY_ORDER that you can use as a handle to call compare on it though.
Yeah, it's anonymous. Having a variable refer to it doesn't change that. It's the fact that the class itself is defined inline and has no name that we can use to refer to it that makes it anonymous.
abillconsl
jverd wrote:
abillconsl wrote:
Not exactly anon with the named variable SENIORITY_ORDER that you can use as a handle to call compare on it though.
Yeah, it's anonymous. Having a variable refer to it doesn't change that. It's the fact that the class itself is defined inline and has no name that we can use to refer to it that makes it anonymous.
Of course you're both right, the class has no name - that's the important point. I didn't mean to confuse anyone, and I apologize.

OP, probably, usual practice is that anon classes are declared without a reference variable attached:
new Comparator<Product>() { ... }
As opposed to:
Comparator<Product> SENIORITY_ORDER = new Comparator<Product>() { ... }
Looking at the compiled .class names will usually show though, that, as opposed to a true local class coded more like this:
class MyComparator<String> implements Comparator<String> {
- that has a name:
MyClass$MyComparator.class
The anon class will likely be named as:
MyClass$1.class
Thus the lack of a class name.
796440
abillconsl wrote:
jverd wrote:
abillconsl wrote:
Not exactly anon with the named variable SENIORITY_ORDER that you can use as a handle to call compare on it though.
Yeah, it's anonymous. Having a variable refer to it doesn't change that. It's the fact that the class itself is defined inline and has no name that we can use to refer to it that makes it anonymous.
Of course you're both right, the class has no name - that's the important point. I didn't mean to confuse anyone, and I apologize.

OP, probably, usual practice is that anon classes are declared without a reference variable attached:
I disagree. I don't have solid numbers, but I do know that in my own case, a pretty significant number of my anonymous classes to get a reference variable attached by me at the point I declare them. And even if I don't assign the reference to a variable, whatever I hand that object off to will.
abillconsl
jverd wrote:
abillconsl wrote:
jverd wrote:
abillconsl wrote:
Not exactly anon with the named variable SENIORITY_ORDER that you can use as a handle to call compare on it though.
Yeah, it's anonymous. Having a variable refer to it doesn't change that. It's the fact that the class itself is defined inline and has no name that we can use to refer to it that makes it anonymous.
Of course you're both right, the class has no name - that's the important point. I didn't mean to confuse anyone, and I apologize.

OP, probably, usual practice is that anon classes are declared without a reference variable attached:
I disagree. I don't have solid numbers, but I do know that in my own case, a pretty significant number of my anonymous classes to get a reference variable attached by me at the point I declare them. And even if I don't assign the reference to a variable, whatever I hand that object off to will.
The way I phrased my reply allows anyone to freely disagree, without hard facts. What I meant was simply that in most of the cases a beginner will see - via tutorials for example - will likely be the w/o the ref variable. I say likely, only because that is my own experience. Again, anyone is obviously free to disagree.
EJP
OP, probably, usual practice is that anon classes are declared without a reference variable attached
Except in the other cases. I fail to see the relevance of this remark. His question is about 'comparator object instantation', and this is a perfectly legitimate way to do it, if the Comparator is stateless.
The way I phrased my reply
The way you phrased your reply was that your statement was 'probably' true, and it was indeed 'without hard facts' of your own. Dubious and irrelevant.
YoungWinston
SquareBox wrote:
If yes, then why do I have to use an anon class to instantiate the Comparator object?
Simple answer is: you don't.
This works too:
static final class SeniorityOrder
       implements Comparator<Product>{
   public SeniorityOrder() {}
   public int compare(Product e1, Product e2) {
      return 1;
   }
};
And then whenever you need one, use 'new SeniorityOrder()'. I hope that isn't your actual comparison method though :-).

Winston
1 - 12
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Aug 19 2010
Added on Jul 6 2010
4 comments
4,123 views