ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » count related function in esql

Post new topic  Reply to topic
 count related function in esql « View previous topic :: View next topic » 
Author Message
vijsam
PostPosted: Thu Feb 02, 2012 7:16 am    Post subject: count related function in esql Reply with quote

Apprentice

Joined: 01 Jun 2011
Posts: 46

Hello All,
I need to count how many times a particular character in a string is repeatating,
example want to calculate the number of commas in value like:sam,ram,mbm. need your asisatnce.
Back to top
View user's profile Send private message
Vitor
PostPosted: Thu Feb 02, 2012 7:26 am    Post subject: Re: count related function in esql Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

vijsam wrote:
I need to count how many times a particular character in a string is repeatating,


AFAIK there's no supplied function that does this in ESQL. It would be a trivial task to write your own (I came up with 2 possible methods in 1 sip of coffee).

I'll leave others to comment on the possibilities Java offers. I would imagine there's some kind of tokenising facility & you could count the tokens but I imagine a lot of things that turn out not to be true.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
kash3338
PostPosted: Thu Feb 02, 2012 7:26 am    Post subject: Re: count related function in esql Reply with quote

Shaman

Joined: 08 Feb 2009
Posts: 709
Location: Chennai, India

vijsam wrote:

I need to count how many times a particular character in a string is repeatating,
example want to calculate the number of commas in value like:sam,ram,mbm. need your asisatnce.


You can write a simple function for that in ESQL with a IN parameter as the character to be checked and OUT parameter as the count.
Back to top
View user's profile Send private message Send e-mail
lancelotlinc
PostPosted: Thu Feb 02, 2012 7:28 am    Post subject: Reply with quote

Jedi Knight

Joined: 22 Mar 2010
Posts: 4941
Location: Bloomington, IL USA

Or Java Compute Node.
_________________
http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER
Back to top
View user's profile Send private message Send e-mail
mqsiuser
PostPosted: Thu Feb 02, 2012 7:41 am    Post subject: Reply with quote

Yatiri

Joined: 15 Apr 2008
Posts: 637
Location: Germany

Code:
   CREATE FUNCTION countCharInChar(IN char1 CHAR, IN char2 CHAR) RETURNS INT
   -- Returns the number of occurences of char1 in char2
   -- E.g.:     ('A', 'ABCDABCDABCD')    --> 3
   --           ('ABC', 'ABCDABCD')    --> 2
   --         ...   
   BEGIN     
      DECLARE count INT 0;     
      IF char1 IS NOT NULL AND char2 IS NOT NULL THEN     
         DECLARE position1 INT POSITION( char1 IN char2 REPEAT count+1 );         
         WHILE position1 <> 0 DO
            SET count = count + 1;     
            SET position1 = POSITION( char1 IN char2 REPEAT count+1 );
         END WHILE;
      END IF;   
      RETURN count;
   END;   


Simple things should also be done with care !
_________________
Just use REFERENCEs
Back to top
View user's profile Send private message
adubya
PostPosted: Thu Feb 02, 2012 7:53 am    Post subject: Reply with quote

Partisan

Joined: 25 Aug 2011
Posts: 377
Location: GU12, UK

SET tmpString = REPLACE ( originString, ',' );
SET count = LENGTH ( originString) - LENGTH (tmpString);

or

SET count = LENGTH ( originString) - LENGTH ( REPLACE ( originString, ',' ) );



There are many ways to skin a cat.

Method #54: Sandblasting.
Back to top
View user's profile Send private message Send e-mail
mqsiuser
PostPosted: Thu Feb 02, 2012 8:32 am    Post subject: Reply with quote

Yatiri

Joined: 15 Apr 2008
Posts: 637
Location: Germany

adubya wrote:
There are many ways to skin a cat.


We are searching for the fastest (and most appropriate) approach.

Your approach looks elegant, but manipulating strings (changing a string) can be expensive in memory-space and processing-time. That's why Java has something called a StringBuffer/Builder. The wiki-page says: "In order to insert or remove characters at arbitrary positions, whole sections of arrays must be moved". It works similar with C/ESQL... there actually is a best practice for performance in Broker, which is "try to avoid string manipulation".

Looping with increasing the pos-counter might also get slow (for large strings), I must admit.
_________________
Just use REFERENCEs
Back to top
View user's profile Send private message
vijsam
PostPosted: Fri Feb 03, 2012 12:49 am    Post subject: Reply with quote

Apprentice

Joined: 01 Jun 2011
Posts: 46

Thanku all for the valuable inputs
Back to top
View user's profile Send private message
Vitor
PostPosted: Fri Feb 03, 2012 6:01 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

lancelotlinc wrote:
Or Java Compute Node.


For the record, I deliberately said Java. Perhaps even called as a function from ESQL if you don't want to go JCN.

Is there some kind of tokenizing thing? Not as an answer to the OP but just to see if I was imagining that & need to adjust my medication. Again.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
kimbert
PostPosted: Fri Feb 03, 2012 6:07 am    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

Vitor: Java cannot tokenize stuff. Ever. Please adjust your medication.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Fri Feb 03, 2012 6:33 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

kimbert wrote:
Vitor: Java cannot tokenize stuff. Ever. Please adjust your medication.


No, no. Vitor needs *more* Java...
Back to top
View user's profile Send private message
Vitor
PostPosted: Fri Feb 03, 2012 6:51 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

kimbert wrote:
Vitor: Java cannot tokenize stuff. Ever. Please adjust your medication.




Just when I think I'm getting somewhere....
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
mqjeff
PostPosted: Fri Feb 03, 2012 6:55 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

Vitor wrote:
kimbert wrote:
Vitor: Java cannot tokenize stuff. Ever. Please adjust your medication.




Just when I think I'm getting somewhere....



You should know better than to trust random strangers on the internet...

http://docs.oracle.com/javase/1.5.0/docs/api/java/util/StringTokenizer.html
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » count related function in esql
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.