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

Hello guys I have a small predicatement which has me a little confused. I have a table similar to the following. (It is a sample of my real of the table. I use this to explain the original table containing 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' is wildcard character elements * (I inherit it and I can not change the table format) * I would like to make a query as follows

select tuid from test01 where fund= '100000' and org= '67130'
However I like to do is to retrieve all the records that have have these segments in them including ' x
in other words the output expected here would be

"TUID"                        "FUND"                        "ORG"                         
"9102416AB"                   "1XXXXX"                      "6XXXXX"                      
"9102416CC"                   "100000"                      "67130"                       
"915522211"                   "1000XX"                      "67XXX"                       
"566653456"                   "xxxxxx"                      "xxxxx"  
I started to write a massive sql statement that would have the 12 as the instruction inside, because I must compare the org and finance 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 someone give me a hand to come with this sql statement...

mlov83 wrote:
If I run the present

select tuid,fund, org
from   test01
where '100000' like translate(fund, 'xX','%%') and '67130' like translate(org, 'xX','%%');

That's what I

"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 bad, too. Looking for 6 characters ("100000"), but the funds on this line is 7 characters ("1XXXXXX").

and it's always get picked up.

That's why you should use the Joker _ instead of %

select  tuid, fund, org
from    test01
where  '100000' like translate (fund, 'xX', '__')
and    '67130'  like translate (org,  'xX', '__')
;

It is difficult to see, but in two calls to TRANSLATE, the 3rd argument is a string 2 ' _.

Tags: Database

Similar Questions

  • Get all possible combinations in SQL

    Hi all

    I try to get all possible combinations for a given set of points.

    For example, the elements (A, B, C) I want to output all possible combinations that are ordered from left to right:
    A
    B
    C
    AB
    AC
    BC
    ABC
    Basically, I want the sys_connect_by_path output, but instead of having groups that are concatenated in the same line, I want to have the lines. The query I bellow gives the output I want, but has the limitation that sys_connect_by_path can't handle more than 4,000 sizes.
    WITH t AS
     (SELECT 1 seqno,
             'A' txt
        FROM dual
      UNION ALL
      SELECT 2 seqno,
             'B' txt
        FROM dual
      UNION ALL
      SELECT 3 seqno,
             'C' txt
        FROM dual
      UNION ALL
      SELECT 4 seqno,
             'D' txt
        FROM dual),
    src AS
     (SELECT rownum combination_id,
             substr(sys_connect_by_path(txt, ','), 2) txt
        FROM t
      CONNECT BY seqno > PRIOR seqno)
    SELECT combination_id,
           regexp_substr(txt, '[^,]+', 1, l) list
      FROM (SELECT DISTINCT combination_id,
                            txt,
                            column_value l
              FROM src,
                   TABLE(CAST(MULTISET (SELECT LEVEL
                                 FROM dual
                               CONNECT BY LEVEL <= nvl(length(regexp_replace(src.txt, '[^,]+', NULL)), 0) + 1) AS
                              sys.odcivarchar2list)))
     ORDER BY combination_id,
              l;
    Is it possible to get this output in SQL without using sys_connect_by_path?

    Thanks in advance.

    Published by: Manuel Vidigal on March 21, 2011 10:45

    Hi, manual,.

    I'm not sure that I understand why you cannot use SYS_CONNECT_BY_PATH. You have thousands of lines? The number of combinations is 2 ^ N ^-1, so it will be billions of combinations!

    The problem you have only a few lines, but only the data you want to display are not a single character (as txt in your sample data), but may be present of the characters, and that is what exceeds the limit of 4000 characters?
    If Yes, you can use the SYS_CONNECT_BY_PATH on just the primary key and then join this list to get the data you really need, like this:

    WITH       got_path    AS
    (
         SELECT     SYS_CONNECT_BY_PATH (seqno, '/') || '/'          AS path
         FROM     t
         CONNECT BY     seqno > PRIOR seqno
    )
    SELECT       DENSE_RANK () OVER (ORDER BY  p.path)     AS c_num
    ,       t.txt
    FROM       got_path     p
    JOIN               t  ON   INSTR ( p.path
                                 , '/' || t.seqno || '/'
                              )    > 0
    ORDER BY  c_num
    ,            t.seqno
    ;
    

    c_num lists the combinations of 1, 2, 3... You can use the actual path (perhaps with the/s deleted) If you wish.

    Sven had a good idea, but it takes you to know how many lines is in the table and hardcode a lot of self-joins (minus 1) in the query. What a pity that you have Oracle 11.1. If you use Oracle 11.2, you can use the approach of Sven with a WITH recursive clause, without knowing how many lines there and with a fixed amount of coding.

  • Need help with Oracle SQL merge records according to date and term dates

    Hi all

    I need help to find this little challenge.

    I have groups and flags and effective dashboards and dates of term against these indicators according to the following example:

    GroupName Flag_A Flag_B Eff_date Term_date
    Group_ATHERETHERE2011010199991231
    Group_ANN2010010120101231
    Group_ANN2009010120091231
    Group_ANN2006010120081231
    Group_ANTHERE2004010120051231
    Group_ATHERETHERE2003010120031231
    Group_BNTHERE2004010199991231
    Group_BNTHERE2003010120031231

    As you can see, group_A had the same combination of (N, N) flag for three successive periods. I want to merge all the time periods with the same indicators in one. Where entry into force will be the most early (underlined) time period and end date will be later (underlined)

    So the final result should look like this:

    GroupName Flag_A Flag_B Eff_date Term_date
    Group_ATHERETHERE2011010199991231
    Group_ANN2006010120101231
    Group_ANTHERE2004010120051231
    Group_ATHERETHERE2003010120031231
    Group_BNTHERE2003010199991231

    Thanks for your help

    Here's the DDL script

    drop table TMP_group_test;

    create table TMP_group_test (groupname varchar2 (8))

    , flag_a varchar2 (1)

    , flag_b varchar2 (1)

    , eff_date varchar2 (8)

    , term_date varchar2 (8)

    );

    insert into TMP_group_test values ('Group_A', 'Y', 'Y', ' 20110101 ', ' 99991231');

    insert into TMP_group_test values ('Group_A', 'n', ' n ', ' 20100101 ', ' 20101231');

    insert into TMP_group_test values ('Group_A', 'n', ' n ', ' 20090101 ', ' 20091231');

    insert into TMP_group_test values ('Group_A', 'n', ' n ', ' 20060101 ', ' 20081231');

    insert into TMP_group_test values ('Group_A', 'n', 'Y', ' 20040101 ', ' 20051231');

    insert into TMP_group_test values ('Group_A', 'Y', 'Y', ' 20030101 ', ' 20031231');

    insert into TMP_group_test values ('Group_B', 'n', 'Y', ' 20040101 ', ' 99991231');

    insert into TMP_group_test values ('Group_B', 'n', 'Y', ' 20030101 ', ' 20031231');

    commit;

    Post edited by: user13040446

    It is the closest, I went to the solution


    I create two rows;

    Rnk1: partition by group name, order of eff_date / / desc: this grade will sort the records of the most recent and handed to zero for each group\

    Rnk2: (dense) partition by group name, flag_A, flagb: this grade for each combination of group\flag gives a number so that they are classified as "families".

    Then I use the function analytic min

    Min (eff_date) more (partition of GroupName, rnk2): the idea is that, for each Member of the same family, the new date is the min of the family (and the max for the date of the term), at the end I just need separate so that the duplicates are gone

    Now the problem. As you can see from the query below, records of 1 and 6 (as identified by rownum) are identified in the same family, because they have the same combination of flag, but they are not successive, so everyone must keep its own date of entry into force.

    If only I can make the distinction between these two that would solve my problem


    Query:


    Select rowNum,GroupName, flag_a, flag_b, eff_date, term_date, rnk1, rnk2

    , min (eff_date) more than (partition by GroupName rnk2( ) min_eff

    Of

    (

    Select rowNum,

    GroupName , flag_a , flag_b , eff_date , term_date

    rank() more than (partition by GroupName stopped by eff_date desc) rnk1

    DENSE_RANK() more than (partition by GroupName order by flag_A flag_B ( ) rnk2

    de dsreports . tmp_group_test

    ) order by rowNum

    Hello

    user13040446 wrote:

    Hi KSI.

    Thanks for your comments, you were able to distinguish between these lines highlight, but lost lines 2,3,4 which are supposed to have the same date min = 20060101.

    Please see the table wanted to see the final result I want to reach

    Thanks again

    This first answer is basically correct, but in the main query, you want to use the function MIN, not the analytical function aggregation and GROUP BY columns with common values, like this:

    WITH got_output_group AS

    (

    SELECT GroupName, flag_a, flag_b, eff_date, term_date

    ROW_NUMBER () OVER (PARTITION BY GroupName

    ORDER BY eff_date

    )

    -ROW_NUMBER () OVER (PARTITION BY GroupName, flag_a, flag_b)

    ORDER BY eff_date

    ) AS output_group

    OF tmp_group_test

    )

    SELECT GroupName, flag_a, flag_b

    MIN (eff_date) AS eff_date

    MAX (term_date) AS term_date

    OF got_output_group

    GROUP BY GroupName, flag_a, flag_b

    output_group

    ORDER BY GroupName

    eff_date DESC

    ;

    The result I get is

    GROUP_NA F F EFF_DATE TERM_DAT

    -------- - - -------- --------

    Group_A Y 20110101 99991231 Y

    N Group_A 20101231 20060101 N

    Group_A N 20051231 20040101 Y

    Group_A Y Y 20031231-20030101

    Group_B N Y 99991231 20030101

    which is what you asked for.

  • Operation range (get all possible combinations of characters)

    Hello
    Example: the string '1,2,4'
    Output:
    1, 2
    1, 4
    2, 4
    1,2,4

    Looking for a simple way.

    Thank you.

    Hello

    Here's one way:
    First, splits the string into a separate line for each item.
    Then use CONNECT BY and SYS_CONNECT_BY_PATH for all combinations of lines.

    WITH     separate_rows     AS
    (
         SELECT     REGEXP_SUBSTR ( txt
                         , '[^,]+'
                         , 1
                         , LEVEL
                         )          AS item
         FROM    (
                   SELECT     '1,2,4'     AS txt
                   FROM     dual
              )
         CONNECT BY     LEVEL <= 1 +REGEXP_COUNT ( txt
                                                , ','
                                         )
    )
    SELECT     SUBSTR ( SYS_CONNECT_BY_PATH (item, ',')
                , 2
                )     AS combination
    FROM     separate_rows
    WHERE     LEVEL     > 1
    CONNECT BY     item     > PRIOR  item
    ;
    

    REGEXP_COUNT was new in Oracle 11.1. In earlier versions, find the number of commas in txt by seeing how the LENGTH decreases when you delete them.

  • Need help with PL/SQL so and then select

    Hello guys, I am new to the PL/SQl programming (only Java experience) and I'm pretty stuck to my task. It would be great if you could help me. I am in programming with Oracle SQL * Plus Version 10.2.0.3.0

    Whenever a user logs on to the server a database entry is created with information about the logged-on user. I need to create a PL/SQL command that selects all the information from last month. Unfortunately, the date_stamp column has a certain weird format: 1131210 for December 10, 2013


    My idea so far:


    DECLARE

    v_today NUMBER;

    BEGIN

    v_today: = TO_NUMBER (TO_CHAR (SYSDATE, 'MM'));       -Save the number of the month (e.g.12) in v_today

    IF v_today = 01 THEN

    SELECT * from audittrl

    WHERE the date_stamp between 1131201 AND the 1131231;

    ELSIF v_today = 02 THEN

    SELECT * from audittrl

    WHERE the date_stamp between the 1130131 AND 1130101;

    .......

    END IF;

    END;

    /

    Error code: "an INTO clause in this SELECT statement.

    I do not want to save the result to select a variable, hope you can help me. Thanks in advance.

    Hello

    6a4d1bcd-c00e-4dac-AB64-9b6bdb1652d1 wrote:

    Thanks, I'll try that, if still get caught once, I'll be back. Anway I'm not sure of the solution of Chris227, because I can't test it right now. From my point of view it gives you information the current month (e.g., December) and not the month previous (-online November), or have I missed something. ?

    You are right.  In addition, it does not for a given year.  If you have data from several years in the table, it will select lines for the month of December 2012, 2011, 2010,... but also of 2013.

    Here's a way to get around that:

    DECLARE

    prev_month_start PLS_INTEGER: = TO_NUMBER (TO_CHAR (ADD_MONTHS (SYSDATE-1)

    , "YYMM"1' "01"

    )

    );

    this_month_start PLS_INTEGER: = TO_NUMBER (TO_CHAR (SYSDATE

    , "YYMM"1' "01"

    )

    );

    BEGIN
    FOR (IN) rec
    SELECT *.
    Of audittrl
    WHERE the date_stamp > = prev_month_start
    AND date_stamp< >
    ORDER BY user_id, date_stamp - or other

    )
    LOOP
    dbms_output.put_line (rec.date_stamp);
    dbms_output.put_line (rec.event);
    dbms_output.put_line (rec.user_id)
    dbms_output.put_line (rec.host_name);
    END LOOP;
    END;

    This should also be more effective, because it will allow the optimizer to use an index on date_stamp.  Even if there is no index, it will be more effective because it avoids calling any function (for example, SUBSTR) on each line of the table.

    You needn't PL/SQL to get these results.  Just use SQL, you might say:

    SELECT event, host_name, user_id and date_stamp
    Of audittrl
    WHERE the date_stamp > = TO_NUMBER (TO_CHAR (ADD_MONTHS (SYSDATE-1)
    , "YYMM"1' "01"
    )
    )
    AND date_stamp<  to_number="" (="" to_char="" (="" sysdate="" to_number="" (="" to_char="" (="">


    , "YYMM"1' "01"
    )
    )

    ORDER BY user_id, date_stamp - or other

    ;

    Your front end will provide column headers and touch the data so that the columns line up.  It can also set the output to a file.  (For example, if your front-end is SQL * Plus, you can use the command of the COIL.)

    I guess date_stamp is a NUMBER.  If it is a string, the solutions above can be simplified a bit.

    This problem (and many other problems) would be so much simpler if date_stamp was a DATE column.  Using numbers or strings to store the date information is simply asking for trouble.

  • All possible combinations of the strings in the array in PL/SQL

    Hello

    I'm trying to figure out how to build a list of all possible combinations of string values that are stored in a single table.

    There are several 'levels' (a level being of the order in which the value appears in the output string) and multiple values per level...

    I am using Oracle 10 g R2, and my table structure is as follows:
    --not the best naming conventions, but it works for discussion...
    CREATE TABLE FamilyValues
    (
      myID      INTEGER                             NOT NULL,
      FamilyID  INTEGER                             NOT NULL,
      myLevel     INTEGER                             NOT NULL,
      myValue     VARCHAR2(10)
    )
    
    insert into familyvalues values(1,1,1,'I',);
    insert into familyvalues values(2,1,1,'E',);
    insert into familyvalues values(3,1,2,'2',);
    insert into familyvalues values(4,1,2,'J',);
    insert into familyvalues values(5,1,2,'B',);
    insert into familyvalues values(6,1,3,'0',);
    insert into familyvalues values(7,1,3,'1',);
    insert into familyvalues values(8,1,3,'2',);
    insert into familyvalues values(9,1,3,'3',);
    insert into familyvalues values(10,1,3,'4',);
    insert into familyvalues values(11,1,3,'5',);
    insert into familyvalues values(12,1,3,'6',);
    insert into familyvalues values(13,1,3,'7',);
    insert into familyvalues values(14,1,3,'N',);
    insert into familyvalues values(15,1,3,'T',);
    insert into familyvalues values(16,1,3,'V',);
    insert into familyvalues values(17,1,3,'W',);
    insert into familyvalues values(18,1,4,'0',);
    insert into familyvalues values(19,1,4,'1',);
    insert into familyvalues values(20,1,4,'2',);
    insert into familyvalues values(21,1,4,'3',);
    insert into familyvalues values(22,1,4,'4',);
    insert into familyvalues values(23,1,4,'B',);
    insert into familyvalues values(24,1,4,'D',);
    insert into familyvalues values(25,1,4,'F',);
    insert into familyvalues values(26,1,4,'H',);
    insert into familyvalues values(27,1,4,'J',);
    insert into familyvalues values(28,1,4,'K',);
    insert into familyvalues values(29,1,4,'L',);
    insert into familyvalues values(30,1,4,'M',);
    insert into familyvalues values(31,1,4,'N',);
    insert into familyvalues values(32,1,4,'P',);
    insert into familyvalues values(33,1,4,'R',);
    insert into familyvalues values(34,1,4,'T',);
    insert into familyvalues values(35,1,4,'V',);
    insert into familyvalues values(36,1,4,'W',);
    insert into familyvalues values(37,1,4,'X',);
    insert into familyvalues values(38,1,4,'Y',);
    insert into familyvalues values(39,1,4,'Z',);
    I want to get results, for the sample data above (using only 3 levels for a reasonable amount of data):
    I     2     0
    I     2     1
    I     2     2
    I     2     3
    I     2     4
    I     2     5
    I     2     6
    I     2     7
    I     2     N
    I     2     T
    I     2     V
    I     2     W
    E     J     0
    E     J     1
    E     J     2
    E     J     3
    E     J     4
    E     J     5
    E     J     6
    E     J     7
    E     J     N
    E     J     T
    E     J     V
    E     J     W
    so far my best attempt is:
    select
        A.myValue || '-' || B.myValue || C.myValue || D.myValue
    from
        FamilyValues A
        FULL JOIN FamilyValues B ON (B.myLevel -1) = A.myLevel
        FULL JOIN FamilyValues C ON (C.myLevel -1) = B.myLevel
        FULL JOIN FamilyValues D ON (D.myLevel -1) = C.myLevel
    WHERE
        A.myValue IS NOT NULL
        AND B.myValue IS NOT NULL
        AND C.myValue IS NOT NULL
        AND D.myValue IS NOT NULL
    I read on the post to (Re: all possible combinations of string in PL/SQL but think it is a slightly different implementation...)

    I wish I could recusively pass by the table and make all possible combinations with each of the values in the table in the positions provided by the level...
    select ltrim(sys_connect_by_path(myValue,' ')) combination
      from  familyvalues
      where connect_by_isleaf = 1
      start with myLevel = 1
      connect by FamilyID = prior FamilyID
             and myLevel = prior myLevel + 1
    /
    COMBINATION
    --------------------------------
    I 2 0 0
    I 2 0 1
    I 2 0 2
    I 2 0 3
    I 2 0 4
    I 2 0 B
    I 2 0 D
    I 2 0 F
    I 2 0 H
    I 2 0 J
    I 2 0 K
    I 2 0 L
    I 2 0 M
    I 2 0 N
    I 2 0 P
    I 2 0 R
    I 2 0 T
    I 2 0 V
    I 2 0 W
    I 2 0 X
    I 2 0 Y
    I 2 0 Z
    I 2 1 0
    I 2 1 1
    I 2 1 2
    I 2 1 3
    I 2 1 4
    .
    .
    .
    

    SY.

  • Help with making SQL query references to column aliases in the Case statement

    I need help with a sql query that I'm trying. I can go about it the wrong way, but I would be grateful if I could get any suggestions on possible solutions. This is my query:


    SELECT DISTINCT spriden_pidm, spriden_id id, spriden_last_name | ',' | spriden_first_name name,

    CASE
    WHEN rcresar_comm_code_01 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_01
    WHEN rcresar_comm_code_02 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_02
    WHEN rcresar_comm_code_03 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_03
    WHEN rcresar_comm_code_04 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_04
    WHEN rcresar_comm_code_05 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_05
    WHEN rcresar_comm_code_06 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_06
    WHEN rcresar_comm_code_07 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_07
    WHEN rcresar_comm_code_08 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_08
    WHEN rcresar_comm_code_09 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_09
    WHEN rcresar_comm_code_10 IN ('268 ', '269', ' 270') THEN rcresar_comm_code_10
    END acg_elig_comm_code

    CASE
    WHEN acg_elig_comm_code = ' 268' THEN 'rigorous HS course. "
    WHEN acg_elig_comm_code = '269' THEN ' 2 or several AP or IB"
    WHEN acg_elig_comm_code = '270' THEN 'NOC as possible ".
    END comm_code_description

    OF spriden, rcresar, rcrapp1

    WHERE (rcresar_comm_code_01 IN ('268 ', '269', ' 270')

    OR rcresar_comm_code_02 ('268 ', '269', ' 270')

    OR rcresar_comm_code_03 ('268 ', '269', ' 270')

    OR rcresar_comm_code_04 ('268 ', '269', ' 270')

    OR rcresar_comm_code_05 ('268 ', '269', ' 270')

    OR rcresar_comm_code_06 ('268 ', '269', ' 270')

    OR rcresar_comm_code_07 ('268 ', '269', ' 270')

    OR rcresar_comm_code_08 ('268 ', '269', ' 270')

    OR rcresar_comm_code_09 ('268 ', '269', ' 270')

    OR rcresar_comm_code_10 ('268 ', '269', ' 270'))


    Rcresar_aidy_code = & aidy_code

    AND rcrapp1_aidy_code = rcresar_aidy_code

    AND rcrapp1_curr_rec_ind = 'Y '.

    AND rcrapp1_seq_no = rcresar_seq_no


    AND spriden_pidm = rcresar_pidm

    AND rcrapp1_pidm = rcresar_pidm


    AND spriden_change_ind IS NULL

    ORDER BY name


    The second case statement is where I don't know exactly what it takes to get what I want.

    Output should be like:
    spriden_pidm name ID acg_elig_comm_code comm_code_description
    «0000000000', ' 1111111111 ","John Doe","268", «rigorous HS race"»

    If I take the second case statement it works great except that I do not have my comm_code description column. My question is how can I use my first statement value box to determine this column? I think that I need a case statement as I have, but I don't know how to reference the value of acg_elig_comm_code. Any help would be greatly appreciated. Thank you.

    Published by: blackhole82 on January 20, 2009 09:20

    Hello

    You cannot use the alias column in the query, even where it is set (except in the ORDER BY clause).
    You can set the alias in a subquery and then use it in a great query, like this:

    WITH  sub_q  AS
    (
        SELECT DISTINCT spriden_pidm,spriden_id id, spriden_last_name||', '||spriden_first_name name,
            CASE
                WHEN rcresar_comm_code_01 IN ('268','269','270') THEN rcresar_comm_code_01
                WHEN rcresar_comm_code_02 IN ('268','269','270') THEN rcresar_comm_code_02
                WHEN rcresar_comm_code_03 IN ('268','269','270') THEN rcresar_comm_code_03
                WHEN rcresar_comm_code_04 IN ('268','269','270') THEN rcresar_comm_code_04
                WHEN rcresar_comm_code_05 IN ('268','269','270') THEN rcresar_comm_code_05
                WHEN rcresar_comm_code_06 IN ('268','269','270') THEN rcresar_comm_code_06
                WHEN rcresar_comm_code_07 IN ('268','269','270') THEN rcresar_comm_code_07
                WHEN rcresar_comm_code_08 IN ('268','269','270') THEN rcresar_comm_code_08
                WHEN rcresar_comm_code_09 IN ('268','269','270') THEN rcresar_comm_code_09
                WHEN rcresar_comm_code_10 IN ('268','269','270') THEN rcresar_comm_code_10
            END acg_elig_comm_code   -- Originally posted with , here (error)
        FROM spriden, rcresar, rcrapp1
        WHERE (rcresar_comm_code_01 IN ('268','269','270')
                OR rcresar_comm_code_02 IN ('268','269','270')
                OR rcresar_comm_code_03 IN ('268','269','270')
                OR rcresar_comm_code_04 IN ('268','269','270')
                OR rcresar_comm_code_05 IN ('268','269','270')
                OR rcresar_comm_code_06 IN ('268','269','270')
                OR rcresar_comm_code_07 IN ('268','269','270')
                OR rcresar_comm_code_08 IN ('268','269','270')
                OR rcresar_comm_code_09 IN ('268','269','270')
                OR rcresar_comm_code_10 IN ('268','269','270'))
        AND rcresar_aidy_code = &aidy_code
        AND rcrapp1_aidy_code = rcresar_aidy_code
        AND rcrapp1_curr_rec_ind = 'Y'
        AND rcrapp1_seq_no = rcresar_seq_no
        AND spriden_pidm = rcresar_pidm
        AND rcrapp1_pidm = rcresar_pidm
        AND spriden_change_ind IS NULL
    )
    SELECT    sub_q.*,
              CASE
                  WHEN acg_elig_comm_code = '268' THEN 'Rigorous HS course'
                  WHEN acg_elig_comm_code = '269' THEN '2 or more AP or IB'
                  WHEN acg_elig_comm_code = '270' THEN 'ACG possible'
              END comm_code_description
    FROM      sub_q
    ORDER BY  name
    

    Furthermore, you might think to rearrange your table, so that you do not have 10 columns (rcresar_comm_code_01, rcresar_comm_code_02,...) that essentially do the same thing. The usual way to handle this kind of one-to-many relationship is to have all rcresar_comm_codes in a separate table, one per line, with a pointer to the table where you have them now.

    Published by: Frank Kulash, January 20, 2009 11:35
    Syntax error has been corrected

  • Need help with a SQL query

    Hello

    I have a data in table (raj_table) with columns (char11) raj_id, raj_number (varchar2 (15)), raj_format (NUMBER), Primary_ID (identity with the values of the primary key column)

    Primary_ID raj_id Raj_number Raj_format

    1                            raj                 rajvend                      1

    2                            raj                 rajvend                      1

    3                            raj                 rajvendor1                 2

    4                            raj                 rajvendor1                 2

    5                            raj                 rajvendor1                 2

    6                            raj                 rajvendor2                 3

    I used under SQL to get query output as below, but has not achieved the required result:

    Select client_id vendor_number, vendor_format, primary_id, row_number() on sl_no (client_id partition, primary_id, vendor_format order of client_id primary_id, vendor_format, vendor_number, vendor_number)

    from raj_table by sl_no asc

    SL_NO raj_id raj_number raj_format primary_id

    1                   1                   raj              rajvendor                 1

    1                   2                  raj              rajvendor                 1

    2                   3                   raj              rajvendor1                2

    2                   4                   raj              rajvendor1                2

    2                   5                  raj               rajvendor1                2

    3                   6                    raj              rajvendor2                3

    I need help with a SQL query to get the result as above without using the group by clause. I want to bring together the combination of separate line of the three columns (raj_id, raj_number, raj_format) and add a unique serial number for each online game (SL_NO column below). So, above there are 3 unique set of (raj_id, raj_number, raj_format) I can get in a group by clause, but I can not add prmiary_id, SL_NO values if I group by clause. I used the analytical functions like row_number() but no luck. Need solution for this.

    with t as)

    Select 'raj' raj_id, 'rajvend' raj_number, 1 raj_format, 1 primary_id Union double all the

    Select option 2, 'raj', 'rajvend', 1 double Union all

    Select 3, 'raj', 'rajvendor1', 2 double Union all

    Select 4, 'raj', 'rajvendor1', 2 double Union all

    Select 5, 'raj', 'rajvendor1', 2 double Union all

    Select 6, 'raj', 'rajvendor2', 3 double

    )

    Select dense_rank() over (order of raj_id, raj_number, raj_format) sl_no,

    t.*

    t

    order by primary_id

    /

    PRIMARY_ID RAJ RAJ_NUMBER RAJ_FORMAT SL_NO
    ---------- ---------- --- ---------- ----------
    1 1 raj rajvend 1
    1 2 raj rajvend 1
    2 3 raj rajvendor1 2
    2 4 raj rajvendor1 2
    2 5 raj rajvendor1 2
    3 6 raj rajvendor2 3

    6 selected lines.

    SQL >

    SY.

  • Clicking on the tab help for help with photoshop first time get in "photoshop online help could not be displayed because you are not connected to internet" but I'm connected to the internet?

    Dear all

    I need help with the following problem:

    Clicking on the tab help for help with photoshop first time get in "photoshop online help could not be displayed because you are not connected to internet" but I'm connected to the internet.

    Appreaciate help on this problem.

    MSD

    I find it easier and faster to use just this link, which goes to the same place as aid > online help for Photoshop:

    Using Photoshop | Photoshop help

    To bookmark so that you can find.

  • Need help with PL/SQL query complex

    I need help with a query that need access to data from 3 tables. That's what I did

    I created 3 tables

    CREATE TABLE post_table
    (
    post_id varchar (20),
    datepost DATE,
    KEY (post_id) elementary SCHOOL
    ) ;

    CREATE TABLE topic
    (
    TOPIC_ID varchar (20),
    name varchar (20),
    PRIMARY KEY (topic_id)
    );

    CREATE TABLE blogpost_table
    (
    TOPIC_ID varchar (20),
    post_id varchar (20),
    PRIMARY KEY (topic_id, post_id);
    FOREIGN KEY (topic_id) REFERENCES topic (topic_id) ON DELETE CASCADE,
    FOREIGN KEY (post_id) REFERENCES post_table (post_id) ON DELETE CASCADE
    );


    Now, I inserted a few values in these tables as

    INSERT INTO post_table VALUES ('p1', to_date ('2009-09-14 18:00 "," MM/DD/YYYY mi:ss'));))
    INSERT INTO post_table VALUES ('p2', to_date ('2009-07-18 18:00 "," MM/DD/YYYY mi:ss'));))
    INSERT INTO post_table VALUES ('p3', to_date ('2009-07-11 18:00 "," MM/DD/YYYY mi:ss'));))
    INSERT INTO post_table VALUES ('p4', to_date ('2009-03-11 18:00 "," MM/DD/YYYY mi:ss'));))
    INSERT INTO post_table VALUES ('p5', to_date ('2009-07-13 18:00 "," MM/DD/YYYY mi:ss'));))
    INSERT INTO post_table VALUES ('p6', to_date ('2009-06-12 18:00 "," MM/DD/YYYY mi:ss'));))
    INSERT INTO post_table VALUES ('p7', to_date ('2009-07-11 18:00 "," MM/DD/YYYY mi:ss'));))

    INSERT INTO VALUES subject ("t1", "baseball");
    INSERT INTO category VALUES ('t2', 'football');

    INSERT INTO blogpost_table VALUES ("t1", "p1");
    INSERT INTO blogpost_table VALUES ('t1', 'p3');
    INSERT INTO blogpost_table VALUES ("t1", "p4");
    INSERT INTO blogpost_table VALUES ('t1', 'p5');
    INSERT INTO blogpost_table VALUES ('t2', 'p2');
    INSERT INTO blogpost_table VALUES ('t2', 'p6');
    INSERT INTO blogpost_table VALUES ("t2", "p7");


    I'm launching SQL queries on the table in this topic.

    I want to write a SQL query that returns me the name of a topic (s) and the number of blog_post (s) associated with the topic in descending order of the number of blog posts created in July.

    Can someone please help me to write this query?

    Thank you

    Published by: user11994430 on October 9, 2009 07:24

    Thanks for the test of the configuration!

    SQL>SELECT   t.NAME, COUNT(*)
      2      FROM topic t, blogpost_table b, post_table p
      3     WHERE b.topic_id = t.topic_id
      4       AND p.post_id = b.post_id
      5       AND p.datepost >= DATE '2009-07-01'
      6       AND p.datepost < DATE '2009-08-01'
      7  GROUP BY t.NAME
      8  ORDER BY COUNT(*) desc;
    
    NAME                   COUNT(*)
    -------------------- ----------
    baseball                      2
    soccer                        2
    

    HTH, Urs

  • Need help with query SQL Inline views + Group

    Hello gurus,

    I would really appreciate your time and effort on this application. I have the following data set.

    Reference_No---Check_Number---Check_Date---description---Invoice_Number---Invoice_Type---Paid_Amount---Vendor_Number
    1234567 11223 - 05/07/2008 -paid for cleaning- 44345563-I-* 20.00 *---19
    1234567 11223 - 05/07/2008 - 44345563 -a--10,00---19 ofbad quality adjustment
    7654321 11223 - 05/07/2008 - setting the last billing cycle - 23543556 - A - 50.00 - 19
    4653456 11223 - 05/07/2008 - paid for cleaning - 35654765 - I - 30, 00-19

    Please ignore '-' added for clarity

    I'm writing a paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, aggregate query Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Type, Invoice_Number, Vendor_Number. When there are no more records I want to display the respective Description.

    The query should return the following data set

    Reference_No---Check_Number---Check_Date---description---Invoice_Number---Invoice_Type---Paid_Amount---Vendor_Number
    1234567 11223 - 05/07/2008 -paid for cleaning- 44345563-I-* 10.00 *---19
    7654321 11223 - 05/07/2008 - setting the last billing cycle - 23543556 - A - 50.00 - 19
    4653456 11223 - 05/07/2008 - paid for cleaning - 35654765 - I - 30, 00-19
    Here's my query. I'm a little lost.

    Select b., A.sequence_id, A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
    de)
    Select sequence_id, check_number, check_date, invoice_number, sum (paid_amount) sum, vendor_number
    of the INVOICE
    Sequence_id group check_date, check_number, invoice_number, vendor_number
    ) A, B OF INVOICE
    where A.sequence_id = B.sequence_id


    Thank you
    Nick

    It seems that this is a duplicate thread - correct me if I am wrong in this case->

    Need help with query SQL Inline views + Group

    Kind regards.

    LOULOU.

  • The best way to generate all possible combinations of 5 digits

    Hi Experts,

    I'm on Oracle 11.2.0.2 on Linux. I have a task to generate all possible combinations of five digits (1 to 5) and each number can be used only once. I wrote the code below, but I wonder if this is optimal - or if it can be improved on. I will be grateful for your commens on this subject:

    DECLARE
    BEGIN
       FOR i IN 1 .. 5
       LOOP
          FOR j IN 1 .. 5
          LOOP
             IF i = j
             THEN
                CONTINUE;
             ELSE
                NULL;
             END IF;
             FOR k IN 1 .. 5
             LOOP
                IF (j = k OR i = k)
                THEN
                   CONTINUE;
                ELSE
                   NULL;
                END IF;
                FOR l IN 1 .. 5
                LOOP
                   IF (k = l OR i = l OR j = l)
                   THEN
                      CONTINUE;
                   ELSE
                      NULL;
                   END IF;
    
                   FOR m IN 1 .. 5
                   LOOP
                      IF (l = m OR i = m OR j = m OR k = m)
                      THEN
                         CONTINUE;
                      ELSE
                         NULL;
                      END IF;
                      DBMS_OUTPUT.put_line (
                         i || ' ' || j || ' ' || k || ' ' || l || ' ' || m);
                   END LOOP;
                END LOOP;
             END LOOP;
          END LOOP;
       END LOOP;
    END;
    /
    

    Thnaks,

    OrauserN

    Hello

    orausern wrote:

    Hi Frank

    Wow! It's all just awesome.

    Can you please elaborate more and explain this code? I mean that I do not understand how this sql. You can exaplain in detail how it works?

    Thanks again!

    OrauserN

    What, precisely, do you understand?  I guess it's CONNECT BY, I used twice.

    CONNECT is a feature that allows for recursion in SQL.  It includes an optional to BEGIN WITH and a clause CONNECT BY, which are both similar in a WHERE or HAVING clause conditions.  Which respect the terms of the START WITH clause are supposed to be at the level of the line = 1.  When it does not START WITH paragraph, all lines are LEVEL = 1.  (This is the case in two of my CONNECT garages).  A line is on LEVEL = N (N.1) if he meets the conditions CONNECT BY, when you look at some PREVIOUSLY already selected line in this query at level N-1 =.  It is often useful to consider the lines forming a graph oriented; the SYS_CONNECT_BY_PATH function returns a string that represents how we traveled through this graph to get each line of output.

    As used in the subquery called universe, START WITH is particularly difficult to understand.  For now, do not try to understand; just accept that it is a quick and convenient to generate a set of results with 5 rows, numbered from 1 to 5.  Let us look at the CONNECT BY the main query instead.  This query is very similar to this one, using the scott.dept table:

    SELECT path SYS_CONNECT_BY_PATH (deptno, ',')

    deptno

    LEVEL

    OF scott.dept

    DeptNo CONNECT BY NOCYCLE <> deptno PRIOR

    ;

    Output:

    DEPTNO LEVEL PATH
    -------------------- ---------- ----------
    , 10                         10          1
    , 10, 20                     20          2
    10, 20, 30 30 3
    10, 20, 30, 40 40 4
    10, 20, 40 40 3
    10, 20, 40, 30 30 4
    , 10, 30                     30          2
    10, 30, 20 20 3
    10, 20, 30, 40 40 4
    10, 30, 40 40 3
    10, 30, 40, 20 20 4
    , 10, 40                     40          2
    10, 40, 20 20 3
    10, 40, 20, 30 30 4
    10, 40, 30 30 3
    10, 30, 40 and 20-20-4
    , 20                         20          1
    , 20, 10                     10          2
    20, 10, 30 30 3
    ...

    40, 30, 20 20 3
    4 10 10, 20, 30, 40

    64 selected lines.

    As you can see, the above query shows all possible combinations of the 4 values distinct deptno.  The query starts by taking a line (in this case, the line with deptno = 10, I'll just say 10 in the future) and the place level = 1.  Then he sees what lines are connected to 10 (as defined by the CONNECT BY clause) and places them on LEVEL = 2.  All lines except 10 itself are connected to 10 of this affection.  Such a line is 20.  The lines are connected to 20?  Again, all the lines except 20 himself. (10 <> 20, so if you think 10 would seem still level = 3, but it is not.)  By default, CONNECT BY will raise an error if a line is connected to itself, directly or indirectly, as in the path ", 10, 20, 10'.»  The NOCYCLE keyword tells Oracle to ignore these connections rather than trigger an error).

    If there is a WHERE clause, it is applied after the CONNECT BY is completed.  In your problem, we did not all combinations, we wanted only the combinations that included all 5 lines, so I used a WHERE clause to display only lines that went up to the LEVEL of output = 5.

    For an introduction to CONNECT BY, see

    START BY and CONNECT in Oracle SQL

    or

    Hierarchical queries in Oracle & #8211; The CONNECT BY clause. Welcome to the server Oracle by Massimo Ruocchio

  • Best way to sum up all possible combinations (different) in a table?

    Hey guys,.

    Say that I have an array of sorted values (for mitigation), I want to build a table of all possible sums of these values, sorting, and then refer to him as a list of all the possible attenuation values (say theyre bits on a discrete digital attenuator).  I'll try to show you an example of what I mean with letters:

    Wait table: [a, b, c and d]

    I want a table like this: [a + b, a + c, a + d, a + b + c, a + b + d, a + c + d, b + c, b + d, b + c + d]... I hope that I'm not missing combos here...

    I enclose my attempt at this idea, but it lacks something I think, I'm doing something wrong...

    Thanks for any ideas or help them.

    The challenge will be to all possible combinations.

    Have you considered looking at this as a variation on binary counting?

    The total number of combinations is 2 ^ (NumberOfSettings) If you include 'None '.

    Then build a ramp between zero and the total number possible.

    Convert each number in a table of Boolean and then use the Boolean value to determine if its corresponding value gets add in total.

    After processing all the values of the ramp, the final table should be in ascending order.

    I hope this plan helps,

    Ben

  • Is Acrobat Pro just for us. We have an employee handbook that needs editing. A part is current pdf, some of an earlier version. You want to get all in a manual, the table of contents automatically adjust and links to specific pages of the table of content

    Is Acrobat Pro just for us. We have an employee handbook that needs editing. A part is current pdf, some of an earlier version. You want to get all in a manual, the table of contents automatically adjust and links to specific pages of the table of contents.

    Acrobat Pro is certainly not the right tool for editing. You want to change the manual using the source - MS Word files for example. Once you have the full changes including OCD work as you want, Acrobat Pro is the tool to convert the source document to PDF format, and ensure the accessibility requirements of 508 - and preferably ISO 14289 (PDF/UA) - are met.

  • Problems with Oracle sql developer

    Hello

    I have problems with my Oracle SQL developer 3.0.04 Version. It makes windows unstable once the query tries to display too many rows of data (for example, 300 k). Is there a way to solve this problem in addition to increasing the amount of physical memory? I currently have only 1 GB of RAM on this machine. Thank you.

    Hello

    Upgrading hardware can be a very satisfying experience, especially as it is almost always little expensive compared to the value of your time. Virtual memory / paging on the Windows and PC hardware is a huge disappointment, so more memory on Windows is a cure-all. With more and more common 64-bit operating systems, laptop computers and the PC is currently available with 8G of memory.

    That said, I think few users have a business case for the visualization of the hundreds of thousands of lines via a graphical user interface.

    Getting back to what concerns the management of memory in java, I want to put in a plug for the garbage and first new Garbage Collector. It will be the production in JDK 1.7, but can be found in the JDK 1.6 u14 & high in experimental option. The most recent revision update, the better it is. Just add something like this in your sqldeveloper.conf file:

    AddVMOption - XX: + UnlockExperimentalVMOptions
    AddVMOption - XX: + UseG1GC
    AddVMOption - XX: + G1YoungGenSize = 25 m
    AddVMOption - XX: + G1ParallelRSetUpdatingEnabled
    AddVMOption - XX: + G1ParallelRSetScanningEnabled

    It does a much better job of actually release unused memory in the context of the o/s.
    To learn more on this subject: http://www.oracle.com/technetwork/java/javase/tech/g1-intro-jsp-135488.html

    Gary Graham
    SQL DeveloperTeam

Maybe you are looking for

  • I have a problem of "Secure connection failed", access to an HTTPS site.

    I have a problem of "Secure connection failed", access to an HTTPS site. It is of this type: Your certificate contains the same serial number for another certificate issued by the certification authority. Please get a new certificate containing a uni

  • HP 630: Remove Bios password

    pls help me to remove the code for password bios generation after entering 3 times 54860105

  • Receive the message http 501 error / http 505 - please help

    Try to connect via a google account and e-mail at MandMDirect Web site.  Whenever I do this on any computer I get the error HTTP501/HTTP505.  I tried various changes according to the instructions to clear this problem but none have worked. One was to

  • How to install it?

    Hi, I just bought a used router WRT54G ver2, but with no sense and not a clue on how to install it.  I have phone/cable internet connection.  Please help ASAP!  Had been using a connection of neighbours for my Ipod touch and lost the connection yeste

  • HP Color Laserjet 277dw MFP: recording digitized files in smaller formats such as jpeg or pdf

    The scanner automatically saves files as TIF, which are too big for my needs. How can I change this setting to save the files scanned in JPEG or PDF format? (I scan using only HP Easy Scan of my computer, because my home computer is not on a network,