Please help me correct this SQL query...

hi, please consider following:
create table test(col varchar2(255))
insert into test values ('DURATION');
insert into test values ('VOLUME');
select col from test where col in ('DURATION','VOLUME');
this returns the rows.
but my input string is a comma separated list:
DURATION,VOLUME
so i try
select col from test where col in (replace('DURATION,VOLUME',',',''','''));
but no results. Or:
select col from test where col in (''''||replace('DURATION,VOLUME',',',''',''')||'''');
however
select ''''||replace('DURATION,VOLUME',',',''',''')||'''' from dual
gives 'DURATION','VOLUME'
so why doesnt it work?
hope you can help. Thanks

Another solution will be:
SQL> variable comma_sep_value VARCHAR2(100);
SQL> exec :comma_sep_value := 'DURATION,VOLUME,ABCD'
PL/SQL procedure successfully completed.
SQL> SELECT *
  2    FROM TEST
  3   WHERE INSTR (:comma_sep_value, col) > 0
  4  /
DURATION
VOLUME
2 rows selected.
SQL>  exec :comma_sep_value := 'DURATION';
PL/SQL procedure successfully completed.
SQL>  SELECT *
  2     FROM TEST
  3    WHERE INSTR (:comma_sep_value, col) > 0
  4   /
DURATION
1 row selected.
SQL>  exec :comma_sep_value := 'DURATION,VOLUME';
PL/SQL procedure successfully completed.
SQL> SELECT *
  2    FROM TEST
  3   WHERE INSTR (:comma_sep_value, col) > 0
  4  /
DURATION
VOLUME
2 rows selected.Hope this helps.
Regards,
Jo

Similar Messages

  • Please help me with this SQL query

    I am practicing SQL queries and have come across one involving fetching data from 3 different tables.
    The three tables are as below
    <pre>
    Country
    location_id          country
    loc1          Spain
    loc2          England
    loc3          Spain
    loc4          USA
    loc5          Italy
    loc6          USA
    loc7          USA
    </pre>
    <pre>
    User
    user_id location_id
    u1 loc1
    u2 loc1
    u3 loc2
    u4 loc2
    u5 loc1
    u6 loc3
    </pre>
    <pre>
    Post
    post_id user_id
    p1 u1
    p2 u1
    p3 u2
    p4 u3
    p5 u1
    p6 u2
    </pre>
    I am trying to write an SQL query - for each country of users, display the average number of posts
    I understand the logic behind this that we first need to group together all the locations and then the users belonging to one country and then find the average of their posts.
    But, i'm having a difficulty in putting this in SQL form. Could someone please help me with this query.
    Thanks.

    select
    country.country,
    count(*) Totalpostspercountry,
    count(distinct post.user_id) Totaldistincuserspercountry,
    count(*)/count(distinct post.user_id) Avgpostsperuserbycountry
    from
    country, muser, post
    where country.location_id = muser.location_id
    and muser.user_id = post.user_id
    group by country.country
    The output is like this for your sample data - hope this is what you were looking for :)
    COUNTRY,TOTALPOSTSPERCOUNTRY,TOTALDISTINCUSERSPERCOUNTRY,AVGPOSTSPERUSERBYCOUNTRY
    England,1,1,1,
    Spain,5,2,2.5,

  • I have comcast internet. Now I cannot open any of my e-mails.Please help me correct this problem. Comast is not the problem.

    I upgraded to a newer version of firefox. My ISP is Comcast.
    I tried opening up my e-mails they will not open up.I contacted Comcast ,they told me there customers have no problems opening their e-mails.Please help me with this problem asap.
    The problem started after I upgraded to the higher version.
    Thank you,
    Arnold
    My phone is: 313 882-9785

    If it's a thin 1 pixel wide vertical line it's highly likely it could be caused by a defective LCD.
    One quick basic way to check is to note the position of the line. Then go to System Preferences, Displays, and lower the resolution. If ther line moves it's on the video and the logic board or video card if fitted is likely to be defective. If the line stays in the same position it's likely to be an LCD fault. Either way to have it repaired you'll need to visit an Apple store or AASP.
    The worst offender for this problem is the Late 2006 17" iMac. FOC replacement of the LCD used to be covered by a quality program, but it's now ended.
    Steve

  • The font for my yahoo log in is very very small anbd my email fonts are far too big and the words overlap, please help to correct this problem

    The font for sign into my yahoo mail is so small that I am unable to make out my ID and password and when I do get into my mailbox, the fonts are far too big and the words overlap. Tried going into tools /options to make changes but not successful, please help.thanks

    Reset the page zoom on pages that cause problems, make sure that the window is not maximized:
    *<b>View > Zoom > Reset</b> (Ctrl+0 (zero); Cmd+0 on Mac)
    *http://kb.mozillazine.org/Zoom_text_of_web_pages
    If you have increased the minimum font size then try the default setting "none" as a high value can cause such issues.
    *Tools > Options > Content : Fonts & Colors > Advanced > Minimum Font Size (none)
    Make sure that you allow websites to choose their fonts.
    *Tools > Options > Content : Fonts & Colors > Advanced > [X] "Allow pages to choose their own fonts, instead of my selections above"
    You can use an extension to set a default font size and page zoom on web pages.
    *Default FullZoom Level: https://addons.mozilla.org/firefox/addon/default-fullzoom-level/
    *NoSquint: https://addons.mozilla.org/firefox/addon/nosquint/

  • Continuation-Please help with a complex sql query

    Hi all,
    Thanks a lot for your suggestions and inputs in the last thread of this post.
    With the help of your suggested approach,i went ahead and was able to get some more data in the format as needed..I worked on gradually adding one table after another exactly as the data is required stepwise.But,still I am facing issues with displaying them.
    there are many issues I am not able to do and would appreciate if you please have a look at my latest modified SELECT given below and help me writing it to get the display as needed.
    Below,is the attempted query i tried out using your inputs.But,am stuck and need your help in writing it.
    **Here,there is 1 ->MANY lines for the t_objective_id--->This has many learning_record_ids which i want to group by the unique objective_id.
    Also,prior to that,there is a tplan_id---->which has MANY t_objective_id's
    SELECT DECODE (LAG (firstname, 1, 0) OVER (ORDER BY firstname),
                   firstname, ' ',
                   firstname
                  ) firstname,
           DECODE (LAG (emplid, 1, 0) OVER (ORDER BY emplid),
                   emplid, ' ',
                   emplid
                  ) emplid,
           DECODE (LAG (tplan_name, 1, 0) OVER (ORDER BY tplan_name),
                   tplan_name, ' ',
                   tplan_name
                  ) tplan_name,
                  tplan_id,
                  DECODE (LAG (activities, 1, 0) OVER (ORDER BY activities),
                   activities, ' ',
                   activities
                  ) activities,
                  activities,
                  --activities,
           DECODE (LAG (t_objective_id, 1, 0) OVER (ORDER BY t_objective_id),
                   t_objective_id, ' ',
                   t_objective_id
                  ) t_objective_id,           
                   completed_activities,required_credits,
          DECODE (LAG (learning_record_id, 1, 0) OVER (ORDER BY learning_record_id),
                   learning_record_id, ' ',
                   learning_record_id
                  ) learning_record_id,           
                   catalog_item_name,catalog_item_type           
      FROM (SELECT test_cp.firstname, test_op.emplid, tp.tplan_name,tp.tplan_id,FN_TP_GET_CMPLTD_ACT_CNT(tp.tplan_id,test_lp.lp_person_id,'1862') activities,
                   test_tpo.t_objective_id,
                   (  fn_tp_obj_comp_req_act_cdt (test_lp.lp_person_id,
                                                  tp.tplan_id,
                                                  test_tpo.t_objective_id,
                                                  tp.is_credit_based
                    + fn_tp_obj_comp_opt_act_cdt (test_lp.lp_person_id,
                                                  tp.tplan_id,
                                                  test_tpo.t_objective_id,
                                                  tp.is_credit_based
                   ) completed_activities,test_tpo.required_credits,lr.learning_record_id,lr.catalog_item_name,lr.catalog_item_type
              FROM test_learning_plan test_lp,
                   test_training_plan tp,
                   test_person test_cp,
                   test_org_person test_op,test_tp_learning_activity test_tplplr,
                   test_tp_objective test_tpo,test_learning_record lr,test_train_obj_activity tpobjact
             WHERE test_lp.lp_person_id = '1862188559'
               AND test_cp.person_id = test_lp.lp_person_id
               AND tp.tplan_id = 'tplan200811200632352287621599'
               AND test_tpo.t_objective_id = tpobjact.t_objective_id
               AND test_lp.LP_CATALOG_HIST_ID = tp.tplan_id
               AND test_tplplr.tp_lp_lr_id =test_lp.learning_plan_id
               AND test_tplplr.activity_lp_lr_id = lr.learning_record_id
               AND lr.LR_CATALOG_HISTORY_ID = tpobjact.activity_id
               AND test_op.o_person_id = test_cp.person_id
               AND test_tpo.tplan_id = tp.tplan_id)
    If we see the outer SELECT ---then one of the main issues is for EACH t_objective_id----->There are n learning_record_ids.
    But,this select only shows 1 learning_record_id for each objective_id which is wrong.
    Similarly,the data displayed isnot proper.
    Below is the way I am getting the data now from the above SELECT.
    Note:- FIRSTNAME is not correctly displayed.
    FIRSTNAME     EMPLID     TPLAN_NAME     TPLAN_ID     ACTIVITIES     ACTIVITIES_1  
                      001                TP1          tplan1          5          5
    TESTNAME                                              tplan1           5          
    Continuation of the other columns of the same rows--**couldnt paste it properly so.
    T_OBJECTIVE_ID     COMPLETED_ACTIVITIES     REQUIRED_CREDITS     LEARNING_RECORD_ID        CATALOG_ITEM_NAME     CATALOG_ITEM_TYPE
              obj1               1                         5                         lr1                            C1                          Course
                    obj2               4                        4          

    Something like this might solve your problem ->
    satyaki>
    satyaki>select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    PL/SQL Release 10.2.0.1.0 - Production
    CORE    10.2.0.1.0      Production
    TNS for Linux: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>
    satyaki>select * from emp;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7521 WARD       SALESMAN        7698 22-FEB-81     226.88        500         30
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1815       1400         30
          7788 SCOTT      ANALYST         7566 19-APR-87     598.95                    20
          7839 KING       PRESIDENT            17-NOV-81       7260                    10
          7844 TURNER     SALESMAN        7698 08-SEP-81       2178          0         30
          7876 ADAMS      CLERK           7788 23-MAY-87     159.72                    20
          7900 JAMES      CLERK           7698 03-DEC-81     1379.4                    30
          7902 FORD       ANALYST         7566 03-DEC-81    5270.76                    20
          7934 MILLER     CLERK           7782 23-JAN-82     1887.6                    10
          7566 Smith      Manager         7839 23-JAN-82       1848          0         10
          7698 Glen       Manager         7839 23-JAN-82       1848          0         10
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7599 BILLY      ANALYST         7566 10-JUN-09       4500                    30
    12 rows selected.
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>
    satyaki>
    satyaki>
    satyaki>select decode(lag(job,1,null) over(order by job),'CLERK','CK',
      2                                                   'SALESMAN', 'SM',
      3                                                   'ANALYST','AL',
      4                                                   'BO') res
      5  from emp;
    RE
    BO
    AL
    AL
    AL
    CK
    CK
    CK
    BO
    BO
    BO
    SM
    RE
    SM
    12 rows selected.
    Elapsed: 00:00:00.01
    satyaki>
    satyaki>
    satyaki>select MAX(decode(lag(job,1,null) over(order by job),'CLERK','CK',
      2                                                   'SALESMAN', 'SM',
      3                                                   'ANALYST','AL',
      4                                                   'BO')) res
      5  from emp;
    select MAX(decode(lag(job,1,null) over(order by job),'CLERK','CK',
    ERROR at line 1:
    ORA-30483: window  functions are not allowed here
    Elapsed: 00:00:00.01
    satyaki>
    satyaki>select MAX(res)
      2  from (
      3          select decode(lag(job,1,null) over(order by job),'CLERK','CK',
      4                                                           'SALESMAN', 'SM',
      5                                                           'ANALYST','AL',
      6                                                           'BO') res
      7          from emp
      8     );
    MA
    SM
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>Regards.
    Satyaki De.

  • Can someone help me correct this sql statement in a jsp page?

    ive been getting the java.sql.SQLException: Incorrect syntax error for one of my sql nested statements. i cant seem to find similar egs online, so reckon if anyone here could help, really appreciate it.
    as im putting the nested sql in jsp page, it has to be with lots of " " n crap. very confusing if there are nested.
    heres the sql statement without those "" that i want to use:
    select top 5 * from(
    select top+"'"+offset+"'"+" * from prod where cat=" +"'" cat "'"+"
    )order by prodID desc
    when i put this in my jsp pg, i had to add "" to become:
    String sql = "select top 5 * from("+"select top"+"'"+offset+"'"+" * from prod where cat=" +"'" +cat+ "'"+")order by prodID desc";cat=" +"'" cat "'"+")order by prodID desc";
    all those "" are confusing me to no end, so i cant figure out what should be the correct syntax. the error says the syntax error is near the offset.

    If offset is, say, 10, and cat is, say, "new", then it looks like you're going to produce the SQL:
    select top 5 * from(
      select top '10' * from prod where cat='new'
    )order by prodID descThat looks exactly like incorrect syntax to me... top almost certainly can't handle a string literal as its operand... you almost certainly would want "top 10" instead of "top '10'"...
    If you use PreparedStatement, you don't have to remember what you quote and what you don't and you can have your SQL in a single static final string to boot...

  • Require help to solve this sql query

    Hi
    With the help of sql I a making report.But there is a problem
    my query is like....
    select x,y,(select count(z) from tab)
    from tab1
    now i want data ' y' columnwise
    suppose y is a circle(CITYs in particualr region) and x is a region(SOUTH,NORTH,EAST,WEST)
    i want regionwise circle details
    i Know about group by but it doesnt work here..

    Hi,
    YAL regarding [pivot | http://asktom.oracle.com/pls/ask/search?p_string=%22rows+to+columns%22]
    Edited by: hoek on Jun 18, 2009 9:46 AM fixed link

  • Please help me correct this code

    Hi, I have to develop a Java applications that converts a positive number from base 10 to another base. It has to prompt the user to enter the number to be converted an the base to be converted into. After conversion is completed, the program should ask for another conversion. The program would run in a loop until the user would decide to end it. In case of an error entry as a base less than 2, the program should warn the user about the type of error and ask the user to re-enter the values. At the nd of the program, provide a statistic with how many conversions the user has done.
    Please look at code below, and see where i went wrong, i can't seem to figure out the formula for conversions.
    import java.io.*;
    public class Class1
         public static void main (String[] args)throws IOException
              int num=0;
              int base=0;
              int result;
              int rem;
              int arr[]=new int[20];
              int count=0;
              boolean prompt= true;
              for(int i=0; i<arr.length; i++)
                             while(prompt)
              //int i=0     ;
              String s;
              int x;
              BufferedReader aa =
                             new BufferedReader(new InputStreamReader(System.in));
              System.out.println("Enter a positive number for the conversion:");
              s = aa.readLine();
              num = Integer.parseInt(s);
                   System.out.println("Enter the base number that you want to convert your number:");
                   s=aa.readLine();
                   base = Integer.parseInt(s);
                   if(base >= 2)
                        if(num > 0)
                        {   rem= num%base;
                             num=num/base;
                             arr=rem;
                             System.out.println("The converted number is: " + arr[i]);
                             System.out.print("Would you like to go on (yes/no)?");
                             s=aa.readLine();
                             prompt= s.equalsIgnoreCase("no");
                             count++;
                             //i++;     
                        else
                             System.out.println("The number must be greater that 0, please enter an other number!!");
                   else
                        System.out.println("The base number is not the appropriate,must be greater of two!!");
                   //promt the user if he/she wants to continiue or not
                   System.out.println("You have used the conversion thingy " count " times, You Freak!");
                   System.in.read();

    Since I have already started this I will try to make the conversion work. ( usually I do not like to to other people's homework ).
    import java.io.*;
    public class Class1
         static char[] theDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
         public static void main (String[] args)throws IOException
              int num=0;
              int base=0;
              int result;
              int rem;
              String arr[]=new String[20];
              int count=0;
              boolean prompt= true;
              for(int i=0; i<arr.length && prompt; i++)     {
                   while(prompt) {
                        String s;
                        int x;
                        BufferedReader aa =
                        new BufferedReader(new InputStreamReader(System.in));
                        System.out.println("Enter a positive number for the conversion:");
                        s = aa.readLine();
                        num = Integer.parseInt(s);
                        System.out.println("Enter the base number that you want to convert your number:");
                        s=aa.readLine();
                        base = Integer.parseInt(s);
                        if( base >= 2 && base < 17 ) {
                             if (num > 0)     {
                                  s = "";
                                  while ( num > 0 ) {
                                       rem= num%base;
                                       s = theDigits[rem] + s;
                                       num=num/base;
                                  arr[count] = new String(s);
                                  count++;
                                  //promt the user if he/she wants to continiue or not
                                  System.out.println("The converted number is: " + s + " base " + base );
                                  System.out.print("Would you like to go on (yes/no)?");
                                  s=aa.readLine();
                                  prompt= s.equalsIgnoreCase("yes");
                             else
                                  System.out.println("The number must be greater that 0, please enter an other number!!");
                        else
                             System.out.println("The base number is not the appropriate,must be greater of two and lower of 17!!");
              System.out.println("You have used the conversion thingy " +count +" times, You Freak!");
              System.in.read();
    }kurt

  • Please help me correct this

    import java.util.*;
    public class ThirteenCards
    {//1
    Card[] hand;
    ArrayList<Card> deck;
    Random rand;
         public ThirteenCards()
         {//2
              deck = Card.newDeck();
              rand = new Random();
              hand = makeHand();
              printHand();
         }//2
         Card[] makeHand()
         {//3
         Card[] deal = new Card[13];
         Arrays.fill(deal, null);
         for (int i = 0; i < deal.length; ++i)
         deal[i] = pickCard(deal);
         return deal;
         }//3
         Card pickCard(Card[] dealt)
         {//4
              int i = rand.nextInt(52);
              Card c = deck.get(i);
              if (! got(c, dealt))
                   return c;
              else
                   return pickCard(dealt);
         }//4
         boolean got(Card card, Card[] ca)
         {//5
              Card cc;
              int i = 0;
              while ((cc = ca[i++]) != null)
                   if (cc.equals(card))
                        return true; // already got } } return false; }
                   return false;
              }//5
         public void printHand()
         {//6
              Card[] spades = new Card[13];
              Card[] diamonds = new Card[13];
              Card[] clubs = new Card[13];
              Card[] hearts = new Card[13];
              Arrays.fill(spades, null);
              Arrays.fill(diamonds, null);
              Arrays.fill(clubs, null);
              Arrays.fill(hearts, null);
              int si, di, ci, hi;
              si = di = ci = hi = 0;
              for (Card c : hand)
              {//a
                   System.out.print(c + ", ");
                   switch(c.suit())
                   {//b
                        case SPADES : spades[si++] = c;
                        break;
                        case DIAMONDS : diamonds[di++] = c;
                        break;
                        case CLUBS : clubs[ci++] = c;
                        break;
                        case HEARTS : hearts[hi++] = c;
                   }//b
              }//a
                        System.out.println();
                        System.out.print("Spades : ");
                        for (Card c : spades)
                        {//c
                             if (c == null)
                             { break;
                             }//c
                             System.out.print(ra(c) + ", ");
         }//6
                        System.out.println();
                        System.out.print("Diamonds : ");
                        for (Card c : diamonds)
                             if (c == null)
                                  break;
                             System.out.print(ra(c) + ", ");
                             System.out.println();
                             System.out.print("Clubs : ");
                             for (Card c : clubs)
                                  if (c == null)
                                       break;
                                  System.out.print(ra(c) + ", ");
                             System.out.println();
                             System.out.print("Hearts : ");
                             for (Card c : hearts)
                                  if (c == null)
                                  { break;
                                  System.out.print(ra(c) + ", ");
                                  System.out.println();
    //                         System.out.println();
                             String ra(Card c)
                                  String s = c.getString();
                                  return s.substring(0, s.indexOf(" "));
                        public void printHandInShortForm()
                                  Card[] spades = new Card[13];
                                  Card[] diamonds = new Card[13];
                                  Card[] clubs = new Card[13];
                                  Card[] hearts = new Card[13];
                                  Arrays.fill(spades, null);
                                  Arrays.fill(diamonds, null);
                                  Arrays.fill(clubs, null);
                                  Arrays.fill(hearts, null);
                                  int si, di, ci, hi;
                                  si = di = ci = hi = 0;
                                  for (Card c : hand)
                                       System.out.print(sf(c) + " ");
                                       switch(c.suit())
                                            case SPADES : spades[si++] = c;
                                            break;
                                            case DIAMONDS : diamonds[di++] = c;
                                            break;
                                            case CLUBS : clubs[ci++] = c;
                                            break;
                                            case HEARTS : hearts[hi++] = c;
                                            System.out.println();
                                            System.out.print("Spades : ");
                                            for (Card c : spades)
                                            if (c == null)
                                                 { break;
                                                 System.out.print(sfr(c) + " ");
                                                 System.out.println();
                                                 System.out.print("Diamonds : ");
                                                 for (Card c : diamonds)
                                                      if (c == null)
                                                      break;
                                                      System.out.print(sfr(c) + " ");
                                                 System.out.println();
                                                 System.out.print("Clubs : ");
                                                 for (Card c : clubs)
                                                      if (c == null)
                                                           break;
                                                      System.out.print(sfr(c) + " ");
                                                      System.out.println();
                                                      System.out.print("Hearts : ");
                                                      for (Card c : hearts)
                                                           if (c == null)
                                                                break;
                                                           System.out.print(sfr(c) + " ");
                                                           System.out.println();
                                                           String sf(Card c)
                                                                String s, r;
                                                                s = r = null;
                                                                switch (c.suit())
                                                                     case SPADES : s = "s";
                                                                     break;
                                                                     case DIAMONDS : s = "d";
                                                                     break;
                                                                     case CLUBS : s = "c";
                                                                     break;
                                                                     case HEARTS : s = "h";
                                                      switch (c.rank())
                                                           case DEUCE : r = "2";
                                                           break;
                                                           case THREE : r = "3";
                                                           break;
                                                           case FOUR : r = "4";
                                                           break;
                                                           case FIVE : r = "5";
                                                           break;
                                                           case SIX : r = "6";
                                                           break;
                                                           case SEVEN : r = "7";
                                                           break;
                                                           case EIGHT : r = "8";
                                                           break;
                                                           case NINE : r = "9";
                                                           break;
                                                           case TEN : r = "10";
                                                           break;
                                                           case JACK : r = "j";
                                                           break;
                                                           case QUEEN : r = "q";
                                                           break;
                                                           case KING : r = "k";
                                                           break;
                                                           case ACE : r = "a";
                                                           return r + s;
                                                           String sfr(Card c)
                                                           String sf = sf(c);
                                                           return sf.substring(0, sf.length() - 1);
    public static void main(String[] args)
    ThirteenCards tc = new ThirteenCards();
    System.out.println();
    System.out.println("[short forms]");
    tc.printHandInShortForm();
    }//1
    I get the following error
    ThirteenCards.java:133: 'class' or 'interface' expected
         String ra(Card c)
    ^
    1 error

    MULTI POST
    http://forum.java.sun.com/thread.jspa?threadID=714652&tstart=0

  • Help me write a SQL query; urgent

    Hi, can somebody please help me write a SQL query.
    I have 3 tables each with the same column names (Col1, Col2, Col3). Col1 is PK with Unique Constraint.
    I wanted to add values of Col2 and Col3 (from all 3 tables) and put it in a separate table (i.e aggregated) of all values found in Col1.
    Does anybody help me please ?
    thanks alot.

    Please don't mark your question as urgent. You've been around here long enough that you should know that it will not get your question anwered any faster, and may just irritate people into not answering at all.
    I'm not sure exactly what you want.
    Are you saying you want t1.c2 + t1.c3 + t2.c2 + t2.c3+ t3.c2 + t3.c3 for the rows that have the same c1 in all three tables?
    If so, it would be like this, I think: insert into t4
    select t1.c1
    , t1.c2 + t1.c3 + t2.c2 + t2.c3+ t3.c2 + t3.c3
    from t1, t2, t3
    where t2.c1 = t1.c1
    and t3.c1 = t1.c1If that's not what you want, please clarify.
    And next time maybe you should post your SQL question in a SQL forum.

  • Please help to modifiy this query for better performance

    Please help to rewrite this query for better performance. This is taking long time to execute.
    Table t_t_bil_bil_cycle_change contains 1200000 rows and table t_acctnumberTab countains  200000 rows.
    I have created index on ACCOUNT_ID
    Query is shown below
    update rbabu.t_t_bil_bil_cycle_change a
       set account_number =
           ( select distinct b.account_number
             from rbabu.t_acctnumberTab b
             where a.account_id = b.account_id
    Table structure  is shown below
    SQL> DESC t_acctnumberTab;
    Name           Type         Nullable Default Comments
    ACCOUNT_ID     NUMBER(10)                            
    ACCOUNT_NUMBER VARCHAR2(24)
    SQL> DESC t_t_bil_bil_cycle_change;
    Name                    Type         Nullable Default Comments
    ACCOUNT_ID              NUMBER(10)                            
    ACCOUNT_NUMBER          VARCHAR2(24) Y    

    Ishan's solution is good. I would avoid updating rows which already have the right value - it's a waste of time.
    You should have a UNIQUE or PRIMARY KEY constraint on t_acctnumberTab.account_id
    merge rbabu.t_t_bil_bil_cycle_change a
    using
          ( select distinct account_number, account_id
      from  rbabu.t_acctnumberTab
          ) t
    on    ( a.account_id = b.account_id
           and decode(a.account_number, b.account_number, 0, 1) = 1
    when matched then
      update set a.account_number = b.account_number

  • Could you please help me make this query less complicated

    could you please help me make this query less complicated
    select t1.R_OBJECT_ID
    from dm_relation_sp a, ddt_resolution_sp t1
    where a.parent_id = '0900000283560456' -----------ID
    and a.child_id = t1.R_OBJECT_ID
    union all
    select t3.R_OBJECT_ID
    from ddt_resolution_sp t3
    where t3.R_OBJECT_ID in (select t2.child_id
    from dm_relation_sp t2
    where t2.parent_id in (select a.child_id
    from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
    where a.parent_id = '0900000283560456' -----------ID
    and a.child_id = t1.R_OBJECT_ID))
    union all
    select t4.R_OBJECT_ID
    from ddt_resolution_sp t4
    where t4.R_OBJECT_ID in(
    select t3.child_id from dm_relation_sp t3
    where t3.parent_id in (
    select t2.child_id
    from asud_fsk.dm_relation_sp t2
    where t2.parent_id in (select a.child_id
    from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
    where a.parent_id = '0900000283560456' -----------ID
    and a.child_id = t1.R_OBJECT_ID))
    and t3.relation_name = 'RESOLUTION_RELATION')
    union all
    select t5.R_OBJECT_ID
    from ddt_resolution_sp t5
    where t5.R_OBJECT_ID in
    (select t4.child_id
    from dm_relation_sp t4
    where t4.parent_id in(
    select t3.child_id from dm_relation_sp t3
    where t3.parent_id in (
    select t2.child_id
    from asud_fsk.dm_relation_sp t2
    where t2.parent_id in (select a.child_id
    from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
    where a.parent_id = '0900000283560456' -----------ID
    and a.child_id = t1.R_OBJECT_ID))
    and t3.relation_name = 'RESOLUTION_RELATION')
    and t4.relation_name = 'RESOLUTION_RELATION')
    Edited by: user13025450 on 29.04.2010 16:23

    Hi,
    Welcome to the forum! You'll find that there are many qualified people (such as Tubby) willing to help you. Will you do what you can to help them? In order to simplify the query you posted,someone will first have to understand what it does, what the tables that it uses are like, and what tools you have to work with (that is, what version of Oracle, and any other software you are using). To actually test their ideas, people will need versions of your tables.
    Many people, if they spent enough time, might be able to figure out roughly what you are doing, make some tables themselves and test a solution. You can help with all of that. I assume you already know what the appliction is, and what this particular query is supposed to do: you don't have to figure out any of that, you just have to say it. You know what all your tables are, what the datatypes of all the columns are, and what kinds of data are in the tables: you don't have to guess at any of that.
    Describe what you're doing. Think about it: how do we know that
    SELECT  NULL
    FROM    dual;doesn't do what you want?
    Post CREATE TABLE and INSERT statements for a little sample data.
    Post the results that this query is supposed to produce from those results. (Is it producing the right output now? Then it should be easy to post the correct results.)
    Describe, as well as you can, how the present query is doing it.
    Format your existing code, so it's easy to see what the different branches of the UNION are, and what the main clauses are in each one.
    When posting formatted text (code or results) type these 6 characters
    \(all small letters, inside curly brackets) before and after each formatted section, to keep this site from compressing the spaces.
    Say what versions of Oracle (e.g. 10.2.0.3.0) and any other relevant software you are using.
    I know it's a lot of work, but it really helps. You can do it as well (probably better) than anyone else, and if you're unwilling to do it, why should anyone else be willing?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Query Issue in Creating a View....Please help me with this query..

    I would like to create a view on this table with four columns
    1. PN#_EXP_DATE
    2. PN#
    3. PN#_EFF_DATE
    4. PN#
    P_S_C     A_C     P     EXP_DT
    21698     13921     1     5/29/2009 3:15:41 PM     
    21698     13921     1     5/29/2009 3:54:57 PM     
    21698     1716656     4     5/29/2009 3:15:41 PM     
    21698     3217     3     5/29/2009 3:15:40 PM     
    21698     3217     3     5/29/2009 3:54:57 PM     
    21698     60559     2     5/29/2009 3:15:41 PM     
    21698     60559     2     5/29/2009 3:54:57 PM     
    I have a trigger on A, which inserts the DML records into B. (Table A and B structure is the almost the same,
                                       where table B will have one extra column exp_dt)
    NOw Table B can have records with same P_S_C and A_C columns and exp_dt will capture the history.
    for example: from the above sample data, let us take first two records..
    P_S_C     A_C     P     EXP_DT
    21698     13921     1     5/29/2009 3:15:41 PM     --- Record 1
    21698     13921     1     5/29/2009 3:54:57 PM     --- Record 2
    from this..
    Note: 1. Table A and Table C can be joined using A.P_S_C and C.R_C to get the start_date.
    2. PN# comes from table D. It contains numbers for the resp. weeks.
    3. PN#_EFF_DATE is the previous immediate previous date for that record in history table (Table B).
    I wanted the data like..
    ---- this is for the second record in the above..
    PN#_EXP_DATE PN# PN#_EFF_DATE PN#
    5/29/2009 3:54:57 PM     214 5/29/2009 3:15:41 PM     214
    ---- this is for the first record in the above..
    PN#_EXP_DATE PN# PN#_EFF_DATE PN#
    5/29/2009 3:54:41 PM     214 ( for this we should query the table C to get the
                        start_date, for this combinatation of P_S_C and A_C in table B
                             where B.P_S_C = C.A_C
                             and that value should be the EFF_DT for this record)
    Please help me with this....
    Thanks in advance..

    Hi All,
    select d.P# as "PN#_EXP_DATE", exp_date
    from daily_prd d, cbs1_assoc_hist b
    where to_char(d.day_date,'MM/DD/YYYY') = to_char(b.exp_date,'MM/DD/YYYY')
    and d.period_type = 'TIMEREPORT';
    This above query gives the output as follows:
    pn#_exp_date exp_date
    214     5/29/2009 3:15:40 PM
    214     5/29/2009 3:15:41 PM
    214          5/29/2009 3:15:41 PM
    214          5/29/2009 3:15:41 PM
    214          5/29/2009 3:54:57 PM
    214          5/29/2009 3:54:57 PM
    214          5/29/2009 3:54:57 PM
    This below is the data from history table (Table B).
    P_S_C     A_C PLACE EXP_DATE
    21698          3217          3     5/29/2009 3:15:40 PM     
    21698          13921          1     5/29/2009 3:15:41 PM     
    21698          1716656          4     5/29/2009 3:15:41 PM     
    21698          60559          2     5/29/2009 3:15:41 PM     
    21698          13921          1     5/29/2009 3:54:57 PM     
    21698          3217          3     5/29/2009 3:54:57 PM     
    21698          60559          2     5/29/2009 3:54:57 PM     
    I got the pn#_exp_date from the Table 'D', for the given exp_date from Table B.
    My question is again....
    CASE - 1
    from the given records above, I need to look for exp_date for the given same P_S_C and A_C.
    in this case we can take the example...
    P_S_C     A_C PLACE EXP_DATE
    21698          3217          3     5/29/2009 3:15:40 PM
    21698          3217          3     5/29/2009 3:54:57 PM
    In this case, the
    pn#_exp_date exp_date     pn#_eff_date eff_date
    214     5/29/2009 3:15:57 PM     < PN# corresponding to the     5/29/2009 3:15:40 PM
                        eff_date .>
                        <Basically the eff_date is
                        nothing but the exp_date only.
                        we should take the immediate before one.
    In this case, our eff_date is '5/29/2009 3:15:40 PM'.
    but how to get this.
    CASE - 2
    from the above sample data, consider this
    P_S_C     A_C PLACE EXP_DATE
    21698     1716656     4     5/29/2009 3:15:41 PM
    In this case, there is only one record for the P_S_C and A_C combination.
    The expected result :
    pn#_exp_date exp_date               pn#_eff_date eff_date
    214     5/29/2009 3:15:41 PM     < PN# corresponding to the     5/29/2009 3:15:40 PM
                        eff_date .>
                   <Basically the eff_date is
                   nothing but the exp_date only.
                        we should take the immediate before one.
    In this case to get the eff_date, we should query the Table 'C', to get the eff_date, which is START_DT column in this table.
    for this join B.P_S_C and C.R_C.
    Hope I am clear now..
    Thanks in advance.....

  • Please help me formulate this in PL/SQL - Thanks.

    Hi ALL,
    Please help me formulate this in PL/SQL. I really appreciate your help in advance. Below is the Specification.
    Read Previous records
    Check if this is a New Customer.
    If New
    Than check for New site
    If New Site than Insert Site
    End If
    Insert Practice
    Insert Customer
    Check for Previous Months Balance for that Customer.
    If there than (formula)
    Else
    set balance = 0
    End if
    Insert balance.
    Thanks Much in adavance.

    Hi ALL,
    Please help me formulate this in PL/SQL. I really appreciate your help in advance. Below is the Specification.
    Read Previous records
    Check if this is a New Customer.
    If New
    Than check for New site
    If New Site than Insert Site
    End If
    Insert Practice
    Insert Customer
    Check for Previous Months Balance for that Customer.
    If there than (formula)
    Else
    set balance = 0
    End if
    Insert balance.
    Thanks Much in adavance.

  • Hi Everyone...Please help me with this query...!

    Please Help me with this doubt as I am unable to understand the logic...behind this code. It's a begineer level code but I need to understand the logic so that I am able to grasp knowledge. Thank you all for being supportive. Please help me.
    //Assume class Demo is inherited from class SuperDemo...in other words class Demo extends SuperDemo
    //Volume is a method declared in SuperDemo which returns an integer value
    //weight is an integer vairable declared in the subclass which is Demo
    class Example
         public static void main(String qw[])
              Demo ob1=new Demo(3,5,7,9);
    //Calling Constructor of Demo which takes in 4 int parameters
              SuperDemo ob2=new SuperDemo();
              int vol;
              vol=ob1.volume();
              System.out.println("Volume of ob1 is " + vol);
              System.out.println("Weight of ob1 is " + ob1.weight);
              System.out.println();
              ob2=ob1;
    }Can someone please make me understand --- how is this possible and why !
    If the above statement is valid then why not this one "System.out.println(ob2.weight);"
    Thanks Thanks Thanks!

    u see the line wherein I am referencing the objectof
    a subclass to the superclass...right? then why we
    can't do System.out.println(ob2.weight)?You need to distinguish two things:
    - the type of the object, which determines with the
    object can do
    - the type of the reference to the object, which
    determines what you see that you can do
    Both don't necessarily have to match. When you use a
    SuperDemo reference (obj2) to access a Demo instance
    (obj1), for all you know, the instance behind obj2 is
    of type SuperDemo. That it's in reality of type Demo
    is unknown to you. And usually, you don't care -
    that's what polymorphism is about.
    So you have a reference obj2 of type SuperDemo.
    SuperDemo objects don't have weight, so you don't see
    it - even though it is there.So from ur explanation wat I understand is - Even though u reference a subclass object to a superclass, u will only be able to access the members which are declared in the superclass thru the same...right
    ?

Maybe you are looking for

  • What are the OUT_E_USER_PWD and OUT_E_ORCL_PWD parameters?

    Hi friends, I put this question on Database General Forum, but may be it's more appropiated here: I'm trying to find more information about pass encryption process. (Specially in Applications Environment) What I don't know is the meaning of two param

  • Sleepmode gets interrupted

    I have the following problem: My new MacBook Pro (produced in week 26) is a bit buggy. Except the whining noise, which seems to be normal for this generation of MBP (gets repaired next week), the MBP wakes up from sleepmode because of this here (extr

  • Encore CS3 - Blu-ray authoring - video formats?

    Does anyone know if we'll be able to use h.264 or VC-1 video formats for Blu-ray discs in Encore CS3? I already own some software that's MPEG2 only but would prefer more flexability (Roxio's DVDit Pro HD) Will you be able to do "pop-up" menus that yo

  • HT2729 iphone timed out-cant sync iphone 5s

    downloaded the latest version of itunes and i cant sync my new iphone 5s. "device timed out message" any sugguestions

  • Dreamweaver Webseiten Title: !-- InstanceBeginEditable name=doctitle

    Hallo, ich bin von goLive auf den Dreamweaver cs5.5 über das webkit habe ich meine Seite importiert und dann die Vorlage auf ein HTML5-Dokument umgewandelt. Jetzt zeigt es mir in den Tabs vor dem eigentlichen Title " <!-- InstanceBeginEditable name=d