Alessandro Lacava’s Blog

Google
 

April 27, 2007

How to put a set of rows into a single row in Oracle

Filed under: Computer, Oracle — alessandrolacava @ 4:11 pm

In Oracle you can execute hierarchical queries using some cool operators--CONNECT BY PRIOR, START WITH and the pseudocolumn SYS_CONNECT_BY_PATH, namely. However, using your fantasy you can exploit these operators to put in a single row--with each item separated by the next through a separator, such as a comma--what you have in multiple rows. For example if you have more than one telephone number in different rows and you want to put them in a single comma-separated row you could use a query similar to the following:

SQL:
  1. SELECT ltrim(sys_connect_by_path(telephone, ', '), ', ') tel
  2. FROM (SELECT telephone,
  3. rownum num_of_rows
  4. FROM (-- Select the first 9 rows    (1)
  5. SELECT ds_number telephone
  6. FROM telephones t
  7. WHERE cd_customer = 50
  8. AND rownum <= 9)) x
  9. WHERE num_of_rows = (-- Count the # of rows selected in (1)
  10. SELECT COUNT(*)
  11. FROM telephones t
  12. WHERE cd_customer = 50
  13. AND rownum <= 9)
  14. START WITH num_of_rows = 1
  15. CONNECT BY PRIOR x.num_of_rows = (x.num_of_rows - 1);

The previuos query selects all the telephone numbers for the customer with cd_customer = 50 and put them in a single comma-separated row


How to edit the startup menu in Windows

Filed under: Computer, Windows — alessandrolacava @ 10:37 am

Warning: If you're not an expert I advise you against the below steps since you could cause fatal errors.

  1. Go to Start -> Run
  2. Type msconfig and click enter
  3. Go to the startup tab and uncheck what you don't want to start when Windows starts up
  4. Click Apply and then restart the PC

Next Page »