Searching a string in a table.
Hi,
I am using Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production.
I have a situation where I need to find the number of occurrences of a string that is present in a table having comma separated values. To explain with an example:
create table test_data ( textfield varchar2(100));
insert into test_data values('DM,HM');
insert into test_data values('EM');
insert into test_data values('AM,CA,CD,FM,ST');
insert into test_data values('LS');
insert into test_data values('TQ,SP,AM,FM,ST,CA,CD');
insert into test_data values('TQ,SP,AM,FM,ST,CA,CD,LS');
insert into test_data values('DM,HM,LS');
The data in the table test_data looks like
DM,HM
EM
AM,CA,CD,FM,ST
LS
TQ,SP,AM,FM,ST,CA,CD
TQ,SP,AM,FM,ST,CA,CD,LS
DM,HM,LS
Now I need to search"LS" in the table test_data. Basically, I need to find if "LS" is present at least once in any of the rows or not. Please note that I want to avoid looping here.
Thanks
DS
Hi,
Watch out for the "Mother is in chemotherapy" problem.
If one key can be a substring of another, then Kapil's solution will be too lax. For example, if you're looking for 'LS', it will match words like 'ALSO' and 'GALS'. In that case, you need something like this:
SELECT COUNT (*) AS num_rows
FROM test_data
WHERE ',' || textfield || ',' LIKE '%,LS,%'
You could get the same results with regular expressions, but they would be slower, and not much simpler (if any).
Why do you have data like that in your table? Relational databases were designed to have only 1 item in each column of each row. That's something so basic to table design that it's called First Normal Form. You application could be much simpler and faster if you redesigned the table so that it had more rows, with less on each row, or pehaps put this information in a separate table.
Similar Messages
-
Function for search string in all table of a particular schema ? (postgres)
Hi ,
i want to create a function postgresql, that can able to search a string from all tables.
I try as below.... please rectify this
CREATE OR REPLACE FUNCTION search_string(str char(50))
returnS character varying AS
$BODY$
DECLARE
tempCount bigint ;
record_v record;
itemid_v bigint ;
query varchar;
return_v character varying := null;
BEGIN
for record_v in (select table_name ,column_name
from information_schema.columns and data_type in ('character','character varying','text')) loop
query := 'select count(*) from '|| record_v.table_name ||' where ' || record_v.column_name || ' like ''%' || str ||'%''' ;
execute query into tempcount;
if (tempCount >0) then
return 'l';
else
return '2572';
end if;
end loop;
END;
$BODY$ LANGUAGE plpgsql VOLATILE
COST 100;
in output i need all tables in which string exists :
like table_name count_of_string_matchMr. singh wrote:
oracle is the master of all databases - i hope u know
if any body work on oracle .. he can right any query in any database :)Query maybe. but you were asking about functions. ANSI SQL is a pretty good standard for most normal dbs nowadays. But the procedural extensions differ more. Therefor you should go to a postgress forum to ask there. Or upgrade your database to oracle. -
Searching TEXT String in a document stored in BLOB Column
Hi,
I fairly new to this concept of Oracle iText. I would like to get the atmost procedural approach to meet the following scenario.
I have a table with 3 columns (viz. id,name, content) of which content is a BLOB datatype. I have stored a simple .doc file in this column. (Just one row has been stored into this table ). I am aware that this document contains my search word say 'TOPIC'.
These are the following steps i did to get my soln but didnt meet my expected result.
1. Inserted the row into the table ..... successful
2. Tried to do a simple select (using contains)after creating context index....no rows selected
3. Tried to create preference (DIRECT_PREFERENCE) and create an index using this PREFERENCE and do the select for the search string......no rows selected
It would b great if u would let me know, how can i retrive the doc info ie. atleast the id,name from the database if i get a matched search string in the table.
Regards
KevinWhen you index BLOBs (or RAW, or file) the product assumes that you have some kind of
binary data -- like Microsoft Word or something like that. It then automatically
engages the INSO filter.
In your case, if I understand correctly, you have text data stored in a blob.
So INSO filtering is not appropriate. So you will want to tell the product not to
use INSO:
create index ...
parameters ('filter ctxsys.null_filter');
try that... -
Help required- Searching Particular string in column
Hi,
I have a table by name temp and 2 values in the table. I'm using LIKE caluse to search a string. I'm getting output for some particular string. Please correct the below query for me.
I have given a table/data reference for you:
Create table temp(col1 varchar2(255));
insert into temp values ('Test_Scale_High');
1 row inserted
insert into temp values ('Test_Scale_High');
1 row inserted
commit;
select * from temp;
col1
Test_Scale_High
Test_Scale High
select * from temp where upper(col1) like '%TEST_SCALE%';
COL1
Test_Scale_High
Test_Scale High
select * from temp WHERE UPPER(COL1) LIKE '%TEST_SCALE_%';
COL1
Test_Scale_High
Test_Scale High
select * from temp WHERE UPPER(COL1) LIKE '%TEST_SCALE_H%';
No Row Selected
Thanks,
Santhosh.Ssanthosh.shivaram wrote:
select * from temp;
col1
Test_Scale_High
Test_Scale High
select * from temp where upper(col1) like '%TEST_SCALE%';
COL1
Test_Scale_High
Test_Scale High
select * from temp WHERE UPPER(COL1) LIKE '%TEST_SCALE_%';
COL1
Test_Scale_High
Test_Scale High
If I understand your requirement correctly you need to escape the Wild Card '_'
Hope the following code helps:
SQL> set feedback on;
SQL> SELECT * FROM TEMP
2 /
COL1
Test_Scale_High
Test_Scale High
2 rows selected.
SQL> SELECT *
2 FROM temp
3 WHERE UPPER (col1) LIKE '%TEST_SCALE%'
4 /
COL1
Test_Scale_High
Test_Scale High
2 rows selected.
SQL> SELECT *
2 FROM temp
3 WHERE UPPER (col1) LIKE '%TEST_SCALE\_%' ESCAPE '\'
4 /
COL1
Test_Scale_High
1 row selected.
SQL> SELECT *
2 FROM temp
3 WHERE UPPER (col1) LIKE '%TEST_SCALE_H%'
4 /
COL1
Test_Scale_High
Test_Scale High
2 rows selected.
SQL> SELECT *
2 FROM temp
3 WHERE UPPER (col1) LIKE '%TEST_SCALE\_H%' ESCAPE '\'
4 /
COL1
Test_Scale_High
1 row selected.
SQL>Regards,
Jo
Edited by: Joice John : Added 2 Sample Codes -
Searching a string in a column
Hi All,
I have a table having a column containing names,i need to write a query that would fetch the exact string from the table.
eg. Available funcions- is the data in the table
Query: select name from <table> where LOWER(name) like LOWER('av%')
the query explained above will return the result : Available functions
instead of the LIKE clause do i have anyother effective way of searching the table??
thanks in advance
regards
KarthikThere is another method, but I do not know if it would be faster
I'll search for names that have MICHELLE
MY_TABLE:
NAME_IND
ABRAHAM MICHELLE LYNN
BATEY MICHELLE LYNN
CARR CRAIG MICHEAL
COTE BRUCE MICHEAL
ELDREDGE MICHEAL BRUCE XOX
FLINT MICHELLE LEIGH
FORSBERG JOHN MICHEAL JR
GESSFORD MICHELLE LANA
GREAUX MICHEL EDMOND
HAWLEY MICHELE LEE
HINDS KRISTY MICHELLE
JARRELL SHARIKA MICHELLEANN
JENNINGS MICHELLE DYAN
JONES MICHELLE LEE XOX
MICHEL BRIAN PATRICK
MICHEL CHARLES FREDERICK
MICHELS MARSHALL THOMAS
SHEARIN MICHELE LYNN
THOMAS MICHELL
WARNE MICHELLE MARIE
SELECT name_ind
FROM My_Table
WHERE 'MICHELLE' = SUBSTR( Name_Ind, INSTR(Name_Ind,'MICHELLE',1), LENGTH('MICHELLE') )RESULTS:
NAME_IND
ABRAHAM MICHELLE LYNN
BATEY MICHELLE LYNN
FLINT MICHELLE LEIGH
GESSFORD MICHELLE LANA
HINDS KRISTY MICHELLE
JARRELL SHARIKA MICHELLEANN
JENNINGS MICHELLE DYAN
JONES MICHELLE LEE XOX
WARNE MICHELLE MARIE -
How to search a string in some folder.
Hi ,
In my application users will upload some pdf,xls files to server. files will be saved in server. From the front end can search on all files with some specific string. If that string is there in any of the file, user has to get link to download that file and the text just before and after that user string. Its like how we get in google. This type of search we need to implement, Could any one please let me know how to implement, any free API are there in java. Please its urgent, help on this.
Thanks
Mohanuser594301 wrote:
I have 2 columns in a table. entry_no and msg_txt. entry_no is number(12) and msg_txt is LONG. I want to search one string in msg_txt. How can I write a query for this ?You can't write a query for this. The only thinks you can do with a long in a query is put something in and take it out again - with diffiuclty, usually.
You can write a PL/SQL function to do this for you if necessary. The function will have to perform the search directly if the long < 32760 bytes or use DBMS_SQL to break the LONG up into 32760 byte segments that can then be manually searched. If you are lucky someone has done this already and posted the code online. Either way the solution will be slow and probably painful to implement.
If possible convert your data to a CLOB and use DBMS_CLOB to find the data you need. -
ORA-13223: duplicate entry for string in SDO_GEOM_METADATA table and
I got the above error while trying to insert a record into the table SDO_GEOM_METADATA. However, when querying this table I did find any duplicate table_name, column_name pair that match with the error.
Here are the steps that I worked on:
1. Add a geometry column into an existing table.
ALTER TABLE GEO_MAP ADD (ORG_GEOM mdsys.sdo_geometry);
2. Register the new column into mdsys
insert into USER_SDO_GEOM_METADATA
values ('GEO_MAP','ORG_GEOM',
mdsys.sdo_dim_array(
mdsys.sdo_dim_element('LONG',-180,180,0.00005),
mdsys.sdo_dim_element('LAT',-90,90,0.00005)
8307)
I got the error ORA-13223: duplicate entry for string in SDO_GEOM_METADATA table even there was no such record in there.
3. I inserted values in the column ORG_GEOM fine.
4. However, when I tried to create the index for this column I got the error:
ORA-29855: error occurred in the execution of ODCIINDEXCREATE routine
ORA-13203: failed to read USER_SDO_GEOM_METADATA view
ORA-13203: failed to read
Please help.
Thanks.SQL> select * from mdsys.sdo_geom_metadata_table;
SDO_OWNER SDO_TABLE_NAME
SDO_COLUMN_NAME
SDO_DIMINFO(SDO_DIMNAME, SDO_LB, SDO_UB, SDO_TOLERANCE)
SDO_SRID
QW_USER1 GEO_REF
LOC_GEOM
SDO_DIM_ARRAY(SDO_DIM_ELEMENT('LONG', -180, 180, .00005), SDO_DIM_ELEMENT('LAT',
-90, 90, .00005))
SDO_OWNER SDO_TABLE_NAME
SDO_COLUMN_NAME
SDO_DIMINFO(SDO_DIMNAME, SDO_LB, SDO_UB, SDO_TOLERANCE)
SDO_SRID
8307
MDSYS SDO_CMT_CBK_RTREE_TAB
GEOM
SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X', -180, 180, .000000005), SDO_DIM_ELEMENT('Y',
SDO_OWNER SDO_TABLE_NAME
SDO_COLUMN_NAME
SDO_DIMINFO(SDO_DIMNAME, SDO_LB, SDO_UB, SDO_TOLERANCE)
SDO_SRID
-90, 90, .000000005))
The situation is we have 2 tables (GEO_MAP, and GEO_REF) that have spatial columns. Everything worked fine until when one of the queries that searched through the table GEO_MAP ran so slow, we decided to rebuild the related spatial index by dropping and recreating it. However, after I dropped it I could not recreated. Keep getting the error:
ORA-29855: error occurred in the execution of ODCIINDEXCREATE routine
ORA-13203: failed to read USER_SDO_GEOM_METADATA view
ORA-13203: failed to read
Any help is very much appreciated. -
How to search the content in a Table
Hi all,
How can i search the content in a table. is there any UI Element is there to do this? Can any body give me any sample code for this
regards,
VJRHi,
you gotta do that programmatically,
here is a sample code:
int sizeOfstudent = wdContext.nodeCtx_vn_student().size();
//Ctx_vn_student is the node associated with the table ie its dataSource property
String filtername = wdcontext.currentContextElement.getSName();
//sName is the name to be searched , it is a context attribute
for(int i = sizeOfstudent-1;i>=0;i--)
String matchValue = recNode.getElementAt(i).getAttributeAsText("Name");
//get the name of 1st record(in table) or 1st elememnt in node, "Name" here is value attribute of that node
//so we are fetching its value and comparing it like..
if(matchValue.equalsIgnoreCase(filtername))
//here you can add the action to be taken on mathing name }
hope it helps
regards -
Need a Query to search a value from all tables.
Hi,
I would like to know, is there any way that we could search a string from all the tables.
For example I need to find a STRING 'hello world', on which table it presents. I want to search it from all the tables, as there might be a situtation
where we dont knwo which table the value gets stored.
REgards
SureshRun this code ---this is only search for required value in VARCHAR2 column.as per ur requirement u can change it to oher dataype..
Reply if its helpful to you
DECLARE
S SYS_REFCURSOR;
CURSOR c_user_col IS
SELECT TABLE_NAME,COLUMN_NAME,DATA_TYPE FROM USER_TAB_COLUMNS,TAB
WHERE TABLE_NAME=TNAME AND TABTYPE='TABLE'
ORDER BY TABLE_NAME;
TYPE TAB_LIST
IS
RECORD
TABLE_NAME VARCHAR2(1000),
COLUMN_NAME VARCHAR2(1000),
DATA_TYPE VARCHAR2(100));
TYPE T_TAB_LIST
IS
TABLE OF TAB_LIST;
L_TAB_LIST T_TAB_LIST := T_TAB_LIST();
L_STMT CLOB;
l_exists NUMBER;
BEGIN
FOR i IN c_user_col LOOP
L_TAB_LIST.EXTEND;
L_TAB_LIST(L_TAB_LIST.LAST).TABLE_NAME := I.TABLE_NAME;
L_TAB_LIST(L_TAB_LIST.LAST).COLUMN_NAME := i.COLUMN_NAME;
L_TAB_LIST(L_TAB_LIST.LAST).DATA_TYPE := i.DATA_TYPE;
END LOOP;
FOR i in 1..L_TAB_LIST.COUNT LOOP
l_exists := NULL;
IF L_TAB_LIST(I).DATA_TYPE = 'VARCHAR2' THEN
L_STMT := 'SELECT 1 FROM '||L_TAB_LIST(I).TABLE_NAME||' WHERE '||L_TAB_LIST(I).COLUMN_NAME||'=''samplesdfsdfsdf''';
OPEN S FOR L_STMT;
FETCH S INTO l_exists;
CLOSE S;
IF l_exists IS NULL THEN
NULL;
ELSE
DBMS_OUTPUT.PUT_LINE('Table name: '||L_TAB_LIST(I).TABLE_NAME||'--Column Name: '||L_TAB_LIST(I).COLUMN_NAME);
DBMS_OUTPUT.PUT_LINE(L_STMT);
END IF;
END IF;
END LOOP;
END; -
How to find a string inside Excel table
Hi,
I am trying to find a string inside Excel table, and it does not work. Please see attached figure. I use the find Invoke Node and do not get anthing.
Please help
Attachments:
find_excel.JPG 21 KBSee attached files.
Thanks,
David
Attachments:
Excel_table.xls 15 KB
Read_XL.vi 42 KB -
How to search records in a standard table with * ?
Hi everyone,
Can anyone tell me how to search records in a standard table with * ?
That is, in screen if user type * abc * for searching the records in which the field MC_STEXT contains 'abc'. What the code should be? How to complete the code below?
SELECT SINGLE objid FROM p1000 INTO p1000-objid,
WHERE MC_STEXT = ? .
Thanks!Hi
There are several way to do that, probably just as some guys wrote the easier way is to use LIKE in WHERE condition and the sign % instead of *:
V_STRING = '%ABC%'.
SELECT SINGLE objid FROM p1000 INTO p1000-objid,
WHERE MC_STEXT LIKE V_STRING.
U can also use a range (just like select-options):
RANGES: R_MC FOR P1000-MC_STEXT.
R_MC-LOW = 'ABC'.
R_MC(3) = 'ICP'.
APPEND R_MC.
SELECT SINGLE objid FROM p1000 INTO p1000-objid,
WHERE MC_STEXT IN R_MC.
Max -
Is it possible to make a search help with dynamic selection table?
Hi Experts,
Is it possible to create search helps with dynamic seletion tables means
i dont know the selection table names at the time of creation of search help.
These tables will be determined at runtime.
if yes, Please give an idea how to create and pass the table names at runtime.
Thanks
Yogesh GuptaHi Yogesh,
Create and fill your itab and show it with FM F4IF_INT_TABLE_VALUE_REQUEST
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'field to return from itab'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'field on your screen to be filled'
stepl = sy-stepl
window_title = 'some text'
value_org = 'S'
TABLES
value_tab = itab
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
Darley -
Search a string with in some file and get the name of file
i want to search a string in some files that are in a given directory and return the name of file having searched string.I am doing this with grep command as given below
import java.io.*;
public class linux_java {
public static void main(String[] args) {
try {
String command = "find . | xargs grep -l Resolv /data2/opt/jakarta-tomcat-4.1.24/webapps/Oa/BOG/*.txt";
final Process process = Runtime.getRuntime().exec(command);
OutputStream os= process.getOutputStream();
System.out.println("out put stream= " +os);
PrintStream stdIn = new PrintStream(new BufferedOutputStream(process.getOutputStream()), true);
System.out.println("Return code = " + stdIn);
} catch (Exception e) {
e.printStackTrace();
i dont know how to get the name of file that are return by the execution of command through process object. Please send the code for the samethanks for your suggestion....
i change the code but now it is giving error as /usr/bin/find incomplete syntax....but i am giving the right syntax....
please confirm whether the syntax is correct...
import java.io.*;
import java.util.*;
public class linux_java {
public static void main(String[] args) {
try {
//String command = "ls -alt";
String command = "find /data2/opt/jakarta-tomcat-4.1.24/webapps/Oa/BOG -type f -exec grep -sl 'Aggarwal' {} \\; 2>/dev/null";
///grep -l System test/*java
System.out.println(" the command is"+command);
final Process process = Runtime.getRuntime().exec(command);
InputStream is = process.getErrorStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line="";
System.out.println(" the BufferedReader is"+br.readLine());
while ((line = br.readLine()) != null) {
System.out.println(" the files are"+line);
} catch (Exception e) {
e.printStackTrace();
} -
Search Help values to Internal table
Dear Friends,
Is it possible to export Search Help values to Internal table?
On screen, when user click on Search button, the SAP standard search help will call (Customer Search). After entering values, some result get displayed and this result need to export to the internal table.
Thanks in stack
NileshHi:
try this:
DATA : wa_shlp TYPE shlp_descr,
it_records LIKE ddshretval OCCURS 0 WITH HEADER LINE.
wa_shlp-SHLPNAME = 'MAT0M'. "one of elementary search help name from mara-matnr.
wa_shlp-SHLPTYPE = 'SH'.
CALL FUNCTION 'F4IF_SELECT_VALUES'
EXPORTING
shlp = wa_shlp
MAXROWS = 0
SORT = ' '
CALL_SHLP_EXIT = ' '
IMPORTING
MAXROWS_EXCEEDED =
TABLES
RECORD_TAB =
RECDESCR_TAB =
return_tab = it_records
LOOP AT it_records.
WRITE:/ it_records.
ENDLOOP.
Follows is how to get the search help name:
CALL FUNCTION 'DD_SHLP_GET_HELPMETHOD'
EXPORTING
tabname = 'MARA'
fieldname = 'MATNR'
langu = sy-langu
NO_CHKTAB_MAPPING =
GET_ENTITYTAB = ' '
CHANGING
shlp = wa_shlp
callcontrol = callcontrol
EXCEPTIONS
field_not_found = 1
no_help_for_field = 2
OTHERS = 3
CALL FUNCTION 'F4IF_EXPAND_SEARCHHELP'
EXPORTING
shlp_top = wa_shlp
IMPORTING
shlp_tab = shlps.
好运,
启明星 -
How to search all columns of all tables in a database
i need to search all columns of all tables in a database , i already write the code below , but i've got the error message below when run this script
DECLARE
cnt number;
v_data VARCHAR2(20);
BEGIN
v_data :='5C4CA98EAC4C';
FOR t1 IN (SELECT table_name, column_name FROM all_tab_cols where owner='admin' and DATA_TYPE='VARCHAR2') LOOP
EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM ' ||t1.table_name|| ' WHERE ' ||t1.column_name || ' = :1' INTO cnt USING v_data;
IF cnt > 0 THEN
dbms_output.put_line( t1.table_name ||' '||t1.column_name||' '||cnt );
END IF;
END LOOP;
END;
Error report:
ORA-00933: SQL command not properly ended
ORA-06512: at line 7
00933. 00000 - "SQL command not properly ended"
*Cause:
*Action:
Any help pleaseSQL solutions by Michaels
michaels> var val varchar2(5)
michaels> exec :val := 'as'
PL/SQL procedure successfully completed.
michaels> select distinct substr (:val, 1, 11) "Searchword",
substr (table_name, 1, 14) "Table",
substr (t.column_value.getstringval (), 1, 50) "Column/Value"
from cols,
table
(xmlsequence
(dbms_xmlgen.getxmltype ('select ' || column_name
|| ' from ' || table_name
|| ' where upper('
|| column_name
|| ') like upper(''%' || :val
|| '%'')'
).extract ('ROWSET/ROW/*')
) t
-- where table_name in ('EMPLOYEES', 'JOB_HISTORY', 'DEPARTMENTS')
order by "Table"or
11g upwards
SQL> 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 ('EMP', 'DEPT')),
xmltable (str columns result varchar2(10) path '.')
TABLE_NAME COLUMN_NAME SEARCH_STRING RESULT
DEPT DNAME es RESEARCH
EMP ENAME es JAMES
EMP JOB es SALESMAN
EMP JOB es SALESMAN
4 rows selected.
Maybe you are looking for
-
Problem with sound in system prefrences
Hello everyone, Im a new mac user and im using the new Macbook Pro. Im having a bit of an issue with the sound portion of the system preffrences. About a week ago I was trying to switch the input to the line in so that I could play my bass into my ma
-
I accidentally uninstalled Quicktime from my computer so my Itunes was not functioning. It told me to uninstall my Itunes, then reinstall it. Which I did. Trouble is, now it comes up with 'THE FILE "ITUNES LIBRARY.ITL" CANNOT BE READ BECAUSE IT WAS C
-
EXTREMELY URGENT - the page cannot be displayed
gurus, i'm facing following problem - 1. user logs in portal 2. clicks Navigator link 3. clicks Applications link 4. clicks Application APP_CUSTOMER 5. clicks a dynamic page component in APP_CUSTOMER application and gets the following error - "the pa
-
I have set up my new imac today and the first bit of head scratching was settings for Gmail. Got the emails fine but sending really foxed me. Anyway, two cups of tea later and a cuban cigar did the trick, all works exactly as it should do. Question i
-
DUPLICATE tabs of the same origin are suddenly showing up, i.e. two tabs of my yahoo mail. In addition, "yesterday" I was on the FEDEX website, and ever since then, a tab for FEDEX keeps popping up, even though I didn't initiate it. I've removed misc