Top n characters of a string using package
HelloI need to create a package that returns the top n characters that appear in a string. I do this by using a nested table. Can you give me some ideas how I can start? For example, I can return the letter that occurs most in a string, but I'm not able to count all the letters and update my nested table. If I can do that, then I will just need a statement select top n and desc order by the number of appearances to solve this problem.
Thank you in advance for your help!
Andrew.
OK, let's use nested tables:
CREATE OR REPLACE TYPE str_type AS TABLE OF CHAR(1);
/
CREATE TABLE nested_table (str varchar2(2000) , strtab str_type)
NESTED TABLE strtab STORE AS str_tab;
create or replace procedure insert_string(in_str varchar2) is
mystr str_type:=str_type();
begin
for i in 1..length(in_str) loop
mystr.EXTEND;
mystr(i) := substr(in_str,i,1);
end loop;
insert into nested_table values (in_str, mystr);
commit;
end;
/
Then we'll call the insert_string procedure:
exec insert_string('A sample program that uses nested tables and strings')
Finally, we will read the letters more used in the string by using a simple query:
SQL> select column_value letter, count(0) times_used
2 FROM nested_table t1, TABLE(t1.strtab) t2
3 group by column_value
4 order by count(0) desc;
L TIMES_USED
- ----------
8
s 7
a 5
t 5
e 5
n 3
r 3
p 2
g 2
d 2
l 2
m 2
A 1
u 1
i 1
h 1
b 1
o 1
18 rows selected.
Max
Tags: Database
Similar Questions
-
Hi all
I am trying to remove special characters without the help of regular expressions.
translate (the column name or string,'!@#$ & * (* () _) * "" :} {?}) >? /, «, » ')
I want to eliminate this manual process to give all special characters using a chr() or ascii() function.
Please show me the way.
Thanks in advance
Similar to the solution of Michael...
SQL > ed
A written file afiedt.buf1 with t as (select "[it comes of the #] [more amazing!") Test @# "$* & $%) assuming chain cost $ 5 000' double Str)
2, i like (select level 1 c from dual connect by level<=>=>
3 less
4 Select + 32 (level-1) double connect by level<=>=>
5 less
6 select + 58 (level-1) double connect by level<=>=>
7 less
8 select + 91 (level-1) double connect by level<=>=>
9 less
10. Select 123 + (level-1) from dual connect by level<=>=>
11 less
12. Select 255 double
13 )
14, ts as (select level r, substr (str, level 1) c
15 t
16 connect by level<=>=>
17 )
18, tf as (select row_number() (order for r) r
19 ,ts.c
20 TS
21 I join on (i.c = ascii (ts.c))
22 )
23 select replace (sys_connect_by_path(c,'!'),'! ') Str
24 TF
25 where connect_by_isleaf = 1
26 connect r = prior r + 1
27 * start with r = 1
SQL > /.STR
-----------------------------------------------------------------------------------------------------------------------
Thisisthemostamazingtest¸astringcosting5000Or something as horrible as this...
SQL > ed
A written file afiedt.buf1 with t as (select "[it comes of the #] [more amazing!") Test @# "$* & $%) assuming chain cost $ 5 000' double Str)
2, I like (select replace (sys_connect_by_path (chr (c), 'A'), 'A') as tr)
3 of)
4 select c, rownum r
5 (select 32 + (level-1) as the double connection by level c<=>=>
6 union
7 select + 58 (level-1) double connect by level<=>=>
8 union
9 select + 91 (level-1) double connect by level<=>=>
10 the union
11. Select 123 + (level-1) from dual connect by level<=>=>
12 union
13. Select 255 double
14 tri 1
15 )
16 )
17 where connect_by_isleaf = 1
18 log r = prior r + 1
19 start with r = 1
20 )
21 select translate (str, 'A' |) TR, 'A') as str
22 * t, I
SQL > /.STR
--------------------------------------------------------------------
Thisisthemostamazingtest¸astringcosting5000 -
Changeparticular the characters of a string using regular expressions...
Hi all
I'm writing a function using the function of expression regular oracles REGEXP_REPLACE but I could not succeed until now.
My problem is as follows, I have a text in a column say "Scott Sdfdfs Sdfd" I want to replace all the s and S with X characters and make the text looks like "XdfXdf XdfdfX Xdfd".
It is possible by using regular expressions in oracle?
Can you give me some clue?
Thank youselect regexp_replace('sdfsdf Sdfdfs Sdfd', 's|S', 'X') Replaced from dual;
REPLACED ------------------ XdfXdf XdfdfX Xdfd
-
To delete the characters only at the beginning of a string using regexp_replace
I want to be able to delete the characters in a string only until the first numeric value. If it takes place after the digital, I want to keep them.
"for example"AB1234' becomes '1234', 'AB1234C' becomes ' 1234 C.
It might be also spaces and other types of characters at the beginning. I tried this:
Select
regexp_replace ('ABC1234', ' [^ [: digit:]]').
regexp_replace ('AB 1234',' [^ [: digit:]]').
regexp_replace ('AB 01234',' [^ [: digit:]]').
regexp_replace ('AB1234C', ' [^ [: digit:]]').
regexp_replace ('^ 1234', ' [^ [: digit:]]').
regexp_replace ('* #1234Z ',' [^ [: digit:]]')
OF THE DOUBLE
For all except "AB 01234' returned '1234' so it retains the digital. For "AB 01234' it returns correctly '01234'
The bad are those with a character after digital, for example "AB1234C".
I know it I'm missing something here, can someone please help with this?
Thank you
SQL> with t 2 as 3 ( 4 select 'ABC1234' str from dual 5 union all 6 select 'AB 1234' str from dual 7 union all 8 select 'AB 01234' str from dual 9 union all 10 select 'AB1234C' str from dual 11 union all 12 select '^1234' str from dual 13 union all 14 select '*#1234Z' str from dual 15 ) 16 select str 17 , regexp_replace(str, '^[^[:digit:]]+') str_new 18 from t; STR STR_NEW -------- -------- ABC1234 1234 AB 1234 1234 AB 01234 01234 AB1234C 1234C ^1234 1234 *#1234Z 1234Z 6 rows selected.
-
replace characters in the string
Hi all
Is it possible to index the characters in a string as if it were a table and remove them from the second position and now. I just want with the first letter or number so that I can later concatenate strings to it.
Thanks for any help!
-Michael
Hi Michael,
Yes. Use the function "Sring subset. At the beginning the value 0 (default value) and the length of 1.
This will give you the first character in the string.
Steve
-
Formula to replace characters in a string
Hi all
Is it possible to replace characters in a string somewhere if the string has no specific pattern for these characters? I use the replacestr function to replace characters in a string (i.e. ABC), but the chain is in the ABC format * where * are two random characters. The result I'm looking for is to replace ABC * with the NodeID.
ReplaceStr (propvalue (Core.Abbrev), ABC, ID (), T),) This formula works, but is either two additional characters in the end, after ABC. How can I cut that?
Thank you
If)
Not (Equals (Integer, length (PropValue (Core.ABBREV)), length (ReplaceStr (PropValue (Core.ABBREV), ABC, T))),
ReplaceStr (PropValue (Core.Abbrev), PropValue (Core.Abbrev), ID (), T),
PropValue (Core.Abbrev)
)
-
How to remove the first few characters of a string of liquid
I would like to delete the first three characters of a string of liquid. The question is how.
If I use the markup according to liquid when I know what are the first characters
{{it. {{["Estate status'] | strip_html | remove_first:"11."}}
It will remove the 11 characters.
But if I don't know what are the first characters, this markup can I use to get "RID" of the first three characters?
I tried 'split' and 'slice', but it must always know what characters to split or slice.
Thanks for any help.
Kind regards
Carla
Assign a value into slices and you can have table data that you can get out.
-
Bunch of Oracle on the special characters in a string - translate?
How to remove special characters in a string, it can contain. , (space), etc.
SELECT TRANSLATE('123.456 (90-90)', '', '') FROM DUAL
Basically I want to undress and to compare with the db value.
WHERE TRANSLATE(TABLE.NUMCODE, '', '') = TRANSLATE('123.456 (90-90)', '', '')
Use TRANSLATE, since you're on 9i. For example:
TRANSLATE (your_string,'X,. #! % @$ ^ & * () _-+=', 'X')
Removes all the s characters in ', #! % @$ ^ & * () _-+=' of your_string.
SY.
-
How to get the last 3 characters of a string occuring after a character / alphabet without using REGEXP_SUBSTR ? Ex: 10000A001 is the string. Note: - I want to use it in Oracle reports 6i, therefore i cannot use the statement REGEXP_SUBSTR Sanjay
Hello
substr('10000A001',-3)
-
How to remove the first 11 characters of a string
With the help of ' XML Publusher Desktop / generator model for Word / 5.6 Build 45'
I use XML Publisher. With the help of a RTF model, to generate purchase orders by email of the purchase of the Oracle.
The fields are drawn from the XML code generated by Oracle.
One of the fields is the place of delivery Description field.
Will appear in the report as follows:
* & lt;? SHIP_TO_LOCATION_NAME? & gt; *
When I attach a test XML file in Word and view the output, one of my test case returns a description of the site:
DON'T code USE County Hall of Global location
What I have to do is to remove the * DO NOT USE * according to the description of the location.
I could do is a Find / Replace, or a substring to ignore the first 11 characters from the string. But I don't know how to do it.
Any help would be much appreciated, because it is a production problem that is causing a bit of a small problem for us!
Thank you very much.Hello
Maybe you know this syntax :)Rahul
-
Firefox help
Search
"Found 0 results for" my firefox top bar has been changed, I used to be able to get the bookmarks printed Format file, and other services that I have found useful when taking information from the internet, I found bookmarks to the right of the new game to the top, but it seems not instantly friendly where they went, I want that they come back? »
See:
-
Remove 10 characters of this string
How to remove the last 10 characters of any string?
\
Keep throwing me these easier!
-
separate the characters in a string
Hello
Y at - it an easy way of seprerate characters in a string
For example if I have a string 'abcdef '.
I want to seprate it in an array of 7 elements, where each element is a character in the string.
Thank you
Hi reza_sed,
the attached picture shows one solution.
Mike
-
I publish the YEAR edge .oam. In Dreamweaver, I insert .oam and get this error: pathname contains Unicode or characters double - bye, try using ascii.
Thanks Nancy, I managed to do the work. When in DW, I had no defined site and tried to insert the oam in
a new html. As soon as I set up a site and created a new html then oam all the inserts work very well.
Thanks for your help.
-
extract characters from a string
Hi gurus,
I want to extract the first, third, fifth, seventh... characters in a string.
not to extract characters from a subset of characters in a select query in oracle 9i database.
for example (1):
Assume that a string like this "SUE" is that I am 'ACEGI"of the source string
and the source can be any valid string, I just give an example here.
Example (2) of "kalpataru' in klatau'
Please guide me for thisfor 9i:
SQL> with t as ( select 'ABCDEFGHIJ' str from dual union select 'kalpataru' from dual ) -- -- select str, trim(extract(xmlagg(xmlelement(e, substr(str,level,1)) order by level),'//text()')) str2 from t where mod(level,2) = 1 connect by level <= length(str) and prior str = str and prior sys_guid() is not null group by str / STR STR2 ---------- -------------- ABCDEFGHIJ ACEGI kalpataru klaau
Maybe you are looking for
-
Unable to do "in app purchase".
Hello, Apple, I use to make in-app purchase before but now, for some reason, I can't even make any purchase in game. Can you please help me with it?
-
Qosmio F50: screen all in game - driver Win 8 GPU sometimes black
Hello I have problem with my display driver for nvidia geforce 9700M GTS on windows 8 I just installed new Windows 8. Everything works fine on my laptop but there is a big problem.Update of Windows installed new display driver for Nvidia (I think ver
-
How can I restore the function of carrier on my iPad 2?
Since the last update, I've lost the function of carrier on my ipad2, I completed several resets hard. A new SiM card makes a temporal difference, but the function of carrier went, once again. I read that Apple messed up many iPhones but it seems I
-
Can I change the HARD drive integrated on my Satellite L50-B-281?
Hello is it possible to change the HARD disk integrated in an SSD? Must be a SATA3 SSD?Or it is also possible to install an additional HARD/SSD drive? For example the HARD drive now integrated as a data harvester and a SSD as a system drive?Or the DV
-
(File:TrayApp.Cab) not found source file
Hellowhenever I start my laptop window vista family premium 64-bit, it stalls showing the error message I posted on the title of this Question. I always have to keep cancelling several screens repeat until I can use the software that I want.Can anyo