SQL & PL/SQL :: Finding Number Of Pattern Occurrences In String?

Feb 4, 2012

The code which I am working on consists of an incoming dynamic string which be in the form of binary digits. The max size of the string will be 12 digits. For example, the string can be '111011000001', '000000000000', '111111011111', etc.

I need to find the number of occurences of '111' in the incoming string. Say in the 1st example, result will be 1, in the 2nd example result will be 0, and in the third example, the result will be 3.

I have been trying to capture the string length and replacing the variables '111' to find the number of occurences, but it isn't giving me the result that I want. This is what I have tried

SQL> conn hr/hr
Connected.
SQL> show user
USER is "HR"

[Code]....

I searched the forum and found a similar topic, and following that guideline, I even tried dividing the string with the length of the pattern. It works in some scenarios (the first and second examples mentioned below), while it fails in some scenarios (third example mentioned below)

SQL> select (length('11101110111') - length(replace('11101110111','111','')))/length('111') as occurences from dual;

OCCURENCES
----------
3

SQL> select (length('110111110111') - length(replace('110111110111','111','')))/length('111') as occurences from dual;

OCCURENCES
----------
2

SQL> select (length('111111111111') - length(replace('111111111111','111','')))/length('111') as occurences from dual;

OCCURENCES
----------

SQL>

View 13 Replies


ADVERTISEMENT

SQL & PL/SQL :: Pattern Matching And Updating Of Number Values In String?

Nov 5, 2011

I have a table(PSUSEROBJTYPE) with a long field(PTCUSTFORMAT) containing a row value value in the form:

#1|0|0|0|0|#2|1|0|0|1|#3|1|0|0|0|#4|0|0|0|0

Here, I want to update the above field value to a value in the form:

#2|0|0|0|0|#3|1|0|0|1|#4|1|0|0|0|#5|0|0|0|0

