DBMS_LOB.INSTR - Searching for a pattern
Hi
I have a program supporting several databases. F.ex SQL2000 and Oracle 8/9.
The field in question, text, might contain a lot of characters. In Oracle, it's a CLOB,
on SQL2000 it's a varchar. It is not possible for me to alter the database-structure in
any ways at this moment. The database-schema is locked.
My question is pretty simple, you have probably seen it before.
In SQL2000 I can use this query:
select count(*) from crm5.text where text like 'n%'.
The result returned = 8.
The same on Oracle will be somewhat like:
select count(*) from crm5.text where dbms_lob.instr( text, 'n') > 0
The result returned = 29.
The databases has the same data.
It seems to me that the dbms_lob.instr
does a (case-sensitive) query like this:
select count(*) from crm5.text where text like '%n%
Is this the right assumption? How can I get the correct number
of rows and do the search case-insensitive at the same time not
killing the performance of the database? We use a pretty smart
little thing on "normal" LIKE. But how can we do this with the
CLOB?
Regards,
Ivar
Found the solution.
On Oracle 9, use LIKE as you want.
On Oracle 8, use
select count(*) from crm5.text
where dbms_lob.instr( text, 'N') = 1
or dbms_lob.instr( text, 'n') = 1.
Ivar (same account, different mail-address).
Similar Messages
-
How can I use SQL to search for a pattern within a field?
Hello, Frank, Solomon, ect
I am now faced with this particular scenario, I've got the SQL to search through a field to find text within the field, but I have to know what it is before it can look for it.
What I have to do is this:
Search through a field, for a pattern, and I won't know what the data is I am looking for. Can this be done in SQL?
For instance, Here is my SQL this far, I was helped allot in order to get to this point.
select table_name,
column_name,
:search_string search_string,
result
from (select column_name,
table_name,
'ora:view("' || table_name || '")/ROW/' || column_name || '[ora:contains(text(),"%' || :search_string || '%") > 0]' str
from cols
where table_name in ('TABLE1', 'TABLE2')),
xmltable (str columns result varchar2(10) path '.')
When you execute the above SQL, you have to pass in a value. What I really need is to alter the above SQL, to make it search for a pattern that exist's within the text of the field itself.
Like for instance, lets say the pattern I am looking for is this" xx-xxxxx-xxxx" and it's somewhere in a field.
I need to alter this SQL to take this pattern and search through all the schemas and tables to look for this pattern match.
Can be done?When you use something dynamically within a function or procedure, roles do not apply and privileges must be granted directly. So, you need to grant select on dba_tab_cols directly. If you want to do pattern matching then you should use regular expressions. The following example grants the proper privileges and uses regexp_instr to find all values containing the pattern xxx-xxxx-xxxx, where /S is used for any non-space character. I limited the tables in order to save time and output for the test, but you can eliminate that where clause.
SYS@orcl> CREATE USER test IDENTIFIED BY test
2 /
User created.
SYS@orcl> ALTER USER test QUOTA UNLIMITED ON USERS
2 /
User altered.
SYS@orcl> GRANT CREATE SESSION, CREATE TABLE TO test
2 /
Grant succeeded.
SYS@orcl> GRANT SELECT ON dba_tab_cols TO test
2 /
Grant succeeded.
SYS@orcl> CONNECT test/test
Connected.
TEST@orcl> SET LINESIZE 90
TEST@orcl> CREATE TABLE table1
2 (tab1_col1 VARCHAR2(60))
3 /
Table created.
TEST@orcl> INSERT ALL
2 INTO table1 (tab1_col1) VALUES ('xxx-xxxx-xxxx')
3 INTO table1 (tab1_col1) VALUES ('matching abc-defg-hijk data')
4 INTO table1 (tab1_col1) VALUES ('other data')
5 SELECT * FROM DUAL
6 /
3 rows created.
TEST@orcl> CREATE TABLE table2
2 (tab2_col2 VARCHAR2(30))
3 /
Table created.
TEST@orcl> INSERT ALL
2 INTO table2 (tab2_col2) VALUES ('this BCD-EFGH-IJKL too')
3 INTO table2 (tab2_col2) VALUES ('something else')
4 SELECT * FROM DUAL
5 /
2 rows created.
TEST@orcl> VAR search_string VARCHAR2(24)
TEST@orcl> EXEC :search_string := '\S\S\S-\S\S\S\S-\S\S\S\S'
PL/SQL procedure successfully completed.
TEST@orcl> COLUMN "Searchword" FORMAT A24
TEST@orcl> COLUMN "Table" FORMAT A6
TEST@orcl> COLUMN "Column/Value" FORMAT A50
TEST@orcl> SELECT DISTINCT SUBSTR (:search_string, 1, 24) "Searchword",
2 SUBSTR (table_name, 1, 14) "Table",
3 SUBSTR (t.column_value.getstringval (), 1, 50) "Column/Value"
4 FROM dba_tab_cols,
5 TABLE
6 (XMLSEQUENCE
7 (DBMS_XMLGEN.GETXMLTYPE
8 ( 'SELECT ' || column_name ||
9 ' FROM ' || table_name ||
10 ' WHERE REGEXP_INSTR
11 (UPPER (' || column_name || '),''' ||
12 UPPER (:search_string) || ''') > 0'
13 ).extract ('ROWSET/ROW/*'))) t
14 WHERE table_name IN ('TABLE1', 'TABLE2')
15 ORDER BY "Table"
16 /
Searchword Table Column/Value
\S\S\S-\S\S\S\S-\S\S\S\S TABLE1 <TAB1_COL1>matching abc-defg-hijk data</TAB1_COL1>
\S\S\S-\S\S\S\S-\S\S\S\S TABLE1 <TAB1_COL1>xxx-xxxx-xxxx</TAB1_COL1>
\S\S\S-\S\S\S\S-\S\S\S\S TABLE2 <TAB2_COL2>this BCD-EFGH-IJKL too</TAB2_COL2>
3 rows selected. -
I want to search for a pattern string in the entire registry and need to delete all the keys and sub-keys that contain the pattern. How can I implement this in VB Script or C#? Appreciate if you can give some sample examples. Now every time, I am manually
searching for the pattern in registry and deleting one by one.
Thanks PrasadThere is no built in way to do this. You'll end up having to enumerate all keys and values in the entire registry and comparing each one for a pattern using Regex or similar. This is going to be really slow but there isn't much else you can do about
it (other than parallelize the enumeration). Also note that you won't have permissions to all keys for read and/or write access so you'll need to skip over those using exception handling.
Michael Taylor
http://blogs.msmvps.com/p3net -
Dbms_lob.instr searching backwards
How can I use dbms_lob.instr to locate a string backward? such as "locate the position of the first 'xxx' before the current position (current pos == 88)?
Thanks,
KevinSQL> set serveroutput on size 100000;
SQL> DECLARE
2 str VARCHAR2(100) := 'aiiisalalkjsiiiksjjjslakjsljliiiljflakjfljsldiiiiiisfsljslkjdoooofdiiiiiisfsljslkjdoooof';
3 pos NUMBER;
4 occur NUMBER := 1;
5 subst VARCHAR2(3) := 'iii';
6 BEGIN
7 WHILE instr(str,
8 subst,
9 1,
10 occur) > 0
11 LOOP
12 pos := instr(str,
13 'iii',
14 1,
15 occur);
16 occur := occur + 1;
17 END LOOP;
18 dbms_output.put_line('last occurrence of ' || subst ||
19 ' begins at position ' || pos);
20 END;
21 /
last occurrence of iii begins at position 71
PL/SQL procedure successfully completed
Peter -
InStr search for comma finds period?
Hello,
I am working on a macro in Excel 2007 to find commas in a string.
This:
commaAt = (Len(inp) - InStr(1, strTmp, ",", vbTextCompare))
Returns the location of commas AND periods.
Is there a way to get InStr to find just commas?
I think this may be connected to the mixed use of commas and periods as decimal points.
Curiously, on the worksheet FIND works on only commas with A8 being the string to parse.
RIGHT(A8,(LEN(A8)FIND(",",A8,1)))
Thanks
Hello,
Your question answered my problem. Yikes I was blind. And was seeing what I wanted in Len(inp).
That has to be: Len(strTmp)
inp = "AZ,00000.00,4,aaaaaaaaaaa,bbbbbbbbbbb,cccccccccccc,ddddddddddd,00003,X,X,X,X,X,00<cr><lf>"
I am trimming off comma fields from left to right in a for loop. And the first trim value is 3 which coincidentally matches ".00" the second pass trimmed the correct number of ascii but from the wrong starting point.
I am very sorry to have missed that and posted. I should have gone to bed earlier.
Thank you. -
Search for String patterns in a Database table
Hi
There is a select statement using where condition with a like statement
WHERE table1 <> 'JP'
AND (
( field1 LIKE '%:%' OR field2 LIKE '%:%' )
It fetches records where the field field1 or field2 has string:string as value where string is some set
of characters . What is the equivalent of LIKE in se11 / se12 .
Thanks in advance .
GeethanjaliHello
Try -
Search for a subarray in array
Hi!
Is there a VI or a simple way to search for a subarray in array and to get the index of the subarray? The same thing does DTbl Search for Digital Pattern.vi with digital data and Search 1D Array.vi searches for just one element in the array.
Thank you!
Solved!
Go to Solution.Playing around with Gerd's idea of using the search 1D Array, I came up with this.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
Attachments:
Find Subarray.png 16 KB -
How to search for a particular pattern in a string
Hi,
Hi ,
How to search for a particular pattern in a string?
I heard about java.util.regex; and used it in my jsp program.
Program I used:
<% page import="java.util.regex"%>
<% boolean b=Pattern.matches("hello world","hello");
out.println(b);%>
I run this program using netbeans and am getting the following error message.
"Cannot find the symbol : class regex"
"Cannot find the symbol : variable Pattern "
How to correct the error? -
The search for a perfect design pattern
The search for a perfect design pattern
I am searching tip to upgrade a labview program used. I am looking for the best approach to make
my program more robust and scalable.Software and hardware.
Today the system consists of :
GPS, weather station, ultrasound wind sensor, echosounder and a webcamera, all connected to a computer.
The computer OS is XP pro with Labview version 2009 installed. Except for the webcamera all peripherals have serial communication interface.
The webcamera interface is ethernet.
Device Data type Interval Interface
GPS NMEA string 1 second Serial rs232
Ultrasound wind sensor NMEA string 1 second Serial rs232
Weather, temp,humid NMEA string 35 seconds Serial rs232
Echosounder NMEA string 500ms-5 seconds Serial rs232
(depending of depth)
Webcamera Jpg Snapshot on demand Ethernet
The tasks to be solved
All the data have to be stored.
All the data have to be displayed in real time.
Weather history data must be buffered to be plotted in a graph (pop-up windows).
Absolute wind speed and direction have to be calculated.
Option to send navigation data attached to email at desired time intervals.
Image snapshot at desired time intervals.
The data wich streams into the serial ports are not synchronized and vary in intervals . Would it be a good idea to put all the serial peripherals into a serial device server. Is it possible to let the server place a event in my software, to trigger reading of the data, from the the server. Or how could that be done in other ways?
The perfect design pattern
In version one of the software I use 4 parallel loops to read data at the serial ports, inside these loops the data was separated and outputted to a datasocket server. I used datasocked read in other loops to present and store data. But it did not look good, and yes it was a mess, a really rat nest. I am looking for a better design pattern.
Could some kind of producer/ consumer pattern be the way to go?
Comments and tips are wanted.
TIKNice Project! Congratulations ;-)
I am not an expert for large applications. But your project looks nice and manageable. Here my straightforward ideas:
I would build a GUI, with menu bar, pop-up graph display thing.
THen low level tasks with each one handling a RS232 device and feeding queues or fireing notifications.
Maybe handle the snapshots in an event structure on the GUI blockdiagramm.
When GUI and producer tasks are running, close the gap with a middle layer which captures the data and actualizes GUI by reference. For instance the graph-thing-dialogue triggers a "flush queue" and displays the last 200 entries of the array of data.
I often run into issues when having defined too many userevent structures. I guess i am too stupid for that. Thats why i rather use queues (when i dont want to loose data) or notifiers (data is up-to-date). Nevertheless I like a "stop-all-tasks" user event...traditionally.
My team is actually developing a large application. We are using LabVIEW classes and objects.
So have fun!
Yours
RZM -
hello friends,
I am trying to read a 'C' file and trying to look for all the lines in the 'C' cod, wherever a function call has happened. How could I do that ??
Thanks
ashuimport java.io.*;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.*;
class FileParser{
Scanner sc;
FileParser(String fileName)throws FileNotFoundException{
sc = new Scanner(new File(fileName));
void getFunctions(){
//sc.findInLine("([a-zA-Z]+) (\p{Punct})");
sc.findInLine("");
MatchResult result = sc.match();
//for (int i=1; i<=result.groupCount(); i++)
// System.out.println(result.group(i));//typo in API
//System.out.println(result.group(1));
//System.out.println(result.group(2));
void getLoops(){
//Search for patterns FOR, WHILE, DO-WHILE
sc.findInLine("void");
MatchResult result = sc.match();
for (int i=0; i<=result.groupCount(); i++)
System.out.println(result.group(i));
/* sc.findInLine("main");
result = sc.match();
for (int i=0; i<=result.groupCount(); i++)
System.out.println(result.group(i));
sc.findInLine("void");
result = sc.match();
for (int i=0; i<=result.groupCount(); i++)
System.out.println(result.group(i));
//Search for pattern FOR
void getForLoops(){
//Search for pattern WHILE
void getWhileLoops(){
//Search for pattern DO-WHILE
void getDoWhileLoops(){
//Search for Union
//Search for Struct
}I have added/deleted stuff to try all the different combinations. This class basically will have methods to ....
1) Get a List of Function Calls with Line# in 'C' code
2) Get a List of Loops with Line# in 'C' code
import java.io.*;
class TestScan{
public static void main(String[] args)throws IOException{
FileParser fp = new FileParser("main.c");
// fp.getFunctions();
fp.getLoops();
}Message was edited by:
ashucool83 -
DBMS_LOB.instr (looking backwards for a string)
I am trying to find the position of the first instance of a string ('><'), but staring at a position in the CLOB (not the start) and working backwards
I thought this may work:
num := DBMS_LOB.instr(L_CLOB, '><', 5000, -1);
But unfortunately it returns nothing....
Anyone able to help me?
Thanks,I think you've got the parameters scrambled. Try this:
num := DBMS_LOB.instr(L_CLOB, '><', -1, 1);Cheers, APC -
How do I search for lines with a particular pattern and delete them when a match occurs
How do I search for lines with a particular patter and delete them when a match occurs? For example delete lines containing SUB_NAME = "?" where ? is any string.
How do I search for lines with a particular patter and delete them when a match occurs? For example delete lines containing SUB_NAME = "?" where ? is any string.
Lines in what? And what language are you using to develop with?
Are the lines in a text file? A RichTextBox? A TextBox? Some other control? A List(Of String)?
Is there some expectation by you that by providing what you wrote in your question post that the knowledge in your mind about what you are thinking about will mysteriously emanate to anybody reading your post so all of the sudden your knowledge will
become their knowledge and they will be able to provide you with an answer as they will suddenly understand what you are trying to do? Because that's probably impossible. Most people try providing enough information in a question so anybody, even stupid people
like me, can understand what they want. Maybe you should try that. As well as selecting an appropriate forum for your question in the future. Usually a question like this is related to programming in a particular language therefore a language forum may be
a good choice. Or not.
La vida loca -
Can dbms_lob.instr have end position?
I am extracting data from xml using dbms_lob utility and the pattern in XML is as below.
<Atag>
<Btag>
<Ctag>value</Ctag>
</Btag>
<Btag>
<Ctag>value</Ctag>
<Dtag>value</Dtag>
</Btag>
<Btag>
<Ctag>value</Ctag>
<Dtag>value</Dtag>
</Btag>
</Atag>
I want to extract all tag values inside <Btag> which will be nohting but Ctag and Dtag values. There can be any occurence of <Btag> in this xml. When I use like this,
val:=0;
<LOOP>
val1:=dbms_lob.instr(xml,'<Btag>',val);
val2:=dbms_lob.instr(xml,'</Btag>,val1);
val3:=case(val1) when 0 then 0 else dbms_lob.instr(xml,'<Ctag>,val1) end;
val4:=case(val3) when 0 then 0 else dbms_lob.instr(xml,'</Ctag>,val3) end;
val5:=case(val1) when 0 then 0 else dbms_lob.instr(xml,'<Dtag>,val1) end;
val6:=case(val5) when 0 then 0 else dbms_lob.instr(xml,'</Dtag>,val5) end;
In this case as <Dtag> doesnt exist inside the first occurence of <Btag>, so it gets the value from the next one which is not what I require. I want that to be set to null/zero so for which I want to search only between the first occurence of <Btag> and </Btag>.
I know it is confusing but can some one of you tell me how to go and find the values of <Ctag> and <Dtag> between each occurence of <Btag>. If they are not present I want the value to be set to zero/null.
Thanks in advance.test@ora>
test@ora> @ver1
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
1 row selected.
test@ora>
test@ora>
test@ora> --
test@ora> with t as (
2 select '<Atag>
3 <Btag>
4 <Ctag>Tootsie</Ctag>
5 </Btag>
6 <Btag>
7 <Ctag>Psycho</Ctag>
8 <Dtag>Casablanca</Dtag>
9 </Btag>
10 <Btag>
11 <Ctag>Goodfellas</Ctag>
12 <Dtag>Chinatown</Dtag>
13 </Btag>
14 </Atag>' as x from dual)
15 --
16 select
17 x,
18 regexp_replace(modx,'(.*?)<Btag>(.*?)</Btag>.*$','\2',1,1) as txt1,
19 regexp_replace(modx,'(.*?)(<Btag>(.*?)</Btag>){1}<Btag>(.*?)</Btag>.*$','\4',1,1) as txt2,
20 regexp_replace(modx,'(.*?)(<Btag>(.*?)</Btag>){2}<Btag>(.*?)</Btag>.*$','\4',1,1) as txt3
21 from (
22 select regexp_replace(x,'(>).(<)','\1\2',1,0,'n') as modx, x from t
23 );
X TXT1 TXT2 TXT3
<Atag> <Ctag>Tootsie</Ctag> <Ctag>Psycho</Ctag><Dtag>Casablanca</Dtag> <Ctag>Goodfellas</Ctag><Dtag>Chinatown</Dtag>
<Btag>
<Ctag>Tootsie</Ctag>
</Btag>
<Btag>
<Ctag>Psycho</Ctag>
<Dtag>Casablanca</Dtag>
</Btag>
<Btag>
<Ctag>Goodfellas</Ctag>
<Dtag>Chinatown</Dtag>
</Btag>
</Atag>
1 row selected.
test@ora>
test@ora>
test@ora>@Keith - Regular expressions are from 10g upwards.
isotope -
Dbms_lob.instr question
Hello,
I have a field that holds CLOBs in the database. I have a textfield in which the user can enter a target string, then I hope to use dbms_lob.instr to search for the target string in CLOB. The code looks like: dbms_lob.instr(upper(I.COMMENTS),upper(nvl(:P26_SEARCH_NAME,I.COMMENTS))). If I replace the textfield value :P26_SEARCH_NAME with a string, the line works fine, but the current line returns the error
ORA-22835: Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual: 6250, maximum: 4000) Can someone offer some help with a fix?Steven - Try v('P26_SEARCH_NAME') as a test to see if it makes any difference. If not, I can look at your test case if you put it on apex.oracle.com.
Scott -
How to search for a text node with a particular value in an xml document with labview
supposing i have the following xml document:
<head>
<book>
<bookname>zio</bookname>
<author>dan</author>
</book>
<book>
<bookname>the spear warrior</bookname>
<author>britney</author>
</book>
<book>
<bookname>the beard</bookname>
<author>derrick</author>
</book>
</head>
i want to search for the author of the book "the beard" using for example the V.I Get first match of labview to access the the node with value "the beard" and then use Get next sibling V.I and Get node text content to get get the author of this book..so my question is how do i write the xpath expression for Get first match so as to access the node with bookname "the beard" instantyly? am trying to minimise the use of loops because they increase the time duration,..thank you (NB:i dont want to use Get all Matched V.I because it obliges me to use a loop in order to access the name derrick and this increases the time duration for my v.i)
Solved!
Go to Solution.Since it's all text, why not use a real quick Match Pattern (or Regular Expression, but you don't need that much power here), see attached.
Cameron
To err is human, but to really foul it up requires a computer.
The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
Profanity is the one language all programmers know best.
An expert is someone who has made all the possible mistakes.
To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):
LabVIEW Unit 1 - Getting Started
Learn to Use LabVIEW with MyDAQ
Attachments:
Two-stage match demo.vi 8 KB
Maybe you are looking for
-
Can I have several Time Machines in Mavericks?
I have several boot partitions over several disks. Am I allowed to have more than one Time Machine partition - each backing up different drives? The same question was ever asked against Snow Leopard here, and the answer was no, "You can't have more t
-
With a tab open, for instance, to https://buy.garmin.com/shop/compare.do?cID=145&compareProduct=75228&compareProduct=26876&compareProduct=89557 I can click on a link saying "Custom maps compatible" -- and instead of just going to http://www.garmin.co
-
How to disassemble the Camileo S10?
I would like to hack the S10 to solve 2 problems: 1) Put a wide angle adaptor Actually it is almost impossible, but removing the plastic part in front of objective allow to access to cylindrical part of it and fix a wide angle adaptor 2)I need to fit
-
Hi all, My MacPro seems to be taking longer to start recently and I notice that in the Startup Items list in System Profiler there are a couple of items for Hardware listed, and I don't have the hardware anymore. I'm thinking that these might be the
-
Firefox's installer program does not accept my administrator password. The program won't load. I tried it with version 8 several times a couple weeks ago. Now I just tried it with version 9 a couple times. No luck. I have been using Firefox as my def