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.

Similar Messages

  • HT204053 i RECENTLY PURCHASED ANOTHER IPHONE.  MY INTERNET IS NOT WORKING.  I JUST CREATED AN APPLE ID.  WHAT'S NEXT?  I NOW HAVE TWO DIFFERENT ACCOUNTS WITH DIFFERENT USER NAMES.  HOW CAN I USE ONLY ONE ACCOUNT FOR ITUNES, ICLOUD APPLE ID ETC???

    I RECENTLY PURCHASED ANOTHER IPHONE.  MY INTERNET IS NOT WORKING.  I JUST CREATED AN APPLE ID.  WHAT'S NEXT?  I NOW HAVE TWO DIFFERENT ACCOUNTS WITH DIFFERENT USER NAMES.  HOW CAN I USE ONLY ONE ACCOUNT FOR ITUNES, ICLOUD APPLE ID ETC???

    Welcome to the Apple community.
    iTunes and iCloud and different accounts, you will need to delete both accounts from your device before adding the new details in their place.
    For iCloud go to settings > iCloud, scroll down and hit the delete button. You can then sign back in using your correct details. For iTunes go to settings >store, tap your account ID and then sign out, you can then sign back in using your correct Apple ID.

  • How can I use my itunes library for iphoto slideshow?

    how can I use my itunes library for iphoto slideshow?

    Here's a possible workaround:
    Create the slideshow in Iphoto and add a theme and music.
    Install Picasa  and it will include the slideshow on it's indexed list.
    Upload the slideshow to PicasaWebAlbums and send the link to anyone you wish.
    The music and theme is preserved.
    Caveat: My playback pictures appear darker than usual but that could be just lousy photography...:)
    Example:https://picasaweb.google.com/mb2180/Kona2011?authuser=0&authkey=Gv1sRgCPGWz_qPrM XKZA&feat=directlink

  • HOW CAN I USE MY OWN EMAIL FOR IMESSAGE IF I DONT HAVE MY OWN ACCOUNT

    HOW CAN I USE MY OWN EMAIL FOR IMESSAGE IF I DONT HAVE MY OWN ACCOUNT

    You have to achieve at least 500 points before you are able to do that.
    Award points, level up, and earn new privileges

  • HT1660 how can I use one single library for all users on the same laptop?

    how can I use one single library for all users on the same laptop?

    You are most of the way there. Each user having access to hard drive is the key. If users are limited in file privileges this is harder.
    Any files you add to your library and any files she adds to her library are available to the other. Just not automatically. Each user must add the files to their own library using the add file or add folder option from menu bar.
    What I have done is set library location to a location outside of My Documents\My Music. On my network storage I have a folder names s:\itunes. Both accounts iTunes are set to use this location for the library.

  • I Have and iPhone and iPad. How can i use Finder my iPhone for both devices.

    I Have and iPhone and iPad. How can i use Finder my iPhone for both devices?

    http://itunes.apple.com/us/app/find-my-iphone/id376101648?mt=8
    That app is also compatible with the iPad and requires iOS 3.1.3 or later.

  • How can I use srvctl command line for change "Failover type" and "F method"

    Hi all,
    I am using Oracle One Node (11.2.0.3), and I have a service:
    /u01/11.2.0/grid/bin/srvctl config service -d orcl
    Service name: orcldb
    Service is enabled
    Server pool: orcl
    Cardinality: 1
    Disconnect: false
    Service role: PRIMARY
    Management policy: AUTOMATIC
    DTP transaction: false
    AQ HA notifications: false
    Failover type: NONE
    Failover method: NONE
    TAF failover retries: 0
    TAF failover delay: 0
    Connection Load Balancing Goal: LONG
    Runtime Load Balancing Goal: NONE
    TAF policy specification: BASIC
    Edition:
    Preferred instances: orcl_1
    Available instances:
    I would like to change "Failover type" and "Failover method" to:
    Failover type: SELECT
    Failover method: BASIC
    How can I do that? Is there any graphical tool for it? Or, How can I use srvctl command line for change it?
    Thanks in advance.
    Leonardo.

    user10674190 wrote:
    Hi all,
    I am using Oracle One Node (11.2.0.3), and I have a service:
    /u01/11.2.0/grid/bin/srvctl config service -d orcl
    Service name: orcldb
    Service is enabled
    Server pool: orcl
    Cardinality: 1
    Disconnect: false
    Service role: PRIMARY
    Management policy: AUTOMATIC
    DTP transaction: false
    AQ HA notifications: false
    Failover type: NONE
    Failover method: NONE
    TAF failover retries: 0
    TAF failover delay: 0
    Connection Load Balancing Goal: LONG
    Runtime Load Balancing Goal: NONE
    TAF policy specification: BASIC
    Edition:
    Preferred instances: orcl_1
    Available instances:
    I would like to change "Failover type" and "Failover method" to:
    Failover type: SELECT
    Failover method: BASIC
    How can I do that? Is there any graphical tool for it? Or, How can I use srvctl command line for change it?
    Thanks in advance.
    Leonardo.srvctl modify service -d database_name -s orcldb -q TRUE -m BASIC -P BASIC -e SELECT -z 180 -w 5 -j LONG
    Also see
    11gR2(11.2) RAC TAF Configuration for Admin and Policy Managed Databases [ID 1312749.1]

  • How can I use app find iPod  for my daughters iPod even if she has own acct Id?

    How can I use app find iPod  for my daughters iPod even if she has own acct Id?

    Hi,
    So far so good! I was successful with my first request-and thanks, but I guess i did not ask enough.
    New question: Is there any way for me to have my Apple devices show up with my daughters even though we have different apple id's? I was able to have her sign in and I could see but, if she doesn't sign in I can't see her device. She is only 15 and I going on a trip soon that I would like to just have security if she looses her device or I'll know she is okay. I don't want to sync and see everything, just the where abouts of the device. We were able to create a music folder for her music only and not mine- Success!
    Did I ask too much?
    Thanks for your quick reply!

  • How can I use SQL to check if the receipt is accounted?

    Dear all:
    How can I use SQL to check if the AR receipt is accounted ? Because there is so many receipts to check, I cannot open it to see the detail one by one.
    My environment is :11.5.9
    database : Oracle 9.2.0.8

    Duplicate post.
    How can I use SQL to check if the receipt is accounted?
    Re: How can I use SQL to check if the receipt is accounted?

  • I have a MacBook that is synced with my ipad.  My daughter has an Iphone4 and no computer.  How can we use the one computer for both devices that are unique?

    I have a MacBook that is synced with my ipad.  My daughter has an Iphone4 and no computer.  How can we use the one computer for both devices that are unique and keep them separate. thank you for your help!

    This should help:
    How to use multiple iPods, iPads, or iPhones with one computer
    Regards.

  • How can I use the F11 short cut to go to next field in Microsoft Word 2011 on Macbook Air

    How can I use the F11 short cut to go to next field in Microsoft Word 2011 on Macbook Air?

    The default setting for the function keys is that they do OS X functions.
    To get a regular function hold the fn key and then press the function key.
    This action can be reversed in keyboard preferences.

  • How can I use one iTune account for 2 phones

    How can I set iTunes account up for 2 phones,  in able to sync them and keep them updated?

    Are you using both phones, or is there a second person involved.

  • I live in Germany and in the USA. How can I use an itunes account for both shops ?

    Hi,
    I live half a year in Germany and half a year in California. How can I use my different Apple ID's to buy in Germany from the US-iTunes shop and in the U.S. from the German shop. Reason: the shops have different offers. Some booksare not available in the German shop and some are not available in the U.S. shop.
    For a person, who lives in both countries the restrictions makes absolutely no sense.
    Has anybody an idea how to manage that`
    Thanks

    For starters, there's probably not many people who have dual national residencies so I'm guessing it's not a priority with Apple.  The solution according to the store terms of use regarding your physical location, credit card billing address, nation of store, is when you are physically present in Germany you should be making purchases from the German store with a credit card billed to an address in Germany.  When in the USA you buy from the US store with a credit card billed to a USA address.  You're not supposed to use a store in another country when not actually present in that country even if you have a valid account there.

  • How can I use the same session for different components acroos application ?

    I am trying to include the components(chat, filesharing, whitboard) in different parts of my application. User should be able to access any of the component. We would like to have a single "ConnectSessionContainer" so that we don't see same user creating a seperate session for each component.
    Is there a better way of dealing with this other than declaring the "ConnectSessionContainer" in the main application ? Is there a way to check if we have a "ConnectSessionContainer" session already established ? Please help . Thanks.

    Thanks for the response. Let me explain what I am trying to do..
    I am trying to create components at different places(screens) of the flex application (not in the same .mxml file).
    Each time I create a component, I am using a "AdobeHSAuthenticator" and "ConnectSessionContainer" which is resulting a new participant in the room.
    For example
    screen1.mxml -
    <mx:Panel>
    <rtc:AdobeHSAuthenticator id="auth" authenticationSuccess="onAuthSuccess(event);" authenticationFailure="onAuthFailure(event);" />
    <rtc:ConnectSessionContainer id="mySession" >
            <rtc:Roster id="myRoster" width="100%" height="100%" />
            <rtc:Chat id="mychat" width="100%" height="100%" />
    </rtc:ConnectSessionContainer>
    </mx:Panel>
    screen2.mxml (in the same application) -
    <mx:Panel>
    <rtc:AdobeHSAuthenticator id="auth" authenticationSuccess="onAuthSuccess(event);" authenticationFailure="onAuthFailure(event);" />
    <rtc:ConnectSessionContainer id="mySession" >
            <rtc:SharedWhiteBoard id="wb" width="100%" height="100%" />
    </rtc:ConnectSessionContainer>
    </mx:Panel>
    Here, I open a screen1 and authenticate as UserA and when I try to open screen2 flex is considering me as another user though I am in the same application.
    1) How can I use different components which are in different flex files as a same User ?
    2) Should I place my <rtc:AdobeHSAuthenticator> and <rtc:ConnectSessionContainer> in the main application which calls the screen.mxml?
    3) What is the best way to do it ?
    Thanks for your time !

  • I have Apple ID for using iTunes, but haven't signed in. Now my Ipad stolen, how can I use Find My Phone for finding my Ipad?

    Who can help me, to add my Ipad to Deviecs in Find My Phone. I was usually using my Ipad sign in iTunes for download music, but haven't signed in iCloud yet. Now my I Ipad stolen, how can I use Find My Phone?

    Welcome to the Apple Community.
    You can only locate your device when it is logged into iCloud and 'Find My Phone' is enabled, additionally the device will need to be switched on and connected to a wifi or cellular network.
    Unfortunately, you cannot activate iCloud or 'Find My Phone' remotely.
    If the device is wiped by you or another, you may not be able to locate the device (although some have reported they can)

Maybe you are looking for

  • Where Can I Get an Older Version of iTunes?

    iTunes 10.6.1 has frozen and stopped functioning on a perfectly-maintained Windows XP machine. Where can I download the two versions previous to 10.6.1? Thank you.

  • How do i change an icon for a device?

    How do I change an icon for a device?

  • Assassin's Creed Wont Play

    I just purchased an downloaded the Assassin's Creed game for my iPod Touch. After searching the net and Apple support I haven't found anyone else with this problem so I decided to ask here. After downloading and syncing, the "game" only plays a trail

  • Rejecting a request in Custom Workflow

    Hi I have a custom workflow at operational level for two level of approvals. Workflow is working fine and assigning the request to the correct role but when a user of that role is trying to Reject the request he is getting the error on the console. I

  • Connection help before Imac G5 purchase

    Hi, Looking to purchase a Imac G5 as soon as I can put my mind at rest regarding some connection issues. The Imac will be the main computer. I currently have a PC and a broadband connection with BT (although the modem very old and I don't think it is