This is nothing but finding each occurrence of (#n) in the above string and replacing it by (#n+1). (i.e #1 is replaced by #2,#2 is replaced by #3).

View 4 Replies View Related

SQL & PL/SQL :: Search For A Pattern And Replace With A String?

Jun 20, 2012

I want to search for a pattern and replace with a string. I can easily achieve the same in oracle 10g with REGEXP_REPLACE , I want to get the similar solution in 9i.

Eg.

I have to search for a string pattern 1234 5678 9012 6736 , I want to replace the same with XXXX XXXX XXXX XXXX.

View 8 Replies View Related

Function To Replace All Occurrences Of A String?

Jan 9, 2007

Years ago, someone created a database in Oracle that was carried over and now sits in Oracle 10g. I am developing an application that queries this database and returns the result as XML.

Many (thousands) of rows have an item description that contains an ampersand. I want each of these pieces of data to have it written as & amp; (had to add a space so it would show up here, but you know what I mean) instead of &, but I don't feel like doing thousands of UPDATEs to change this.

Does Oracle have any global find/replace functions that I can call? I'd rather do one update statement that replaces all occurances of & with & amp; but I can't seem to find a function that will do this.

I'm thinking something that would work like:

UPDATE table SET column1=REPLACE(column1,oldstr,newstr);

View 4 Replies View Related

SQL & PL/SQL :: Find Occurrences Of Some String In DB Objects?

Jul 11, 2012

How can i identify all the occurences of raise_application_error(-20XXX, '<the message>'); within all database objects, and replace them with other text?

View 4 Replies View Related

PL/SQL :: How To Search One String With Various Occurrences Using Regexp_substr

Aug 14, 2012

My Scenario is'....456re0,50kg400,500rfabs43qre30,25kg150,354rf658....'

there is possible,using regexp_substr or other way to get the values, 0,50 and 400,500 and 30,25 and 150,354? I'm using [^re]+[$kg] and the string comes, but only the first occurence..

View 5 Replies View Related

Text :: How To Get Number Of Occurrences Per Document

Nov 8, 2013

I have a table of documents (excel, word, pdf, txt) stored in blob column. I want that SCORE returns the number of occurrences within each document, so I'm using this piece of code: 

SELECT bdt.*, SCORE(1) AS score_1, DBMS_CRYPTO.HASH(archivo, 3) AS cod_hashFROM crg_ctx_archivos_recibidos bdt

WHERE CONTAINS(archivo,'<query>   <textquery lang="SPANISH" grammar="CONTEXT">DEFINESCORE(paz, OCCURRENCE * 0.1)</textquery>    <score datatype="INTEGER" algorithm="COUNT"/></query>', 1) > 0

ORDER BY SCORE (1) DESC; 

However I'm getting a maximum score of 10, but I know one of these documents have 490 matches. How can i get the exact number of matches per document? I'm using Oracle 11.2

View 3 Replies View Related

SQL & PL/SQL :: How To Get Total Number Of Occurrences Based On Value Of Column

Apr 20, 2013

I have a query that should return count the number of rows depending on the value of SLOT. The expected result will be like this:

WIPDATAVALUE SLOT N M
1-2 TRALTEST43S1 1 3
1-2 TRALTEST43S1 2 3
3 TRALTEST43S1 3 3
4-6 TRALTEST43S2 1 4
4-6 TRALTEST43S2 2 4
4-6 TRALTEST43S2 3 4
7 TRALTEST43S2 4 4

The M column is used to count the total number of occurrences of a SLOT. Now, as for the N field, this is used to count the occurrence of the SLOT. In my example for the SLOT TRALTEST43S1, it has three occurrences so M will be 3. Why 3, is because of the WIPDATAVALUE. The WIPDATAVALUE of TRALTEST43S1 is 1-2 and 3. 1-2 WIPDATAVALUE signifies two occurrences (one to two) and 3 signifies only one occurrence. As for N, it should just count the number of occurrence. To further explain, see below:

WIPDATAVALUE SLOT N M
1-2 TRALTEST43S1 1 3 -> First occurrence in the total of 3
1-2 TRALTEST43S1 2 3 -> Second occurrence in the total of 3
3 TRALTEST43S1 3 3 -> Third occurrence in the total of 3
4-6 TRALTEST43S2 1 4 -> First occurrence in the total of 4
4-6 TRALTEST43S2 2 4 -> Second occurrence in the total of 4
4-6 TRALTEST43S2 3 4 -> Third occurrence in the total of 4
7 TRALTEST43S12 4 4 -> Fourth occurrence in the total of 4

This is the query that I have so far:

SELECT DISTINCT
WIPDATAVALUE, SLOT
, LEVEL AS n
, m
FROM
(
SELECT
WIPDATAVALUE
, SLOT
, (dulo - una) + 1 AS m
[code]....

I think that my current query is basing its M and N results on WIPDATAVALUE and not the SLOT that is why I get the wrong output. I have also tried to use the WITH Statement and it works well but unfortunately, our system cant accept subquery factoring.

View 2 Replies View Related

PL/SQL :: How To Get Total Number Of Occurrences Based On Value Of Column

Apr 20, 2013

here on your forum but has been following several threads ever since.So anyway here is the thing, I have a query that should return count the number of rows depending on the value of SLOT. Something like this:

WIPDATAVALUE          SLOT             N            M
1-2                   TRALTEST43S1     1            3
1-2                   TRALTEST43S1     2            3
3                     TRALTEST43S1     3            3
4-6                   TRALTEST43S2     1            4
4-6                   TRALTEST43S2     2            4
4-6                   TRALTEST43S2     3            4
7                     TRALTEST43S2     4            4-----

As you can see above, on the SLOT TRALTEST43S1, there are three occurrences so M (Total number of occurrences) should be three and that column N should count it. Same goes with the SLOT TRALTEST43S2. This is the query that I have so far:

SELECT DISTINCT
WIPDATAVALUE, SLOT
, LEVEL AS n
, m
FROM
(
  [code]...

I think that my current query is basing its M and N results on WIPDATAVALUE and not the SLOT that is why I get the wrong output. I have also tried to use the WITH Statement and it works well but unfortunately, our system cant accept subquery factoring.

View 23 Replies View Related

SQL & PL/SQL :: Finding A String With Different Substrings?

Mar 28, 2012

I tried this query .. but no luck / I know it has some errors

SQL> select invoice_num from ap_invoices_all where rownum < 10 and invoice_num in ('%1%','%2%');

no rows selected

View 9 Replies View Related

SQL & PL/SQL :: Finding Date Value In Given String By Using Regular Expression

Jul 3, 2012

I have a Identifier column with start and stop dates along with description .

Two dates are separated by '-'. But the position of that character(-) is not constant always. Depending on the instr function I am able to divide the start and stop dates. But I am getting the performance problem because of huge data

I think the same logic will be implemented by regular expression also . How to write the equivalent logic by using regular expressions

create table REG_EXP_TEST
(
TRANS_ID NUMBER(10),
TRANS_IDENTIFIER VARCHAR2(250)
) ;
insert into REG_EXP_TEST
(TRANS_ID, TRANS_IDENTIFIER)
values
[code].......

View 3 Replies View Related

SQL & PL/SQL :: Finding Value Of Bits From Hex Number?

Jan 12, 2012

Version : Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production

I have a source which is of datatype RAW(1). Basic requirement is to convert it into binary, and then lookup the value of the 4th and 6th bit. Is this possible using simple SQL ?

Eg.

DataBinary
----- -------
EF1110 1111

From this binary output, i need to find the value of 4th and 5th bit.
So if the 4th bit is 1, I need to perform some operations if 0 then some other.

Create table test_hex_to_bin (col1 raw(1));

INSERT into test_hex_to_bin values ('99');
INSERT into test_hex_to_bin values ('EF');
INSERT into test_hex_to_bin values ('AB');

Basically the output should read as

Bit_number Value
----------------
4 1
5 0

View 5 Replies View Related

SQL & PL/SQL :: Replacing 4 Digit Number In A Given String With The Same Number Incremented By 10000?

Jun 17, 2010

i want to replace 4 digit number in a given string with the same number incremented by 10000.

That mean in the given sting 1201 should be replace by 11201 (Icremented BY 10000).

Input String:

<query><matchAll>true</matchAll><row><columnId>1201</columnId><dataType>31</dataType><op>Like</op><val>North America - Houston</val></row><row><columnId>1212</columnId><dataType>31</dataType><op>!=</op><val>Agreement Date Mismatch</val></row><row><columnId>1212</columnId><dataType>31</dataType><op>!=</op><val>Facility Type Mismatch</val></row><row><columnId>1224</columnId><dataType>31</dataType><op>Like</op><val>y</val></row></query>

Required output :

<query><matchAll>true</matchAll><row><columnId>11201</columnId><dataType>31</dataType><op>Like</op><val>North America - Houston</val></row><row><columnId>11212</columnId><dataType>31</dataType><op>!=</op><val>Agreement Date Mismatch</val></row><row><columnId>11212</columnId><dataType>31</dataType><op>!=</op><val>Facility Type Mismatch</val></row><row><columnId>11224</columnId><dataType>31</dataType><op>Like</op><val>y</val></row></query>

View 7 Replies View Related

Forms :: Finding Out Port Number And Oracle ID For Compilation?

May 21, 2010

Is there any way i could figure out what is the current port number used in an existing setup of oracle forms in a linux server.

Is there any specific oracle id i should use to compile oracle forms on server?

View 5 Replies View Related

SQL & PL/SQL :: Finding Record In Table Having Value For Maximum Number Of Columns

Nov 25, 2011

if there is any inbuilt function or way to find a row in the table that is having value for maximum number of columns.

For example, the table A has 5 columns
(c1,c2,c3,c4,c5) and it has 3 records(r1,r2,r3)
and
r1 has values only for c1,c2
r2 has values only for c1,c2,c3,c4
r3 has values only for c1

so I should get the result as "r3 has values for 4 columns & it is not having value for column c5".

View 4 Replies View Related

Difference Between Number And String?

Oct 20, 2012

I can't understand >>

1. Number 2 is less than number 100,

2. string '2' is greater than string '100'.

>> Numbers are ordered by numerical value; strings are ordered by alphabetical value. >>

View 1 Replies View Related

SQL & PL/SQL :: String Together Number Of LIKEs With ORs

Jun 28, 2010

If I have a "smart" key in a database, say one for which each byte of the key is meaningful, is it generally a good idea to string together a number of LIKEs with ORs? For example, if I want to select people where the last two bytes of that smart code are in a certain list and write:

where smart_key LIKE '%02'
or smart_key LIKE '%03'
or smart_key LIKE '%07'
or smart_key LIKE '%19'
or smart_key LIKE '%23'
or smart_key LIKE '%30'
or smart_key LIKE '%33'
or smart_key LIKE '%34'
or smart_key LIKE '%41'
etc.

Say I string a lot of those together, with 40 or 50 ORs. Right off the bat is it fair to say that's a bad query for Oracle, or do substrings of this sort generally perform well?

View 15 Replies View Related

SQL & PL/SQL :: Converting Number To String?

Apr 27, 2012

I found this query in my sub version repository and really wondering how this working

select to_char(to_date(1000000,'J') ,'JSP') string_value from dual;

View 1 Replies View Related

PL/SQL :: Extract Number From String

Oct 21, 2012

I am using this Regexp to extract numbers from a string, and I doubt that there is a more efficient way to get this done:

SELECT  regexp_replace (regexp_replace ( REGEXp_REPLACE ('  !@#$%^&*()_+= '' + 00 SDFKA 324 000 8702 234 |  " ' , '[[:punct:]]',''), '[[:space:]]',''), '[[:alpha:]]','')  FROM dual
{code}

Is there a more efficient way to get this done ?

View 4 Replies View Related

PL/SQL :: String And Result Number

Jul 9, 2012

Im trying to generate this link on my result [URL].....

materialId and materialFolderId are the results of my query.. Im not sure how to combine my results and string on my query..

View 14 Replies View Related

SQL & PL/SQL :: Find A Negative Number In String?

Apr 24, 2012

I am currently working on a Data Dictionary project where we need to run a few rules against the give data sources to see if they all comply together.

One of the rule is to check if the no. is negative or not. So for that what I tried to do was to check if first the field is number or not and then check on if it is negative or not.

This is the code I am currently trying on and is not looking good.

SELECT 1 FROM DUAL
WHERE decode(DECODE( TRANSLATE('-123.45','-0.123456789',''), NULL, 1,0), 1,substr('-123.45',1,1) ,' ' ) = '-'

View 13 Replies View Related

Reports & Discoverer :: Converting The Number To String

Dec 6, 2010

I wanna convert the amount of money from number to string such as 144.5 to be one hundred forty four point five is there any function or i have to write my function? How could i put new line in the string?

for example if i have 'SAB Bank' || 'Riyadh'

but i want SAB bank to be displayed in line and Riyadh in line.

View 2 Replies View Related

Select Greatest - Difference Between Number And String?

Oct 21, 2012

I am confused with third one.

CODE1. >> Comparing two strings >>
SQL> select greatest('99' ,'100') from dual;
GR
99

2. >> comparing both numbers >>
SQL> select greatest( 99 ,100) from dual;
GR
100

3.>> Comparing string and number >>
SQL> select greatest('99' ,100) from dual;
GR
99

whats the logic behind 99 being returned for thirdone.

View 3 Replies View Related

Count Number Of Lines In Multi Line String

Aug 2, 2007

I have a string like this:

s_list varchar2(234) :=
'asdasd
asfsdf
dsfsdfs
dfsdfs';

How can I find the number of lines in this string? I tried using

INSTR('s_list', '
', 1, 1)

but it gives 0.

Is there any inbuilt function/proc SQL or PL/SQL which can do this?

View 2 Replies View Related

SQL & PL/SQL :: Split String Function For Large Number Of Records?

Aug 6, 2010

I have created a function that is used for splitting a comma separated string & give the output in tabular form.here is the function

Here I have used CLOB as my input string will be huge(greater than max limit of varchar2)

CREATE OR REPLACE TYPE SPLIT_TBL_CLOB AS TABLE OF CLOB;
CREATE OR REPLACE FUNCTION CSVTOSTRING_CLOB
(
P_LIST CLOB,
P_DEL VARCHAR2 := ','
) RETURN SPLIT_TBL_CLOB PIPELINED

[code]....

But here I am facing 2 problems.

1. The function is not accepting a large string & I am getting the error

ORA-01704: string literal too long

2. The function is going for an infinite loop.

View 10 Replies View Related

SQL & PL/SQL :: Concatenate String To Number Field In Update Statement

Oct 4, 2011

I need to concatenate string to the number field in an update statement like this:

update test1 set model_pin = seq_no || '_' || model
where eoc_code like 'AEW%'

When I run this command in sql , I get ERROR at line 1:

ORA-01722: invalid number

View 7 Replies View Related

SQL & PL/SQL :: Count Number Of Words In A String Separated By Comma

Aug 31, 2011

I need writing sql which can return the Count of Comma's in a string. Here is my table and data

CREATE TABLE TEST1(SNO NUMBER,STR1 VARCHAR2(30));

INSERT INTO TEST1 VALUES(1234,'ABCD,LL LT,MP');
INSERT INTO TEST1 VALUES(1456,'PP MR');
INSERT INTO TEST1 VALUES(1589,NULL);
INSERT INTO TEST1 VALUES(1897,'PP MR,FTR CLR ON');

Here is the output I am expecting

SNO STR1 STR1_COUNT
1234 ABCD,LL LT,MP 3
1456 PP MR 1
1589 0
1897 PP MR,FTR CLR ON 2

Basically I need to the count of Words separated by comma

View 9 Replies View Related

SQL & PL/SQL :: Pattern Matching Utility

Jul 2, 2013

I am using 11.2.0.3.0 version of oracle. I have not worked on regular expressions. During working on sql injection, I got set of below patterns which is feeded to some JAVA regx classes or utilityto restrict selective Request, based on patterns.below patterns and the characters which will be restricted by this pattern matching utility.

Given below are 3- patterns:

(.*?[sd)'])(?:AND|OR)(?=[s-+(']|.?d)(s*[-+(]?s*(?:[^s!<>=]+?|'.*?')[s)]*(?:s*(?:(?:[-+/*(.]||s*|)s*)+(?:[^s!<>=]+?|'.*?')[s)]*)*s*)(?: <s*>|>s*=|<s*=|!s*=|=|>|<)(.*)
(.*?[sd)'])(?:AND|OR)(?=[s-+(']|.?d)(s*[-+(]?s*(?:[^s]+?|'.*?')[s)]*(?:s*(?:(?:[-+/*(.]||s*|)s*)+(?:[^s]+?|'.*?')[ s)]*)*s*)(? <=[s)']|d.?)(?:LIKE|IN|BETWEEN)([s-+('].*)
.*[sd)'](?:AND|OR)[(+-s]*(?:'.*?'|.?d[ds-+/*().]*)[)s]*(?:<s*>|>s*=|<s*=|!s*=|=|>|<|LIKE|IN|BETWEEN)[(+-s]*(?:(+s*SELECT)?[(+-s]*(?:'.*?'|.?d[ds-+/*().]*).*

View 1 Replies View Related

Find Objects Containing A Specified Character Pattern

Mar 21, 2011

Is there a method or a tool out there that can do a search through an Oracle Schema to find objects ( tables, fields, stored procedures, etc) containing a specified character pattern ? For example : I would like to return all of the tables that contain fields containing the character string "ABC"

View 1 Replies View Related

SQL & PL/SQL :: Need To Check Pattern Matching Numbers

Apr 19, 2010

I am trying to write a pl/sql script where i need to check pattern matching numbers.My database is oracle 10g and i will put this logic in a procedure.i will pass no of tel_no to get.

if the no is 3 then i need 2072860126, 2072860127 and 2072860128(i.e all 3 in sequence)
if 2 then 2072860126, 2072860127. as such..the selected nos must be in sequence.

A query returns list od tel nos. in that tel i need to choose which staisfy my criteria.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved