Use instr to search for multiple values

Hello

My version of Oracle DB is 10.2.0

I have a file of text separated by delimiters. The text file has 14 columns, and in each column, I have to check the presence of the following
RV, RV, RV, GV, GV, GV.

The sample file contains the following

51151111; 28.18.11; 14711119; 512-GV; 821949,39; 1223,21; 471,49; 821197,29; ABC; 1; 27.18.11; 13


The following code is for the search for GV
 FUNCTION FUNC_FIND_GV   (p_str IN  VARCHAR2) RETURN NUMBER
   AS
         l_gv_pos NUMBER ;
         begin
         l_gv_pos := INSTR(p_str, 'GV') ;
         RETURN l_gv_pos ;

   EXCEPTION
      WHEN OTHERS THEN
       l_gv_pos := 0;
    RETURN l_gv_pos 
   END FUNC_FIND_GV ;
How can I search for other cases?

Hello

You can use regular expresssions to find one a |-at the same time delimited list.
For example:

SELECT  REGEXP_INSTR ( p_str
               , '(RV|RV-|RV/|GV|GV-|GV/)'
               )          AS match_pos
FROM     ...
;

It is unnecessary to search for one of the 'RV', 'RV' - and ' RV /'; hot for just 'RV' will give the same results. However, it does no harm real, so if you build the list ' RV | RV | RV / | GV | GV | GV /' dynamically, so you don't have to check for duplicates.

I hope that answers your question.
If this isn't the case, post CREATE TABLE and INSERT statements for some examples of data and the results desired from these data.

Tags: Database

