Help with oracle sql to get all possible combinations in a table.

Hello guys I have a small predicatement that has me a bit stumped. I have a table like the following.(This is a sample of my real table. I use this to explain since the original table has sensitive data.)
CREATE TABLE TEST01(
TUID VARCHAR2(50),
FUND VARCHAR2(50),
ORG  VARCHAR2(50));
Insert into TEST01 (TUID,FUND,ORG) values ('9102416AB','1XXXXX','6XXXXX');
Insert into TEST01 (TUID,FUND,ORG) values ('9102416CC','100000','67130');
Insert into TEST01 (TUID,FUND,ORG) values ('955542224','1500XX','67150');
Insert into TEST01 (TUID,FUND,ORG) values ('915522211','1000XX','67XXX');
Insert into TEST01 (TUID,FUND,ORG) values ('566653456','xxxxxx','xxxxx');
"TUID"                        "FUND"                        "ORG"                        
"9102416AB"                   "1XXXXX"                      "6XXXXX"                     
"9102416CC"                   "100000"                      "67130"                      
"955542224"                   "1500XX"                      "67150"                      
"915522211"                   "1000XX"                      "67XXX"                      
"566653456"                   "xxxxxx"                      "xxxxx"                       The "X"'s are wild card elements*( I inherit this and i cannot change the table format)* i would like to make a query like the following
select tuid from test01 where fund= '100000' and org= '67130'however what i really like to do is retrieve any records that have have those segements in them including 'X's
in other words the expected output here would be
"TUID"                        "FUND"                        "ORG"                        
"9102416AB"                   "1XXXXX"                      "6XXXXX"                     
"9102416CC"                   "100000"                      "67130"                      
"915522211"                   "1000XX"                      "67XXX"                      
"566653456"                   "xxxxxx"                      "xxxxx"  i have started to write a massive sql statement that would have like 12 like statement in it since i would have to compare the org and fund every possible way.
This is where im headed. but im wondering if there is a better way.
select * from test02
where fund = '100000' and org = '67130'
or fund like '1%' and org like '6%'
or fund like '1%' and org like '67%'
or fund like '1%' and org like '671%'
or fund like '1%' and org like '6713%'
or fund like '1%' and org like '67130'
or fund like '10%' and org like '6%'...etc
/*seems like there should be a better way..*/can anyone give me a hand coming up with this sql statement...

mlov83 wrote:
if i run this
select tuid,fund, org
from   test01
where '100000' like translate(fund, 'xX','%%') and '67130' like translate(org, 'xX','%%');this is what i get
"TUID"                        "FUND"                        "ORG"                        
"9102416AB"                   "1XXXXX"                      "6XXXXX"                     
"9102416CC"                   "100000"                      "67130"                      
"915522211"                   "1000XX"                      "67XXX"                      
"566653456"                   "xxxxxx"                      "xxxxx"                      
"9148859fff"                  "1XXXXXX"                     "X6XXX"                       the last item should be excluded. The second digit in "org" is a "7" Fund is wrong, too. You're looking for 6 characters ('100000'), but fund on that row is 7 characters ('1XXXXXX').
and this is sitll getting picked up.That's why you should use the _ wild-card, instead of %
select  tuid, fund, org
from    test01
where  '100000' like translate (fund, 'xX', '__')
and    '67130'  like translate (org,  'xX', '__')
;It's hard to see, but, in both calls to TRANSLATE, the 3rd argument is a string of 2 '_'s.

