Count a certain sign in a string
Hello Forum,
i have a the following query:
-> select doc_ref from file_note where document_nr is not null;
It returns me a result set like this:
DOC_REF
19.01, 13.01
18.01, 18.04, 20.01.01, 20.01.02
05.01, 14.02, 13.01, 17.01, 14.01, 10.05, 15.01
05.01.02
14.01, 14.02, 10.01, 10.02, 10.03, 10.04, 10.07
and so on
Does anybody know, how can i count the commas per row.
This means on the first row there is one comma, on the second are three commas.
How can i build an SQL to retrieve this kind of information.
Regards Stefan
Oracle 11g
with t as (select '19.01, 13.01' col1 from dual
union select '18.01, 18.04, 20.01.01, 20.01.02' from dual
union select '05.01, 14.02, 13.01, 17.01, 14.01, 10.05, 15.01' from dual
union select '05.01.02' from dual
union select '14.01, 14.02, 10.01, 10.02, 10.03, 10.04, 10.07' from dual)
SELECT col1, REGEXP_COUNT(col1,',') from t
05.01, 14.02, 13.01, 17.01, 14.01, 10.05, 15.01 6
05.01.02 0
14.01, 14.02, 10.01, 10.02, 10.03, 10.04, 10.07 6
18.01, 18.04, 20.01.01, 20.01.02 3
19.01, 13.01 1 Oracle 9i:
SQL> ed
Wrote file afiedt.buf
1 with t as (select '19.01, 13.01' col1 from dual
2 union select '18.01, 18.04, 20.01.01, 20.01.02' from dual
3 union select '05.01, 14.02, 13.01, 17.01, 14.01, 10.05, 15.01' from dual
4 union select '05.01.02' from dual
5 union select '14.01, 14.02, 10.01, 10.02, 10.03, 10.04, 10.07' from dual)
6* SELECT col1, LENGTH(col1) - LENGTH(REPLACE(col1,',')) no_of_commas from t
SQL> /
COL1 NO_OF_COMMAS
05.01, 14.02, 13.01, 17.01, 14.01, 10.05, 15.01 6
05.01.02 0
14.01, 14.02, 10.01, 10.02, 10.03, 10.04, 10.07 6
18.01, 18.04, 20.01.01, 20.01.02 3
19.01, 13.01 1
5 rows selected.
SQL> Edited by: AP on Aug 19, 2010 7:49 AM
Similar Messages
-
Getting one character at a certain position from a string array
Hi, i'm new at learning java, but have strong experience at C++ and asm. How would i get one character at a certain positon from a string array.
for example:
String Phrases[] = {"To be or not to be, that is the question","The Simpsons","The Mole","Terminator three rise of the machines","The matrix"};
that is my string array above.
lets say i wanted to get the first character from the first element of the array which is "T", how would i get thisok well that didn't work, but i found getChars function can do what i want. One problem, how do i check the contents of char array defined as char Inchar[];
-
Counting no of digits in a string
Hi all,
Could you please help me on below mentioned one
i need count of digits in the given string
str='' my contact number is 1234567890''
i tried like this
select regexp_count( str,\d) from dual;SQL> var str varchar2(200);
SQL> exec :str :='my contact number is 1234567890';
PL/SQL procedure successfully completed.
select length(ltrim(translate(:str,translate(:str,'0123456789',' '),' '))) cnt from dual;
CNT
10
exec :str :='my number is 9945814523 and my brother number is 9918457853,54';
PL/SQL procedure successfully completed.
select length(ltrim(translate(:str,translate(:str,'0123456789',' '),' '))) cnt from dual;
CNT
22
Message was edited by: Priyasagi -
Count number of characters in a string
Another one for you experts:
Is there a way to count the number of "-" in the strings below:
For instance:
1133500-1-RTN-629-RHR
1133541-10-SRTN-F-630-LR
Should return:
4
5
respectively.
Any ideas?
Thanks in advance,
Zack H.stringvar x := '1133541-10-SRTN-F-630-LR';
stringvar array z := split(x,'-');
ubound(z)-1; -
Match Certain word in a String
Hi all,
I'm actually doing a project regrading e-learning. And i'm suppose to create a set of questions for each topics using labview. So Is there any way that i can match certain word in the string to make sure that answer is correct? Cause i'm sure that every user that input answer will be different. Thus, I want to pick out main point as an answer. Is there anyway i can do it??
Really appreciate your help!!!
Thank you!!
Solved!
Go to Solution.
Attachments:
Match Strings.vi 8 KB
Match Strings.vi 8 KBHere's another option (building on Jeff's code). Turn on the Conditional Terminal on the FOR loop and change it to "Continue if TRUE". This way, the loop will exit as soon as a failure is found. Just pass the result straight out of the loop. If none fail, then the FOR loop will exit on its own (from the auto-indexing) and a pass is passed out.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Attachments:
Match String.png 19 KB -
How to change a certain character in a string?
hi,
how can i change a certain character in a string. Lets say i have a string s="0000" and i want to change the last character (s.charAt(3)) to be a 1. how would i go about doing so?i did this
num.charAt(lspace) = s.charAt(i+1);and am getting an errorThat's because you can't do that. You should go for one of the alternatives mentioned above.
Kaj -
How to count number of words in a string?
Is it only possible by counting the number of white spaces appearing in the string?
Of course that also depends upon how accurate you need to be and what the string contains. It is completely possible that there might be a line break which doesn't have a trailing or leading space.
Like that.
In that case Flash's representation of the string is likely "...space.\n\nLike that.." In chich case "space.\n\nLike" will be a word.
Also if you split on space and there are places where there are two spaces in a row you could inflate your number. So somthing that changes newlines (and returns) to spaces, then removes any multiple spaces in a row, and finally does the split/count thing would be more accurate.
But it all depends upon what you need. -
Count Of each char in a String(Column)
Hi,
I have on column which stores any string.
I need count of each alphabet, repeated how many times.
For Ex:
If a column has value "ORACLE TECHNOLOGY",
O is repeated 2 times, R occurs 1 time, E is repeated 2 time etc.,
Please send the SQL Query for the above problem!!!
Thanks,
regards,
Suman Naidu.SOr..
http://forums.oracle.com/forums/thread.jspa?messageID=
1410941?Nice one Janeesh. I had to laugh though at the number of reponses who were giving PL/SQL answers whilst the OP kept on saying "No, I want a Query" meaning he wanted it just as SQL. Only one person gave a valid answer.
;) -
How to count no. of tokens in a string?
hello everybody?
I am using StringToknizer to read a csv file line by line.
My problem is:
i want to know how many tokens are there in a particular row. How to count it at a streatch?
i am using
<%
if (st.hasMoreTokens())
a3=st.nextToken().trim();
%>i thought of using String.split(), but, i don't know how to use it?(what class to import)
Anyguidence will be appreciated
Thanks for your time.
Regards,
AshviniStringTokenizer will do it for you!
int numberOfTokens = st.countTokens();m -
Method to count number of characters in a string?
hi.
i'm trying to write some script that will count the number of characters in a string passed into a constructor and then compare it against another value to check whether the string passed in is valid.
something like this
public class Stringcheck
public static int maxStringLength;
public static double minSize;
public static boolean testStringLength(String x)
// Insert method for counting number of chars in String x and name as 'int numberOfChars
if(number of Chars <= maxStringLength )
return true;
else
return false;
can someone help me with writing this script.
Thanks
Richard.ummm, you dont need anything fancy. try:
String test = "this is the test string";
int length = test.length(); -
Hi!
I would like to do a String containing the " sign (the quote sign). For instance, I can not write "Hi and welcome to this cool "world" created by me".
You see the word world will be out of this String.
How do I make " signt in quotes in java?
I want to use " and not any other signs like ` or ' .huh? dunno if ur askin for this but.........try \"
-
TextEdit Applescript help counter of certain words
I have tried to modify a script that finds and replaces text. My goal is to count the instances the script finds a word, say "love", and spit out the number of instances that the word "love" appears in the document so I can use it for another subroutine. Any help is appreciated.
I have this as guideline but it seems it does not work.
tell application "TextEdit"
set myCountSign to text of document 1
set myCount to count myCountSign
repeat with this_word in myCountSign
if (this_word as string) is "love" then
set myCount to myCount + 1
end if
end repeat
myCount
end tellThe most obvious problem with your script is the line:
repeat with this_word in myCountSign
This looks at myCountSign (a block of text) and iterates through it assigning each text object to this_word.
The problem is that by default each 'text object' is each character therefore you're comparing each character in the text to the string 'love' which will never, ever match. Even if the word exists you'd be performing a character-by-character comparison.
The simplest fix is to tell AppleScript to look at the words in the text, which is done simply by:
repeat with this_word in (words of myCountSign)
(note you might also need to do this for 'set myCount to count myCountSign' since this will return the character count, not the word count)
There are other, more efficient ways (such as via text item delimiters):
tell application "TextEdit"
set myCountSign to text of document 1
set wordCount to (count words of myCountSign)
set {oldtids, my text item delimiters} to {my text item delimiters, "love"}
log set keywordCount to (count text items of myCountSign) -1
set my text item delimiters to oldtids
display dialog "The document has " & wordCount & " words and " & keywordCount & " occurrences of the word 'love'"
end tell
The text item delimiters approach works by breaking the text into chunks at each occurrence of the delimiter (in this case, the string 'love'). Then all you have to do is count the number of chunks (minus 1) which is a lot quicker than counting all the words, especially for large documents. -
How do count the character in the given string?
hi all,
i have astring like 'AAAARAMARAOAAA'.
i want count how many 'A's in this string using sql statement.Is that a joke? You asked that in a previous thread of yours: how do count how many 'A' s in this string using sql stmt?.
C. -
Query all to display but count only certain criteria
using the following sql statement i can get all the information i want. However since i am decoding the salary_wage how do i count only those items that are over a certain dollar amount?
select lss.job_order_no,
jo.business_no,
bs.business_name,
li.industry_name,
lj.job_title,
js.office_id,
jo.salary,
jo.salary_type,
decode (JO.salary_type,'MONTHLY',JO.salary/173.34,
'BIWEEKLY',JO.salary/80,
'HOURLY',JO.salary,
'ANNUAL',JO.salary/2080) as salary_wage
from link_status_seeker lss,job_order jo,business bs,look_industry li,link_job_order ljo,look_job lj,job_seeker js
where lss.status_date between '06-APR-04' and '20-APR-04'
and jo.job_order_no = lss.job_order_no
and jo.business_no = bs.business_no
AND bs.INDUSTRY_ID = li.INDUSTRY_ID
AND ljo.JOB_ORDER_NO = jo.JOB_ORDER_NO
AND ljo.JOB_ID = lj.JOB_ID
and js.seeker_id = lss.seeker_id
-- and lss.status_id = 105 105 is hiredI dont think your question is clear.
Do you mean you want to put where clause that looks like:
where decode (JO.salary_type,'MONTHLY',JO.salary/173.34,
'BIWEEKLY',JO.salary/80,
'HOURLY',JO.salary,
'ANNUAL',JO.salary/2080) > <some amount>
? if yes, you can do it.
-Bipin. -
Fastest way to count the number of occurences of string in file
I have an application that will process a number of records in a plain text file, and the processing takes a long time. Therefore, I'd like to first calculate the number of records in the file so that I can display a progress dialog to the user (e.g. " 1234 out of 5678 records processed"). The records are separated by the string "//" followed by a newline, so all I need to do to get the number of records is to count the number of times that '//' occurs in the file. What's the quickest way to do this? On a test file of ~1.5 Gb with ~500 000 records, grep manages under 5 seconds, whereas a naive Java approach:
BufferedReader bout = new BufferedReader (new FileReader (sourcefile));
String ffline = null;
int lcnt = 0;
int searchCount = 0;
while ((ffline = bout.readLine()) != null) {
lcnt++;
for(int searchIndex=0;searchIndex<ffline.length();) {
int index=ffline.indexOf(searchFor,searchIndex);
if(index!=-1) {
//System.out.println("Line number " + lcnt);
searchCount++;
searchIndex+=index+searchLength;
} else {
break;
}takes about 10 times as long:
martin@martin-laptop:~$ time grep -c '//' Desktop/moresequences.gb
544064
real 0m4.449s
user 0m3.880s
sys 0m0.544s
martin@martin-laptop:~$ time java WordCounter Desktop/moresequences.gb
SearchCount = 544064
real 0m42.719s
user 0m40.843s
sys 0m1.232sI suspect that dealing with the file as a whole, rather than line-by-line, might be quicker, based on previous experience with Perl.Reading lines is very slow. If your file has single byte character encoding then use something like the KMP algorithm on an BufferedInputStream to find the byte sequence of "//\n".getBytes(). If the file has a multi-byte encoding then use the KMP algorithm on a BufferedReader to find the chars "//\n".getCharacters() .
The basis for this can be found in reply #12 of http://forum.java.sun.com/thread.jspa?threadID=769325&messageID=4386201 .
Edited by: sabre150 on May 2, 2008 2:10 PM
Maybe you are looking for
-
Unable to find file error while loading data from text file to Oracle
Hi, I am having a interface where i am loading a data of Text file to Oracle. But when i am trying to do this i am getting following error. ODI-1227: Task SrcSet0 (Loading) fails on the source FILE connection SAPMM. Caused By: java.sql.SQLException:
-
Apple clearly is a leader and thankfully are bringing fantastic products and initiatives to the market. I certainly hope that the company doesn't get arrogant like it seems to do when forcing people trying to get free apps to put in credit card deta
-
Increasing Processor allocation / speed for encoding / burning Blu Rays
I have several large HDV QT movie files that I have exported from FCP 6.06 and I am burning to BD-R discs using Toast 10.2 and my Lacie external Blu Ray burner. Since Toast uses H.264 it takes quite a while for my PowerBook G4 running Leopard 10.5.8
-
Hypertext Links in PPT with Presenter Quiz breaks Quiz
I have training developed in PowerPoint 2003, using Presenter 7.0.5. I have added hypertext links, which link to hidden slides in the same file. There are also knowledge check questions within each file. When a student clicks on the hypertext link th
-
Why won't my Macbook keyboard work?
My Macbook keyboard is not working. It was fine earlier but upon using it again later I realized that all the letter keys did not work. Whats more is when I try to type with a letter key the mouse cursor vanishes and the trackpad registers single cli