Similar Questions

  • Search for multiple values in a single field

    Hello

    I have this request to get results when the user doing a search query:

    select * from (
    select 
    "ID",
    "ID" ID_DISPLAY,
    "SHIFT_DATE",
    "SHIFT",
    "OFFENSE_ID",
    "DESCRIPTION",
    "ANALYST",
    "STATUS",
    "SUBSTATUS"
    from "#OWNER#"."IDSIEM_OFFENSES") 
    where
    OFFENSE_ID IN(:P223_OFFENSES) AND
    
     (
     instr(upper("DESCRIPTION"),upper(nvl(:P223_DESCRIPTION,"DESCRIPTION"))) > 0 
    )
    AND
    (
     instr(upper("SHIFT"),upper(nvl(:P223_SHIFT,"SHIFT"))) > 0 
    )
    AND
    (
     instr(upper("SUBSTATUS"),upper(nvl(:P223_SUBSTATUS,"SUBSTATUS"))) > 0 
    )
    AND
    (
     instr(upper("ANALYST"),upper(nvl(:P223_ANALYST,"ANALYST"))) > 0 
    )
    AND
    (
     instr(upper("SHIFT_DATE"),upper(nvl(:P223_SHIFTDATE,"SHIFT_DATE"))) > 0 
    )
    AND
    (
     instr(upper("STATUS"),upper(nvl(:P223_STATUS,"STATUS"))) > 0 
    )
    
    ORDER BY OFFENSE_ID DESC
    

    The thing I want to do is to set multiple values in the P223_OFFENSES field when I search. For example, an offence is a number, so I want to put in the search box 1111, 3333, 4444, 5555 and the report shows me these 4 offences in the report. The search operation only works when I put only 1 offences, but when I put more than 1, separated by commas, it gives me this error: error report: ORA-01722: invalid number. That is why, because is a number and the character point is not allowed, how can I achieve this? Thank you in advance.

    Best regards, Bernardo

    I solved a problem like this a few times with a utility function of pipeline for extracting the values from the list:

    CREATE or REPLACE TYPE split_tbl AS TABLE OF VARCHAR2 (32767).

    /

    FUNCTION to CREATE or REPLACE split_list

    (

    p_list VARCHAR2

    p_delimiter VARCHAR2: = ', '.

    ) Split_tbl RETURN

    PIPELINED IS

    l_idx PLS_INTEGER;

    l_list VARCHAR2 (32767): = p_list;

    BEGIN

    LOOP

    l_idx: = instr (l_list, p_delimiter);

    IF l_idx > 0

    THEN

    LINE of CONDUCT (substr (l_list, 1, l_idx - 1));

    l_list: = substr (l_list, l_idx + length (p_delimiter));

    ELSIF TRIM (l_list) IS NOT NULL

    THEN

    PIPE ROW (l_list);

    EXIT;

    ON THE OTHER

    EXIT;

    END IF;

    END LOOP;

    RETURN;

    END split_list;

    /

    In this way, you can define SQL like:

    SELECT to_number (column_value) FROM TABLE (split_list (' 1, 3, 99', ','))

    Or for this specific case: replace the condition

    OFFENSE_ID IN(:P223_OFFENSES)

    with

    OFFENSE_ID IN (SELECT to_number (column_value) FROM TABLE (split_list (: P223_OFFENSES, ',')))

    The advantage over using instr or regex is that you can usually always benefit index on OFFENSE_ID

    Better also to restrict entry to only numbers and ', ' or you will always get invalid numbers errors if a user enters "1234, 567, ABC"in the field of P233_OFFENSES.

    Kind regards

    Thierry

  • using 'like' to search for multiple words in the search sql sentence

    HI, at the moment I have a cfquery as follows

    < name cfquery = 'test' datasource = "" #datasource # "cachedwithin =" #CreateTimeSpan (0,1,0,0) #">"
    SELECT * to #tablename # where nom_entree is not null and (nom_entree like ' %#keyword #% ')
    order of sequencename
    < / cfquery >

    If the EntryName fiield is for example 'Shepton Mallett', it will be back if I search 'Shepton' or "Mallett" or 'Shepton Mallett', however if I spell 1 word of the search expression erroneous "i.e Shepton Mallatt", he finds no results. I realize that I have to split the sentence search and search on these two words, but not very well what is the right way to do it. I also wanted to strip of common words (IE, a, etc.) of the expression of research if it does not return loads of results. I prefer to keep if possible in sql (not verity)

    Thank you very much

    Oli

    Thank you, perfect

  • How to url using NOT IN (NIN) IR filter for multiple values?

    Apex 5.0.1 (but should work for Apex 4.2)

    I want to set a url with an IR filter using the filter NOT IN. For example, to get a filter that says: status not in (3,4)

    To do this, we can use the url IRNIN_STATUS parameter.

    This method works. Problem is how can I set multiple values in the url?

    IRNIN_STATUS:3, 4 will give a filter 'status not in (3) '

    4 is interpreted as the following for the next parameter value, even if there is no additional parameters.

    Find / remember the solution:

    We can add the backslashes to values to distinguish them from others.

    IRNIN_STATUS:\3, 4

  • Struggling to search for multiple files

    Hello

    I'm fighting to search / select multiple files.

    This is my workflow:

    I have 2 computers, one is used for all image manipulations using a combination of LR & PS and the other computer is used for the sales presentation using ProSelect.

    Once I'm done with my post production I export images to my computer for presentation for sale to the JPG file format.

    After the sale I want to then be able to star the images that they have purchased on my computer to post production. Currently I did this manually, even if time can not too bad when you're talking about only 20 images. However, this does not work for weddings by looking at images of 150-200.

    That's what I tried. I made an export of the names of files in ProSelect. I then removed the suffix .jpg for example. In Lightroom, I the filter bar, text, select all text, Contains searchabe and then paste it into the list of file names. After a while, he'll come back and say no images found or it may come with only the 1st image in the list. I tried several combinations of formatting of the list of file names and none seem to work spaces, commas, semicolons, each file name in «»

    If anyone can help me in this regard, I would be very grateful.

    Thank you

    Tony

    The list of files must be separated by spaces or commas - you copy and paste from a list in which they are separated by line breaks.  I have tried in my own 5.6 LR (Mac), and when the file names are separated by spaces, it works, but not when separated by line breaks.

  • How can I use a different search for FlexRIO i/o modules path?

    I want to use an i/o module that is outside the tree of LabVIEW, but it seems that LabVIEW only searches the shared/flexrio/IO modules, and I can't understand how to create symbolic links in windows.

    Is there a variable I can put it somewhere to include other directories to search for modules e/s?

    Olof

    Hello, Olaf,

    There are two locations on your computer in Windows that are searched for files of supported FlexRIO adapt module.  The first is the Program Files directory, you indicated in your message. This directory contains the support files for the NOR made adaptation modules.  However, there is another directory, which can be used for the location of all the modules not - NEITHER adapter manufactured.  For Windows XP, this location is: C:\Documents and Settings\All Users\Documents\National Instruments\FlexRIO\IO Modules.  If you try to install support for a manufactured non - adaptation module, please make sure that you have installed all the files in the module adapter support on this issue.

    If you would like more information regarding a custom adapter module development, please send an email to support to the addresses listed in your Module Development Kit manual.  This e-mail address will give you direct access to the NI FlexRIO R & D team for management as shown here.  If you want to discuss adding the ability to search other directories for adapter module support (except the two mentioned above), please send an email to the email address of support MDK.

  • How to use wildcards to search for e-mail addresses.

    Hi all


    We have a great html site and we need to search all pages to find all built-in e-mail addresses. We just need to make sure that all the addresses on the site are always topical. I tried to use a regex search such as @[\w\W]*?com but the problem is that it will find a great piece of code that starts by the @ and somewhere later ends with the.] com  For example this piece of code would be returned using this search:

    @import url("./menu.css");

    < / style >

    < link hand. CSS"rel ="stylesheet"type =" text/css"/ >

    < link href = "layout.css" rel = "stylesheet" type = "text/css" / > "

    < link href =' http://fonts.googleapis.com/CSS?family=cabin:700,400 ' rel = "stylesheet" type = "text/css" >

    "< script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js "> < / script >

    < / head >

    < body class = "gradient b" >

    < div class = "container" >

    < div class = "header" >

    < div style = "width: 195px; "" float: left "> < a href =" http://www.SiteName.com " " "

    Can someone suggest a better expression of search to find all email addresses on the site? BTW, all used addresses do not necessarily belong to the same domain name, so I can't limit the search string to that. And I realize that I probably repeat the search for .net, .org, etc.

    I am close, or is it just not possible?

    Thank you
    CJ

    Just add them to the final list in parentheses, separated by a vertical bar.

    There are now a large number of top-level domains. If the OP needs a regex more complete, I'll be happy to oblige. But it would be useful to know which TLDs are likely to be needed in research. Otherwise, the regular expression becomes heavy.

  • Best way to search for a value in the table

    Hello world

    Need help to decide which application should be used in the following scenario.
    Table  temp_a
    ( col_1 varchar2(20),
     status_flag varchar2(10)
    );
    col_1 is the primary key


    I want to know if a given value is present in "col_1" of the table "temp_a.

    So what query wud be faster:

    1.
     select count (*)
    from temp_a
    where col_1 = v_col_1   -- using variable to check for value
    and status_flag ='active' ;
    2.
     
     select count (*)
    from temp_a
    where col_1 = v_col_1   -- using variable to check for value
    and status_flag ='active' 
    and rownum =1 ;
    Here, I am not concerned about the number (*), I just need to check if the v_col_1 is present or not.

    1. then please let me know, if both are one and the same. or one of them is faster over another.

    2. also, is there a better way to check?

    Thank you
    Abhishek

    The two approaches are the same, because col_1 is a primary key.
    I think that there is a query then faster:

    select count (*)
    from temp_a
    where col_1 = v_col_1
    ;
    

    Max
    [My Italian blog Oracle | http://oracleitalia.wordpress.com/2010/02/07/aggiornare-una-tabella-con-listruzione-merge/]

  • How to use the find method to search for multiple items in a single paragraph?

    I'm desigining a script to find all instances where ctrl + b and ctrl + i are applied to body text and then replace the format of these characters replaced with chartag italic or bold.  Here's what the script is supposed to do:

    1. put the find method in a while loop that overrides seeks format character.
    2. If a substitution of format character is found, pass the text range returned by the find method and the CharPropsChange flag in the GetTextForRange method.
    3. Use a Boolean comparison between the idata of the text element to the angle of character and character constant weight.
    4. What that is the boolean is set to true, and then use the SetTextProp method to set the properties of the text range for the italic or bold character tag properties.

    This script works on the substitution of format first character found however it ignores other substitutions in the same paragraph. The cause of this is that the while loop updated the line of text control used by the find method for the following paragraph in the stream. I think I need to add an inner loop that runs through all the text in a single paragraph, where teaching iteration the loc text used by the find method is based on the same paragraph, but the offset is changed. I don't know how to do this.

    function removeOverrides (RPSC)

    {

    var vDocStart = pDoc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;

    var vBoldFmt = getCharFmt (RPSC, "Bold")

    var vItalicFmt = getCharFmt (RPSC, 'Italic')

    initFA_errno ();

    While (FA_errno is constant .FE_Success)

    {

    var vTextLoc = new TextLoc(vDocStart,0);

    var vFindParams = findOverrideParams (CDRP);

    var vTextRange = pDoc.Find (vTextLoc, vFindParams);

    If (vTextRange.beg.obj.ObjectValid ())

    {

    var vTextItems = pDoc.GetTextForRange (vTextRange, Constants.FTI_CharPropsChange)

    If (vTextItems.length ==! 0)

    {

    If (vTextItems [0] .idata == constant .FTF_WEIGHT)

    {

    pDoc.SetTextProps (vTextRange, vBoldFmt.GetProps ())

    }

    If (vTextItems [0] .idata == constant .FTF_ANGLE)

    {

    pDoc.SetTextProps (vTextRange, vItalicFmt.GetProps ())

    }

    } else (Log (vLogFileName, ' \nERROR: none of the items were found in the table in text format but alternative size were found: ' + pDoc.Name))

    }

    vDocStart = vDocStart.NextPgfInFlow;

    }

    }

    function findOverrideParams (RPSC)

    {

    var vFindParams = AllocatePropVals (1);

    vFindParams [0].propIdent.num = Constants.FS_FindObject;

    vFindParams [0].propVal.valType = Constants.FT_Integer;

    vFindParams [0].propVal.ival = Constants.FV_FindCharacterFormatOverride;

    Return vFindParams;

    }

    Another approach (which is what I usually did) is after the first search to set vTextLoc = vTextRange.end

    Whatever it is, you might consider moving your initialization of vTextLoc and vFindParams outside the while loop. The settings do not change, why redefine them for each search?

  • How can I search for multiple files at the same time?

    In windows XP, after the advanced search mode, I used to be able to search multiple files simply by adding a comma between them like this...

    90025,90028,90094

    and which returns 3 image files I was looking for.

    How can I do this in Windows 7?

    Use OR instead of the comma...
     
    90025 OR 90028 90094
     
    --
    Dave N.
    MS - MVP (Mail)
    Windows 7 Ultimate 64
    "Tziware" wrote in message
    News: * e-mail address is removed from the privacy... *
     
    In windows XP, after the passage in the advanced search mode, I used to be able to
    Search multiple files, simply by adding a comma between them as
    This...
     
    90025,90028,90094
     
    and which returns 3 image files I was looking for.
     
    How can I do this in Windows 7?
     
     

    Windows 7 Ultimate 64

  • Using Regex to search for a string

    East - viable to use regular expressions with search "Specific tag" (i.e.script) "with the attribute" (i.e. the CBC) and '=' a regex string rather than a precise search term?  Find / Replace tool seems to prevent a generic find simple (i.e. ' searchter * for searchterm ") any idea would be appreciated.

    Screen shot 2012-01-27 at 3.55.27 PM.png

    uneAaron wrote:

    I'm trying to replace a source value of script for all instances where the value contains the string "/ bbcswebdav/xid-144702_1", where the string '-xid' is followed by a different numeric value in each case.

    The regular expression to find this string is:

    \/bbcswebdav\/xid\-[\d_]+
    

    The numeric value contains an underscore, so the last section ([\d_]+) uses a range that selects one or more numbers or underscores.

    Perhaps as important as the identification of what you want to find is to specify how you want to replace it. Regexes can capture groups that can be used in the field replace to simplify things.

  • Search for Null values in the result of the query

    I queries a database for modules. I want to display the e-mail address of users, if there is one, if there is an email address, I want to draw the attention of the user of the present and offer them the chance to enter one. I thought I'd use an if statement, but can understand how cod if 'e-mail eq null. If the statement is looking for the text null instead of a null value

    VR;

    or

    --

    Azadi Saryev
    SABAI - Dee.com
    http://www.SABAI-Dee.com

  • Address book crashes when searching for any value to AddressBook OSX 10.11.1

    Hi, opening address book without problems. Research or an opening speech crashes the application on the MacMini.

    Action 1 failed: delete cache of the application in the user library, then restart the application.

    Q: should I remove my icloud and restore the account or it is not a serious question?

    CrashLog below:

    ###############

    Process: Contacts [98477]

    Path: /Applications/Contacts.app/Contents/MacOS/Contacts

    ID: com.apple.AddressBook

    Version: 9.0 (1679)

    Generation information: AddressBook_executables-1679000000000000 ~ 6

    Code type: X 86-64 (Native)

    Parent process:? [1]

    Officials: Contacts [98477]

    User ID: 502

    Date/time: 21:22:52.215 2015-11-27 + 0100

    OS version: Mac OS X 10.11.1 (B 15, 42)

    Report Version: 11

    Anonymous UUID: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Sleep/wake UUID: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Time since started awake: 97000 seconds

    Integrity of system protection: enabled

    Crashed thread: 5 dispatch queue: com.apple.root.default - qos

    Exception type: EXC_CRASH (SIGABRT)

    Exception codes: 0 x 0000000000000000, 0 x 0000000000000000

    Note the exception: EXC_CORPSE_NOTIFY

    Request for clarification:

    Closing the app due to uncaught exception ", reason: '-[ABRecord setValue: forKey ' # #MyFirstNameDisplayedHere # ': 'First'] invalid value ' ending with an exception uncaught called abort() print type

    Specific application Backtrace 1:

    0 CoreFoundation 0x00007fff987dee32 __exceptionPreprocess + 178

    1 libobjc. A.dylib 0x00007fff937484fa objc_exception_throw + 48

    2 CoreFoundation 0x00007fff9884565d + [print raise: format:] + 205

    3 AddressBook 0x00007fffa071c0fd-[ABSuggestedEntriesFetcher personFromContact:] + 128

    Address book 0x00007fffa071bfc4 4 __53-[ABSuggestedEntriesFetcher entriesByUIDForContacts:] + 41 _block_invoke

    5 address book 0x00007fffa06614a8 __44-[NSArray (ABArrayAdditions) _abMapNoFilter:] + 20 _block_invoke

    6 CoreFoundation 0x00007fff9875b41d __53-[__NSArrayI enumerateObjectsWithOptions:usingBlock:] + 77 _block_invoke

    7 CoreFoundation 0x00007fff9875b2e9-[__NSArrayI enumerateObjectsWithOptions:usingBlock:] + 201

    8 AddressBook 0x00007fffa0646819-[NSArray (ABArrayAdditions) _ab_each:] + 91

    9 AddressBook 0x00007fffa0661484-[NSArray (ABArrayAdditions) _abMapNoFilter:] + 136

    AddressBook 10 0x00007fffa071bf60-[ABSuggestedEntriesFetcher entriesByUIDForContacts:] + 175

    Address book 11 0x00007fffa071bcf3-[ABSuggestedEntriesFetcher fetchEntries] + 43

    Address book 12 0x00007fffa07bb18e-[ABPersonListSearchHelper fetchSuggestedEntriesByUID] + 202

    Address book 13 0x00007fffa07baf40-[ABPersonListSearchHelper performSuggestionSearch:] + 27

    14 ContactsFoundation 0x00007fff9b48286c-[_CNThrottledObservable _sendResultToObserver:withIdentifier:] + 77

    15 ContactsFoundation 0x00007fff9b4840d1 __45-[_CNQueueScheduler afterDelay: performBlock:] + 16 _block_invoke

    16 libdispatch.dylib 0x00007fff8df203c3 _dispatch_client_callout + 8

    17 libdispatch.dylib 0x00007fff8df30674 _dispatch_source_latch_and_call + 2235

    18 libdispatch.dylib 0x00007fff8df24a3b _dispatch_source_invoke + 983

    19 libdispatch.dylib 0x00007fff8df23d0b _dispatch_root_queue_drain + 538

    20 0x00007fff8df23ab8 _dispatch_worker_thread3 + 91 libdispatch.dylib

    21 libsystem_pthread.dylib 0x00007fffa0aa34f2 _pthread_wqthread + 1129

    22 libsystem_pthread.dylib 0x00007fffa0aa1375 start_wqthread + 13

    Binary images:

    0x10584a000 - com.apple.AddressBook (9.0 - 1679) <15886374-2D34-3849-9F68-9B448AC50496>0x1058e3fff /Applications/Contacts.app/Contents/MacOS/Contacts

    0x1085b8000 - 0x1085b9fff com.apple.AddressBook.LocalSourceBundle (9.0 - 1679) <4285734E-D30E-377B-A7EB-D40E0C541F0C>System/Library/Address Book Plug-Ins/LocalSource.sourcebundle/Contents/MacOS/LocalSource

    0x108a8e000 - 0x108a92fff com.apple.DirectoryServicesSource (9.0 - 1679) System/Library/Address Book Plug-Ins/DirectoryServices.sourcebundle/Contents/MacOS/DirectoryServices

    0x108a99000 - 0x108ae7fff com.apple.AddressBook.CardDAVPlugin (10: 9-512) System/Library/Address Book Plug-Ins/CardDAVPlugin.sourcebundle/Contents/MacOS/CardDAVPlugin

    # #MyFirstNameDisplayedHere #.

    If you know that you have a card with this text in the first name field, I suggest that you change or delete. Back up all data before making any changes.

  • Using CONTAINS to search for the exact phrase does not

    I'm trying to use an index of context to the exact phrase INSERT INTO text serch
    create table temp_source as select name, type, line, upper(text) as text from user_source;
    create index usr_src_text on temp_source (text) indextype is ctxsys.context;
    
    select * from temp_source where contains(text, 'INSERT INTO') > 0;
    documentation on several sites, I read all these said should work as they all do the same


    'INSERT INTO' '' INSERT INTO' ' 'INSERT & INTO' 'INSERT AND INTO' but they all return results that have just INSERT in

    Thank you
    Robert

    Is an empty word which is not indexed

    create table temp_source as select name, type, line, upper(text) as text from user_source where 1 = 2;
    insert into temp_source(text) values('insert into');
    insert into temp_source(text) values('insert');
    insert into temp_source(text) values('in');
    
    create index usr_src_text on temp_source (text) indextype is ctxsys.context;
    
    select score(100), text from temp_source where contains(text, 'into', 100) >= 0
    
    SCORE(100) TEXT
    0 insert into
    0 insert
    0 in 
    
    drop table temp_source
    

    So probably yo willl define your own list of empty words and add it to the index (CTX_DDL.create_stoplist, .add_stopword etc..)

    Compare

    create table temp_source as select name, type, line, upper(text) as text from user_source where 1 = 2;
    insert into temp_source(text) values('king kong');
    insert into temp_source(text) values('kong');
    insert into temp_source(text) values('king');
    
    create index usr_src_text on temp_source (text) indextype is ctxsys.context;
    
    select score(100), text from temp_source where contains(text, 'king kong', 100) >= 0
    
    SCORE(100) TEXT
    4 king kong
    0 kong
    0 king 
    
    drop table temp_source
    

    Published by: chris227 on 09.10.2012 04:13

    Published by: chris227 on 09.10.2012 04:16

  • Even if everything goes well when IntExpl is used, every time I use firefox42 to search for a product on this site, I get no results.

    The url is http://www.canadiantire.ca/en.html

    If you use extensions (Firefox, Tools/menu key > Modules > Extensions) which can block content (e.g., Adblock Plus, NoScript, Flash Block, Ghostery) then make sure that these extensions are not blocking content.

Maybe you are looking for