Similar Messages

  • Power Query for Excel - Need Help with Oracle SQL Syntax

    Hello everyone,
    I am new to Power Query and am not able to figure this out.  I am trying to pull in data into my Excel spreadsheet using a specific Oracle SQL query.  While in query editor, how do I take the Oracle.Database function and add my SQL statement? 
    I already know what I want, I don't want it to download all the table names.  According to the help page, I should be able to do this but it does not provide a syntax example
    Also, I don't understand what "optional options as nullable record" means.
    Below is what function and arguments the help page notes.  How do I use this?
    Oracle.Database(server as text, optional options as nullable record) as table
    Any help is greatly appreciated.
    Thank you,
    Jessica

    When I try this, I get an error 
    DataSource.Error: Oracle: Sql.Database does not support the query option 'Query' with value '"Select * from Owner.View_Name"'. Details: null
    I'm trying to download oracle data from a view into power query - Power Query navigator does not list th eviews from my source, it lists only the tables. When I try write sql statements, it throws me the above
    error. This is what I tried
     Oracle.Database("Source/Service",[Query="Select * from Owner.View_Name"])
    Any ideas how to fix this? 

  • Help with Oracle SQL to strip unwanted characters

    Hello,
    I have 2 columns (Weight and Height)  where I need to strip the alpha characters and convert them to numbers (I am required to derive additional columns where I need to present
    these values in inches, cm, KG, LB, etc. (and thus the need to convert them to numbers). I am too much a novice to understand the best way to convert these columns into numbers (same precision as you see here).
    See the image below for a sample of what these columns currently contain. I simply need help with the Oracle SQL code to parse/convert these vales into number. Thanks in advance for your assistance!
    Dave

    Hi,
    In addition to
    Erland Sommarskog's comment which is of course correct and this i not the forum to ask question about Oracle, I dont want to leave you without a lead :-)
    The solution both in SQL Server and Oracle should based on Regular Expressions. I highly recommended NOT to use T-SQL solutions in this case, as mentioned above, unless this is a very small table and the need is very simple and include finding one point
    in the string as in
    SaravanaC solution (when he assume thge string format is based on 2 parts (1) Number + (2) unit type).
    In Oracle there is a build in Regular Expressions option as mentioned here: http://docs.oracle.com/cd/B12037_01/appdev.101/b10795/adfns_re.htm
    In SQL Server the PATINDEX is used for simple cases and there is no built in Regular Expressions, but you can add it using CLR as shown in this link http://msdn.microsoft.com/en-us/magazine/cc163473.aspx
    [Personal Site] [Blog] [Facebook]

  • Developerday  VM Ora-12505 Getting Started with Oracle SQL Developer 3.0

    Just downloaded the VM , Started the tutorial Getting Started with Oracle SQL Developer 3.0
    As mentioned in tutorial , I was trying to make a new connection and I am getting following error
    Ora - 12505 : TNS Listener doesn't currently know of SID
    I gave SID as orcl, and seems to be working OK, can I use orcl for this tutorial
    Edited by: OrcArgusDev on Apr 13, 2012 9:01 AM
    Edited by: OrcArgusDev on Apr 13, 2012 9:11 AM

    Thanks, I'll survive. Just my luck, the first item I try to anon. debug didn't work! :)
    thanks, hopefully this problem will be few and far between

  • I cant dowload the itunes i use win 7 with 64 op i get all thge way through then at the last step  HRESULT:0x800736FD shows up and cant go any further. please help

    I cant dowload the itunes i use win 7 with 64 op i get all thge way through then at the last step  HRESULT:0x800736FD shows up and cant go any further. please help

    Many thanks.
    With those symptoms, I'd try the following document:
    Apple software on Windows: May see performance issues and blank iTunes Store
    (If there's a SpeedBit LSP showing up in Autoruns, it's usually best to just uninstall your SpeedBit Video Accelerator.)

  • Help with oracle 11g pivot operator

    i need some help with oracle 11g pivot operator. is it possible to use multiple columns in the FOR clause and then compare it against multiple set of values.
    here is the sql to create some sample data
    create table pivot_data ( country_code number , dept number, job varchar2(20), sal number );
    insert into pivot_data values (1,30 , 'SALESMAN', 5000);
    insert into pivot_data values (1,301, 'SALESMAN', 5500);
    insert into pivot_data values (1,30 , 'MANAGER', 10000);     
    insert into pivot_data values (1,301, 'MANAGER', 10500);
    insert into pivot_data values (1,30 , 'CLERK', 4000);
    insert into pivot_data values (1,302, 'CLERK',4500);
    insert into pivot_data values (2,30 , 'SALESMAN', 6000);
    insert into pivot_data values (2,301, 'SALESMAN', 6500);
    insert into pivot_data values (2,30 , 'MANAGER', 11000);     
    insert into pivot_data values (2,301, 'MANAGER', 11500);
    insert into pivot_data values (2,30 , 'CLERK', 3000);
    insert into pivot_data values (2,302, 'CLERK',3500);
    using case when I can write something like this and get the output i want
    select country_code
    ,avg(case when (( dept = 30 and job = 'SALESMAN' ) or ( dept = 301 and job = 'SALESMAN' ) ) then sal end ) as d30_sls
    ,avg(case when (( dept = 30 and job = 'MANAGER' ) or ( dept = 301 and job = 'MANAGER' ) ) then sal end ) as d30_mgr
    ,avg(case when (( dept = 30 and job = 'CLERK' ) or ( dept = 302 and job = 'CLERK' ) ) then sal end ) as d30_clrk
    from pivot_data group by country_code;
    output
    country_code          D30_SLS               D30_MGR               D30_CLRK
    1      5250      10250      4250
    2      6250      11250      3250
    what I tried with pivot is like this I get what I want if I have only one ( dept,job) for one alias name. I want to call (30 , 'SALESMAN') or (301 , 'SALESMAN') AS d30_sls. any help how can I do this
    SELECT *
    FROM pivot_data
    PIVOT (SUM(sal) AS sum
    FOR (dept,job) IN ( (30 , 'SALESMAN') AS d30_sls,
              (30 , 'MANAGER') AS d30_mgr,               
    (30 , 'CLERK') AS d30_clk
    this is a simple example .... my real life scenario is compliated with more fields and more combinations .... So something like using substr(dept,1,2) won't work in my real case .
    any suggestions get the result similar to what i get in the case when example is really appreciated.

    Hi,
    Sorry, I don't think there's any way to get exactly what you requested. The values you give in the PIVOT ... IN clause are exact values, not alternatives.
    You could do something like this to map all alternatives to a common value:
    WITH     got_dept_grp     AS
         SELECT     country_code, job, sal
         ,     CASE
                  WHEN  job IN ('SALESMAN', 'MANAGER') AND dept = 301 THEN 30
                  WHEN  job IN ('CLERK')               AND dept = 302 THEN 30
                                                                     ELSE dept
              END     AS dept_grp
         FROM     pivot_data
    SELECT     *
    FROM     got_dept_grp
    PIVOT     (     AVG (sal)
         FOR     (job, dept_grp)
         IN     ( ('SALESMAN', 30)
              , ('MANAGER' , 30)
              , ('CLERK'   , 30)
    ;In your sample data (and perhaps in your real data), it's about as easy to explicitly define the pivoted groups individually, like this:
    WITH     got_pivot_key     AS
         SELECT     country_code, sal
         ,     CASE
                  WHEN  job = 'SALESMAN' AND dept IN (30, 301) THEN 'd30_sls'
                  WHEN  job = 'MANAGER'  AND dept IN (30, 301) THEN 'd30_mgr'
                  WHEN  job = 'CLERK'    AND dept IN (30, 302) THEN 'd30_clrk'
              END     AS pivot_key
         FROM    pivot_data
    SELECT     *
    FROM     got_pivot_key
    PIVOT     (     AVG (sal)
         FOR     pivot_key
         IN     ( 'd30_sls'
              , 'd30_mgr'
              , 'd30_clrk'
    ;Thanks for posting the CREATE TABLE and INSERT statements; that really helps!

  • Problems using SQL*Loader with Oracle SQL Developer

    I have been using TOAD and able to import large (milllions of rows of data) in various file formats into a table in an Oracle database. My company recently decided not to renew any more TOAD licenses and go with Oracle SQL Developer. The Oracle database is on a corporate server and I access the database via Oracle client locally on my machine. Oracle SQL Developer and TOAD are local on my desktop and connected through TNSnames using the Windows XP platform. I have no issues with using SQL*Loader via the import wizard in TOAD to import the data in these large files into an Oracle table and producing a log file. Loading the same files via SQL*Loader in SQL Developer, freezes up my machine and I cannot get it to produce a log file. Please help!

    I am using SQL Developer version 3.0.04. Yes, I have tried it with a smaller file with no success. What is odd is that the log file is not even created. What is created is a .bat file a control file and a .sh file but no log file. The steps that I take:
    1.Right click on the table I want to import to or go to actions
    2. Import Data
    3. Find file to import
    4. Data Preview - All fields entered according to file
    5. Import Method - SQL Loader utility
    6. Column Definitions - Mapped
    7. Options - Directory of files set
    8. Finish
    With the above steps I was not able to import 255 rows of data. No log file was produced so I don't know why it is failing.
    thanks.
    Edited by: user3261987 on Apr 16, 2012 1:23 PM

  • I need help with oracle

    Hi,
    I need some help... if someone can help its great.
    I need to make a statement in Oracle SQL that read data from a file and insert in a Oracle Database ... if someone can show me the syntax of it i appreciate..
    Thanks

    Okay, I see you followed the advice in that other thread and started a new post for you question. Congratulations. Your next lesson in forum etiquette is to give your posts a more relevant subject. Pretty much everybody who posts here needs help with oracle; if they need help with cooking catfish they've come to the wrong place.
    It that other thread I suggested using SQL*Loader or External Tables might be a more suitable solution. Find out more.
    Cheers, APC

  • Getting all possible ordering of vector

    hello
    I need to find all possible order of a set of vector I mean if I have the following:
    0
    1
    2
    all posssible would be:
    0 1 2, 1 0 2, 2 1 0, 1 2 0, 2 0 1, 0 2 1
    I have tried to use the swap but I didn't get all possible set
    I have used the following code:
    Code:
    for( int x=0;x<vector.size();x++)     {            
    for ( int w=0;w< vector.size();w++){
    Collections.swap(vector, x, w);}}
    as I said before the swap method didn't provide me the result I want
    can somebody tell me how to do it please urgent

    warnerja wrote:
    rdkh wrote:
    Sorry I had to wait a few days to do this for you. Here is a "very creative" solution:
    ... (code snipped)If by "very creative" you mean "incorrect" or at least "convoluted", then you're right.As I always ask questions, I watch for any chance to contribute to the forum. But as I don't have confidence and knowledge, I only post info I read in a book or google, and code that compiles/works correctly. As far as I can test, my code works correctly.
    I was inspired by a "very creative" way to calculate "pi" using a circle in a square and random numbers. With modern processors, knowing where to start and end is sometimes enough. Let my CPU tear into the problem, keep guessing to get "pi" to infinite precision, let the computer keep guessing until the requested collection of Vectors is found. While not AI, I find elegence in this approach.
    P.S.
    if(!used.contains(rnd)) {
    used.add(rnd);
    v.add(rnd);What's the point of both "used" and "v" containing exactly the same set of values? One of these is redundant.
    And have you heard about Random.nextInt(int n)?I just know very basic APIs (thats why I hang-out only on "New to Java" forum). As you told me: "Set<Integer> used = new HashSet<Integer>();" was not needed.
    And a special "thank you" goes out to you for trying to do a lazy bum's homework for him/her. May you end up "working with" such a person.ok, but I warned that my code is "proof of concept" and I said I wrote it just for fun, and it works correctly.
    Edited by: rdkh on Jan 11, 2010 4:58 PM

  • Problems when starting with oracle SQL developer

    Hello,
    I am very much new with oracle SQL developer. I use oracle 10g and have a database named 'pallabDB' with username: xxxxxx and paswd:yyyyyy. I have installed oracle SQL developer.But i am unable to start up.What i should do? If any body replies it will be a great help.Thanks in advance.

    But i am unable to
    start up.How to understand this sentence without confusion?
    Can you explain exactly what is your problem at start up of SQL Developer?

  • Can anyone help with facetime? im getting missed calls but it doesnt actually tell me i have an incoming call....and the person im trying to contact gets exactly the same.....just missed calls?

    can anyone help with facetime? im getting missed calls but it doesnt actually come up with an incoming call.....the person im trying to contact just gets missed calls also?

    I've noticed that once you miss a call on FaceTime on a desktop Mac, it won't work properly again until you restart the machine.
    I sent in Feedback so we'll see how that goes.

  • Help with an SQL Query on the Logger

    We are running UCCE 8.5(3) and need help with an SQL query. When I run the below I would also like to see skill group information(name preferably)? Any help would be greatly appreciated!
    select * from dbo.t_Termination_Call_Detail where DateTime between '10-11-2012 00:00:00:00' and
    '10-11-2012 23:59:59:59'

    David, thanks for replying.  Unfortunitly I don't know enough about SQL to put that into a query and have it return data.  Would you be able to give an example on what the query would look like?

  • Fill Array with all possible combinations of 0/1

    Hi,
    i'm looking for a fast way to fill an array, respectively an int[8], with all possible combinations of 0 and 1 (or -1 and 1, shouldn't make a difference).
    I kind of know how to do it using multiple loops but I assume there is a more elegant or at leaster "better" practice.
    Thanks,
    nikolaus
            static int cnt = 0;
         public static void main(String[] args) {
              int[] element = new int[]{1,1,1,1,1,1,1,1};
              Integer[] x = new Integer[2];
              x[0] = 1;
              x[1] = -1;
              for(int i7:x){
                   element[7] = i7;
                   for(int i6:x){
                        element[6] = i6;
                        for(int i5:x){
                             element[5] = i5;
                             for(int i4:x){
                                  element[4] = i4;
                                  for(int i3:x){
                                       element[3] = i3;
                                       for(int i2:x){
                                            element[2] = i2;
                                            for(int i1:x){
                                                 element[1] = i1;
                                                 for(int i0:x){
                                                      element[0] = i0;
                                                      cnt++;
              }Edited by: NikolausO on Oct 30, 2008 4:21 AM
    Edited by: NikolausO on Oct 30, 2008 4:22 AM

    pm_kirkham wrote:
    No I replied to message number 5. as the ' (In reply to #5 )' above my post indicates, which was in reply to (a reply) to Sabre150's post which wasn't using enhanced loops, nor has any obvious place where you could use that approach to fill the array.
    Though you could pass in an array of the values to fill the array with, and loop over those, instead of using 0 or 1, at which point Sabre's approach becomes the same as your OP, but without the manual unrolling:
    import java.util.Arrays;
    public class NaryCombinations {
    public interface CombinationHandler {
    void apply (int[] combination) ;
    public static void main(String[] args) {
    calculateCombinations(new int[]{-1, 0, 1}, 4, new CombinationHandler () {
    public void apply (int[] combination) {
    System.out.println(Arrays.toString(combination));
    public static void calculateCombinations (int[] values, int depth, CombinationHandler handler) {
    recursivelyCalculateCombinations(values, 0, depth, handler, new int[depth]);
    private static void recursivelyCalculateCombinations (int[] values, int index, int depth,
    CombinationHandler handler, int[] combination) {
    if (index == depth) {
    handler.apply(combination);
    } else {
    for (int value : values) {
    combination[index] = value;
    recursivelyCalculateCombinations(values, index + 1, depth, handler, combination);
    Which looks to use the same basic approach to the generalization I created shortly after posting the original.
    public class Scratch1
         * A 'callback' to be invoked with every combination
         * of the result.
        public interface Callback
             * Invoked for each combination.
             * <br>
             * Each call is passed an new instance of the array.
             * @param array the array containing a combination.
            void processArray(int[] array);
        public Scratch1(final int[] array, final Callback callback, final int... values)
            if (callback == null)
                throw new IllegalArgumentException("The 'callback' cannot be 'null'");
            if (array.length < 1)
                throw new IllegalArgumentException("The array length must be >= 1");
            if ((values == null) || (values.length < 1))
                throw new IllegalArgumentException("The 'values' must have be at least of length 2");
            callback_ = callback;
            values_ = values.clone();
            array_ = array;
        public Scratch1(final int order, final Callback callback, final int... values)
            this(new int[order], callback, values);
         * Generates every possible value and invokes the callback for each one.
        public void process()
            process(0);
         * Internal method with no logical external use.
        private void process(int n)
            if (n == array_.length)
                callback_.processArray(array_.clone());
            else
                for (int v : values_)
                    array_[n] = v;
                    process(n + 1);
        private final Callback callback_;
        private final int[] values_;
        private final int[] array_;
        public static void main(String[] args) throws Exception
            final Callback callback = new Callback()
                public void processArray(int[] array)
                    System.out.println(java.util.Arrays.toString(array));
            new Scratch1(6, callback, 2, 1, 0).process();

  • I need help with fp, i cannot get it to work. have tried everything

    i cannot get fp to work.  I have uninstalled and installed so many times.  I use IE9....it worked two months ago.

    thank you for your reply.  I am using Internet Exp. 9 and McAfee software.  It states it installs and when I open a video, receive message I need to upgrade.  I followed the directions for 32 bit vs 64 bit.   Adobe FP is under my programs????
    > Date: Thu, 8 Sep 2011 05:17:21 -0600
    From: [email protected]
    To: [email protected]
    Subject: I need help with fp, i cannot get it to work. have tried everything
    It won't work or just won't install?
    Which OS, browser(s), and anti-virus software are you using?
    If you're using the free Avira AntiVir(us) Personal software, then deactive the Webguard feature first before installing the Flash Player.
    >

  • All possible combinations of a column as applied to a unique entry?

    i am having trouble getting a loop to do what i want, if you
    can help me find out what i am doing wrong i would appreciate it:
    i have a database with 3 tables in it
    table 1 has a list of documents - each one having a primary
    key
    table 2 has a list of document properties, i will call them
    property A, B, and C - each one having a primary key
    table 3 is a "relational" table that has a column for a
    document's PK and a property's PK that that document has
    Example of table 3:
    docPK / propPK
    1 (Document 1) / 1 (A)
    2 (Document 2) / 1 (B)
    3 (Document 3) / 2 (B)
    1 (Document 1) / 2 (B)
    1 (Document 1) / 3 (C)
    i need to create a loop in ColdFusion that spits out the
    number of possible combinations that exist for each document
    so the correct output should look like:
    Property A
    Document 1
    Property B
    Document 1
    Document 2
    Document 3
    Property C
    Document 3
    Property A, Property B
    Document 1
    Proberty A, Property B, Property C
    Document 1
    this output displays all possible combinations of properties
    under the conditions of existing documents
    here is the loop i have so far that does not seem to be
    working for me,
    <cfoutput query="rsProperties">
    <ul>
    <cfloop from="0" to="# of properties per document"
    index="i">
    <li>
    <cfoutput group="propPK">
    <cfif i EQ "# of properties per document">
    [#Trim(propertyName)#]
    </cfif>
    </cfoutput>
    </li>
    <ul>
    <cfoutput group="docPK">
    <li><a href="">#Document
    Name#</a></li>
    </cfoutput>
    </ul>
    </cfloop>
    </ul>
    </cfoutput>
    my loop returns possible combinations, but it is not
    returning ALL possible combinations, for example it may only return
    Property A as a single instead of also returning singles Property B
    and C
    my query simply consists of a SELECT * FROM [the database]
    WHERE [the three tables are set equal (as a join)] AND WHERE
    [documents exist]
    i know this is all rather confusing but if you can help me
    make sense of it i will be grateful
    thanks for your time

    Read the cfoutput section of the cfml reference manual. If
    you don't have one, the internet does.
    Look for the example that shows you how to use the group
    attribute.

Maybe you are looking for

  • Fedex can only be used with dreamweaver using metric, not pounds (lbs)

    Fedex can only be used with dreamweaver using metric, not pounds (lbs), evidently? This as per their tier 2 tech suport. They say I should just convert to metric, no joke! Any ideas would be greatly appreaciated? Also a warning to anyone thinking of

  • Sound Problem in Compaq Presario CQ40-108TU

    I've Transcend 2GB DDR2 667 memory and put it in my laptop (Compaq Presario CQ40-108tu). It read the whole 4GB memory coz I'm using Windows Vista Ultimate 64-bit but it doesn't have an audio. I've try to troubleshoot it, first try it with only 2GB me

  • Ipad or Macbook air more questions

    I have an ipad and a iMac G5- intel core duo as host computer. We use airport extreme at home . I am considering the purchase of a new ipad 2 or a Macbook air My needs are mobility around the house as well as travel, place to up load photos during tr

  • ECC 6.0

    Hi , I want help on ECC 6.0. What differs the ABAP in Previous versions and ABAP in ECC 6.0 . and new features in ECC 6.0. like OOPS . Can any one help me out ?

  • Mobile Browser and LOV

    Hello, I have a mobile browser application to develop and I need something like a LOV mechanism. I saw that the inputListOfValues tag is not supported. I can't use the selectOneChoice for all the fields since they may be very big (in terms of data re