How to count number of occurences of a character in a string
I want to get the count of occurences of a character within a string. Is there any function for this or should i go for a PLSQL.
For example is the sting is "occurences" & if i search for character "c", the answer should be 3.
Regards,
Sunil.
SQL> select length('occurence') - length(replace('occurence','c')) from dual;
LENGTH('OCCURENCE')-LENGTH(REPLACE('OCCURENCE','C'))
3
Similar Messages
-
How to count number of occurence of a particular charchter
Hi All,
Anybody there who can help me in counting the no. of occurence of a particular char in a string, with the help of a select query !!!
For example : there is a string 'RAJENDRA'. I want the select query to print 2 in this case without using a pl/sql function.
Thanks & Regards
--DKarHi,
If you are working on 10G you can use below query also.
SQL> ed
Wrote file afiedt.buf
1* SELECT LENGTH(REGEXP_REPLACE('RAJENDRA','+[^R]')) FROM DUAL
SQL> /
LENGTH(REGEXP_REPLACE('RAJENDRA','+[^R]'))
2
SQL>Regards -
How to count number of repeated characters in a String
I have a String.... 10022002202222.
I need to know how many 2's are there in the string... here the string contains eight 2's..
Thanks in advance..it is workingYes, but... attention to surprises...
SQL> var v1 varchar2(1000);
SQL> exec :v1 := 'How to count the number of occurences of a characters in a string';
PL/SQL procedure successfully completed.
SQL> select length(:v1) - length(replace(:v1,'c')) from dual;
LENGTH(:V1)-LENGTH(REPLACE(:V1,'C'))
6
SQL> exec :v1 := 'cccccc';
PL/SQL procedure successfully completed.
SQL> select length(:v1) - length(replace(:v1,'c')) from dual;
LENGTH(:V1)-LENGTH(REPLACE(:V1,'C'))
SQL> select length(:v1) - nvl(length(replace(:v1,'c')),0) from dual;
LENGTH(:V1)-NVL(LENGTH(REPLACE(:V1,'C')),0)
6
SQL> -
How to count number of sales orders generated in a month in SAP SD
Hi SD Gurus,
I have a very strange query from client. I have to count the number of sales order created in a month for a z report. For example 30 in Jan, 25 in Feb etc. Could anyone suggest me How to count number of sales orders generated in a month in SAP SD.
Regards
Vinod KumarHi,
Goto the T.Code "SE16" or "SE16n" or "SE11".
Enter the table name as VBAK
Enter the created on date as the starting date of the period and to date as the end date.
Enter.
Click on "Number of Entries".It will tell you the number of entries created in a particular period.
If you want a report,goto the T.Code "VA05n".
Regards,
Krishna. -
How to Count Number of completed line items in past 6 months / 12 months ?
How to Count Number of completed line items in past 6 months / 12 months ?
Hi,
I am trying to count "Number of Completed Line Items in Purchase Order Document" for my Key Figure ZPO_CNT.
Purchase Order document = ZEBELN
Line Item = ZEBELP.
I need to find and count if the Line Item has been received in the past 6 months from today and similarly in the past 12 months.
I have "Delivery Completed" field, ELIKZ.
So, based on this would I be able to calculate it in Query Designer?
If so, Please let me know howHello Deva
If youe want to calculate the completed line item for last 6 or 12 month then i think u will be displaying the query data for these montrhs...create a customer exit to give you date range and restric it in filter area....
Now Choose any of the below option
1. I would suggest to implement an additional key figure "counter" in cube and fill values with one for which delivery is completed.
Now use calculated key figure in Query Designer based on logic
IF counter = 1 THEN counter ELSE 0
OR
2. create a formula variable based on ELIKZ and use replacement path variable, it will display you no. of docs for which delivery is completed....
Award points if it solves your problem
Revert back in case of further assistance...
Thanks
Tripple k -
How to count number of ones in table
Hello,
i created one table 16x32 each cell is updating 1 byte of data,how to count number of one in all cell,and is it right way to calculate check sum??
thank youThe simplest way is to call GetTableCellRangeValues with VAL_ENTIRE_TABLE as the range, next summing array elements.
But I don't understand your comment on checksum, so this may not be the more correct method for your actual needs: can you explain what do you mean?
Proud to use LW/CVI from 3.1 on.
My contributions to the Developer Zone Community
If I have helped you, why not giving me a kudos? -
How to count number of rows in table
can I get number of row in table except Count(*) in pl/sql
is there any other wayAlso posted and answered here
how to count number of rows in table
count(*) will be the fastest way. It is only slow if the table has a vast number of rows, in which case why do you need to know the tables has 73552436467721 rows and not 73552436467737 rows. It doesn't seem to be much use. Either that or you are counting them a lot, which again seems rather pointless. -
How to count number of online user
i am developing bid application using servlet/jsp. how to count number of online user ple help me.
hi,
may be the following code help you...
import javax.servlet.http.HttpSessionListener;
import javax.servlet.http.HttpSessionEvent;
public class ActiveUserCount implements HttpSessionListener {
private static int activeUsers = 0;
public void sessionCreated(HttpSessionEvent se) {
activeUsers++;
public void sessionDestroyed(HttpSessionEvent se) {
if(activeUsers > 0)
activeUsers--;
public static int getActiveUsers() {
return activeUsers;
}Dhaval -
I need to WAP to count the number of occurences of an alphabet in a string.
I need to WAP to count the number of occurences of an alphabet in a string.I tried a lot and have surfed a lot regarding this problem.
I m not the most proficient with java.but this is all i could come up with,and would appreciate some help here.I hope you guys would help me find a solution to this.
e.g String : abcabrty
Result should be
a:2
b:2
c:1
r:1
t:1
y:1
public class chkoccurences
public static void main(String args[ ])
String user_Data=args[0];
int counter=0;
try
for(int i=0;i<user_Data.length( );i++)
for(int j=0;j<user_Data.length( );j++)
if(user_Data.charAt(i) == user_Data.charAt(j))
counter++;
System.out.println(user_Data.charAt(i)+" exists "+counter+" time(s) in the word.");
System.out.println(" ");
catch(ArrayIndexOutOfBoundsException e)
System.out.println("Check the array size.");
}This is the output i get out of the program:
a exists 2 time(s) in the word.
b exists 4 time(s) in the word.
c exists 5 time(s) in the word.
a exists 7 time(s) in the word.
b exists 9 time(s) in the word.
r exists 10 time(s) in the word.
t exists 11 time(s) in the word.
y exists 12 time(s) in the word.What i think is i need an array to store the repeated characters because the repeated characters are getting counted again in the loop,if you know what i mean.
Please, i would appreciate some help here.Criticism is welcomed
public class tests {
final int min = 10;
final int max = 35;
final char[] chars = new char[] {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
'v', 'w', 'x', 'y', 'z'};
public static void main(String[] args){
tests t = new tests();
String[] strings = new String[] {"aabcze", "att3%a", ""};
for(String s : strings){
System.out.println(t.getAlphaCount(s));
public String getAlphaCount(String s){
int[] alphaCount = new int[26];
int val;
for(char c : s.toCharArray()){
val = Character.getNumericValue(c);
if( (val>=min) && (val<=max)){
alphaCount[val-min]++;
StringBuilder result = new StringBuilder();
for(int i=0; i<alphaCount.length; i++){
if(alphaCount[i] > 0){
result.append(chars[i] + ":" + alphaCount[i] + ", ");
if(result.length() != 0){
result.delete(result.length()-2, result.length());
return result.toString();
} -
Please let me know how to Count Number of completed line items in past 6 mo
How to Count Number of completed line items in past 6 months / 12 months ?
Hi,
I am trying to count "Number of Completed Line Items in Purchase Order Document" for my Key Figure ZPO_CNT.
Purchase Order document = ZEBELN
Line Item = ZEBELP.
I need to find and count if the Line Item has been received in the past 6 months from today and similarly in the past 12 months.
I have "Delivery Completed" field, ELIKZ.
So, based on this would I be able to calculate it in Query Designer?
If so, Please let me know how
KrishnaHi Experts,
I dont have a defined Restricted key figure yet.
I have populated 0COMPL_DEL(Delivery Completed Indicator) and 0EBELN (Purchasing Document Number) and 0EBELP (Line Item Number in Purchasing Document) .
This is what I think how I need to calculate:
Number of completed line items in past 6 months:
If Delilvery Completed Indicator (0COMPL_DEL) = x, calculate No. of Line Items (ZPO_CNT) from 0CALDAY to 6 months
and
Number of completed line items in past 12 months:
If Delilvery Completed Indicator (0COMPL_DEL) = x, calculate No. of Line Items (ZPO_CNT) from 0CALDAY to 12 months
Please let me know if the logic is correct. If so, how I can create this in report -
Function in oracle to find number of occurances of a character in a string
hi,
is there any function in oracle to find the number of ocurrances of a character in a string ?
or is there any simple way of doing the same, rather than writting many lines of code as my program is already very complex.
MariaHi Maria,
I don't know of such a function in Oracle, but maybe you could use this:
length(search_string) - length(replace(search_string, character_to_be_found))
For example: select length('Hello') - length ( replace('Hello', 'l')) from dual;
Hope this is what you're looking for
Danny -
How to count the number of occurences of a character
hi
wat command is used to count the number of occurences of a charcter in a line?
i have to count the number of '.' in a lineFIND
Searches for patterns.
Syntax
FIND <p> IN [SECTION OFFSET <off> LENGTH <len> OF] <text>
[IGNORING CASE|RESPECTING CASE]
[IN BYTE MODE|IN CHARACTER MODE]
[MATCH OFFSET <o>] [MATCH LENGTH <l>].
The system searches the field <text> for the pattern <p>. The SECTION OFFSET <off> LENGTH <len> OF addition tells the system to search only from the <off> position in the length <len>. IGNORING CASE or RESPECTING CASE (default) specifies whether the search is to be case-sensitive. In Unicode programs, you must specify whether the statement is a character or byte operation, using the IN BYTE MODE or IN CHARACTER MODE (default) additions. The MATCH OFFSET and MATCH LENGTH additions set the offset of the first occurrence and length of the search string in the fields <p> and <l>. -
How to find out the number of occurence of special character
Hi ,
I have a string coming coming in I/p which is like '1;2;100;201;'
I need to break up this string and run my process for each value ( i.e for 1,2,100 and 201).
How i can know the count of number of occurences of ';' character?
How i can loop so that it runs once for each value?1. Split, pre Oracle 10g...
===========================
with t as (select '10,aaaa,20,vvvvv,30,xxx''xx,12,12,56' txt from dual)
select substr( txt
, decode(level, 1, 1, instr(txt, ',', 1, level-1)+1)
, decode(instr(txt, ',', 1, level), 0, length(txt), instr(txt, ',', 1, level)
- decode(level, 1, 0, instr(txt, ',', 1, level-1))-1)
) val
from t
connect by level <= length(txt)-length(replace(txt,','))+1
VAL
10
aaaa
20
vvvvv
30
xxx'xx
12
12
56
9 rows selected.2. Split, 10g onwards using regular expressions
===============================================
with t as (select 'aaaa,,bbbb,cccc,dddd,eeee,ffff' as txt from dual)
-- end of sample data
select REGEXP_SUBSTR (txt, '[^,]+', 1, level)
from t
connect by level <= length(regexp_replace(txt,'[^,]*'))+1
REGEXP_SUBSTR(TXT,'[^,]+',1,LE
aaaa
bbbb
cccc
dddd
eeee
ffff
7 rows selected.example usage with varying IN clause...
SQL> ed
Wrote file afiedt.buf
1 select *
2 from emp
3 where ename in (
4 with t as (select '&input_string' as txt from dual)
5 select REGEXP_SUBSTR (txt, '[^,]+', 1, level)
6 from t
7 connect by level <= length(regexp_replace(txt,'[^,]*'))+1
8* )
SQL> /
Enter value for input_string: SCOTT,JAMES
old 4: with t as (select '&input_string' as txt from dual)
new 4: with t as (select 'SCOTT,JAMES' as txt from dual)
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7788 SCOTT ANALYST 7566 19-04-1987 00:00:00 3000 20
7900 JAMES CLERK 7698 03-12-1981 00:00:00 950 30
SQL>3. Split 10g onwards using XMLTABLE...
======================================
SQL> ed
Wrote file afiedt.buf
1 with t as (select 'This is some sample text that needs splitting into words' as txt from dual)
2 select x.*
3 from t
4 ,xmltable('x/y'
5 passing xmltype('<x><y>'||replace(t.txt,' ','</y><y>')||'</y></x>')
6 columns word varchar2(20) path '.'
7* ) x
SQL> /
WORD
This
is
some
sample
text
that
needs
splitting
into
words
10 rows selected. -
How to Count a Characteristic Occurence?
Morning,
I have Assembly(Material) being displayed as a Row item in my query. My need is to count the number of rows for Assembly in the query. I referred to "How to Count" doc, but that counts every occurence of assembly. Whereas, I need to count an Assembly just once.
Can somebody help me on this?
Thanks.Vijay,
Here is how it is desired:
Plant Assembly Count
7835 711712101 1
< > 711712103 1
< > 711712111 1
< > 711712401 1
< > 711713101 1
Can you explain how I can do with this? -
Hi All
If I have 2 tables with records in it, with primary Table A and Foreign key Table B structure.Then how to count the no of occurances of each records of table A in table B and print the values.
ThanxHi,
If I understood you can a query like this:
SGMS@ORACLE10> create table a (cod number);
Table created.
SGMS@ORACLE10> create table b (cod number,id number);
Table created.
SGMS@ORACLE10> alter table a add constraint pk_a primary key (cod);
Table altered.
SGMS@ORACLE10> alter table b add constraint fk_b_a foreign key (cod) references a;
Table altered.
SGMS@ORACLE10> insert into a values (1);
1 row created.
SGMS@ORACLE10> insert into a values (2);
1 row created.
SGMS@ORACLE10> insert into a values (3);
1 row created.
SGMS@ORACLE10> insert into b values (1,1);
1 row created.
SGMS@ORACLE10> insert into b values (1,2);
1 row created.
SGMS@ORACLE10> insert into b values (1,3);
1 row created.
SGMS@ORACLE10> insert into b values (2,1);
1 row created.
SGMS@ORACLE10> insert into b values (3,1);
1 row created.
SGMS@ORACLE10> insert into b values (3,2);
1 row created.
SGMS@ORACLE10> commit;
SGMS@ORACLE10> select b.cod,count(*) from b,a where a.cod = b.cod group by b.cod;
COD COUNT(*)
1 3
2 1
3 2
SGMS@ORACLE10>Cheers
Maybe you are looking for
-
Using iPhote Keywords with PS Elements and visa-versa
Howdy, Does anyone know if you can xfer (import/export) iPhoto keywords to PS Elements 4 or Photo Bridge and visa-versa? Or do you have to create a new Keyword list with Photo Bridge and PS Elements 4
-
After a bit of a struggle I have a Solaris 8 branded zone installed as a cluster resource and it will fail over perfectly happily. However I installed it by the old fashioned method of building the zone, installing it on one node and then adding it a
-
Search implementation on website in oracle site studio
I m new to Oracle Site Studio & Content server and i have to implement search on the site which i have created using Oracle Site Studio designer 11g so can any one please help me out regarding that.It's urgent please. Thanks Regards Vijay Kumar
-
Hello All , I have a specific requirement where I have to give a ranked listing based on the percentages . This is pretty straight forward . To add to the complexity the ranked list should only display top n contributors contributing X percentage of
-
Java log file is duplicated for each run.
Hi all, I am trying to create a file logger,,Following is part of my coding. Now I can see the log file being created. However my problem is that every time I run the process the log is appended to the test.log file correctly. But the problem is that