Select a column in a rows

I want to select a column in a row.
suppose,
empno
1
2
3
4
5
I want op like,
1 2 3 4 5

Like this...
SQL> ed
Wrote file afiedt.buf
  1  select max(decode(rn, 1, empno)) as emp1
  2        ,max(decode(rn, 2, empno)) as emp2
  3        ,max(decode(rn, 3, empno)) as emp3
  4        ,max(decode(rn, 4, empno)) as emp4
  5        ,max(decode(rn, 5, empno)) as emp5
  6        ,max(decode(rn, 6, empno)) as emp6
  7        ,max(decode(rn, 7, empno)) as emp7
  8        ,max(decode(rn, 8, empno)) as emp8
  9        ,max(decode(rn, 9, empno)) as emp9
10        ,max(decode(rn, 10, empno)) as emp10
11        ,max(decode(rn, 11, empno)) as emp11
12        ,max(decode(rn, 12, empno)) as emp12
13        ,max(decode(rn, 13, empno)) as emp13
14        ,max(decode(rn, 14, empno)) as emp14
15        ,max(decode(rn, 15, empno)) as emp15
16        ,max(decode(rn, 16, empno)) as emp16
17        ,max(decode(rn, 17, empno)) as emp17
18        ,max(decode(rn, 18, empno)) as emp18
19        ,max(decode(rn, 19, empno)) as emp19
20        ,max(decode(rn, 20, empno)) as emp20
21  from (
22        select empno, row_number() over (order by empno) as rn from emp
23*      )
SQL> /
      EMP1       EMP2       EMP3       EMP4       EMP5       EMP6       EMP7       EMP8       EMP9   EMP10         EMP11      EMP12      EMP13      EMP14      EMP15      EMP16      EMP17      EMP18      EMP19      EMP20
      7369       7499       7521       7566       7654       7698       7782       7788       7839    7844          7876       7900       7902       7934
SQL>

Similar Messages

  • Select single column but multiple rows in JTable

    Hi
    I have a jTable and want to be able to select multiple rows but only in a single column.
    I've set these properties which makes selection almost the way I would like it.
    table1.setCellSelectionEnabled(true);
    table1.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);the only problem now is that the user can select multiple columns.
    Is there a simple way to restrict selection to single column?
    regards
    abq

    table.setCellSelectionEnabled(true);
    table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    DefaultListSelectionModel model =
         (DefaultListSelectionModel)table.getColumnModel().getSelectionModel();
    model.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

  • How do I select the end of a row or column in Numbers?

    I am trying to select to the end of a column in Numbers. In Excel, I simply hold down the shift+command+arrow keys and I can select the entire row or column int he arrow direction. How do I do this in Numbers?

    Here two other scripts :
    Select-to-top and select-to-left.
    Both of them take care of possible headers.
    --{code}
    --[SCRIPT select-to-top]
    Enregistrer le script en tant que Script : select-to-top.scpt
    déplacer le fichier ainsi créé dans le dossier
    <VolumeDeDémarrage>:Utilisateurs:<votreCompte>:Bibliothèque:Scripts:Applications :Numbers:
    Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.
    Sélectionner une ou plusieurs cellules d'une ligne dans une table de Numbers
    Aller au menu Scripts , choisir Numbers puis choisir “select-to-top”
    Il étendra la sélection jusqu'à la première ligne standard de la colonne (ne sélectionne pas les rangs d’en tête).
    Bien entendu, ce script sera plus intéressant si vous le dotez d'un raccourci clavier à l’aide, par exemple, de FastScripts.
    --=====
    L’aide du Finder explique:
    L’Utilitaire AppleScript permet d’activer le Menu des scripts :
    Ouvrez l’Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
    Cochez la case “Afficher le menu des scripts dans la barre de menus”.
    Sous 10.6.x,
    aller dans le panneau “Général” du dialogue Préférences de l’Éditeur Applescript
    puis cocher la case “Afficher le menu des scripts dans la barre des menus”.
    --=====
    Save the script as a Script: select-to-top.scpt
    Move the newly created file into the folder:
    <startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
    Maybe you would have to create the folder Numbers and even the folder Applications by yourself.
    Select one or several cells in a row of a Numbers table.
    Go to the Scripts Menu, choose Numbers, then choose “select-to-top”
    It will expand the selection to the first standard row of the table (minus header rows).
    Of course, it would be more useful if you attach a shortcut thanks to a tool like FastScripts.
    --=====
    The Finder’s Help explains:
    To make the Script menu appear:
    Open the AppleScript utility located in Applications/AppleScript.
    Select the “Show Script Menu in menu bar” checkbox.
    Under 10.6.x,
    go to the General panel of AppleScript Editor’s Preferences dialog box
    and check the “Show Script menu in menu bar” option.
    --=====
    Yvan KOENIG (VALLAURIS, France)
    2012/02/09
    --=====
    on run
              my activateGUIscripting()
              set {dName, sName, tName, rowNum1, colNum1, rowNum2, colNum2} to my get_SelParams()
              tell application "Numbers" to tell document dName to tell sheet sName to tell table tName
                        set count_HeaderRows to my countXers("Numbers", "R")
                        set selection range to range ((name of cell (1 + count_HeaderRows) of column colNum1) & " : " & (name of cell rowNum1 of column colNum2))
              end tell
    end run
    --=====
    set { dName, sName, tName,  rowNum1, colNum1, rowNum2, colNum2} to my get_SelParams()
    tell application "Numbers" to tell document dName to tell sheet sName to tell table tName
    on get_SelParams()
              local d_Name, s_Name, t_Name, row_Num1, col_Num1, row_Num2, col_Num2
              tell application "Numbers" to tell document 1
                        set d_Name to its name
                        set s_Name to ""
                        repeat with i from 1 to the count of sheets
                                  tell sheet i to set maybe to the count of (tables whose selection range is not missing value)
                                  if maybe is not 0 then
                                            set s_Name to name of sheet i
                                            exit repeat
                                  end if -- maybe is not 0
                        end repeat
                        if s_Name is "" then
                                  if my parleAnglais() then
                                            error "No sheet has a selected table embedding at least one selected cell !"
                                  else
                                            error "Aucune feuille ne contient une table ayant au moins une cellule sélectionnée !"
                                  end if
                        end if
                        tell sheet s_Name to tell (first table where selection range is not missing value)
                                  tell selection range
                                            set {top_left, bottom_right} to {name of first cell, name of last cell}
                                  end tell
                                  set t_Name to its name
                                  tell cell top_left to set {row_Num1, col_Num1} to {address of its row, address of its column}
                                  if top_left is bottom_right then
                                            set {row_Num2, col_Num2} to {row_Num1, col_Num1}
                                  else
                                            tell cell bottom_right to set {row_Num2, col_Num2} to {address of its row, address of its column}
                                  end if
                        end tell -- sheet…
                        return {d_Name, s_Name, t_Name, row_Num1, col_Num1, row_Num2, col_Num2}
              end tell -- Numbers
    end get_SelParams
    --=====
    on parleAnglais()
              local z
              try
                        tell application "Numbers" to set z to localized string "Cancel"
              on error
                        set z to "Cancel"
              end try
              return (z is not "Annuler")
    end parleAnglais
    --=====
    on activateGUIscripting()
      (* to be sure than GUI scripting will be active *)
              tell application "System Events"
                        if not (UI elements enabled) then set (UI elements enabled) to true
              end tell
    end activateGUIscripting
    --=====
    set count_Row_Headers to my countXers("Numbers","R")
    set count_Column_Headers to my countXers("Numbers","C")
    set count_Footers to my countXers("Numbers","F")
    set count_Row_Headers to my countXers("Pages","R")
    set count_Column_Headers to my countXers("Pages","C")
    set count_Footers to my countXers("Pages","F")
    on countXers(theApp, what)
              local mt, mi, mm, ms
              if theApp is "Numbers" then
                        set mt to 6 (* Table *)
                        if "Row" starts with what then
                                  set mi to 10
                        else if "Column" starts with what then
                                  set mi to 11
                        else if "Footer" starts with what then
                                  set mi to 14
                        else
                                  if my parleAnglais() then
                                            error "“" & what & "” isn’t a valid parameter !"
                                  else
                                            error "« " & what & " » n’est pas un paramètre géré !"
                                  end if -- parleAnglais
                        end if -- "Row"…
              else if theApp is "Pages" then
                        set {mt, mi} to {6, 4} (* Format, Table *)
                        if "Row" starts with what then
                                  set mm to 13
                        else if "Column" starts with what then
                                  set mm to 14
                        else if "Footer" starts with what then
                                  set mm to 15
                        else
                                  if my parleAnglais() then
                                            error "“" & what & "” isn’t a valid parameter !"
                                  else
                                            error "« " & what & " » n’est pas un paramètre géré !"
                                  end if -- parleAnglais
                        end if -- "Row"…
              else
                        if my parleAnglais() then
                                  error "The application “" & theApp & "” isn’t driven by this script !"
                        else
                                  error "L’application « " & theApp & " » n’est pas gérée par ce script !"
                        end if -- parleAnglais
              end if -- theApp…
      activate application theApp
              tell application "System Events" to tell process theApp to tell menu bar 1 to tell menu bar item mt to tell menu 1 to tell menu item mi to tell menu 1
                        if theApp is "Numbers" then
    Here we are in Numbers *)
                                  repeat with ms from 1 to 6
                                            try
                                                      (get value of attribute "AXMenuItemMarkChar" of menu item ms) = "✓"
                                                      exit repeat
                                            end try
                                  end repeat
                        else
    Here we are in Pages *)
                                  tell menu item mm to tell menu 1
                                            repeat with ms from 1 to 6
                                                      try
                                                                (get value of attribute "AXMenuItemMarkChar" of menu item ms) = "✓"
                                                                exit repeat
                                                      end try
                                            end repeat
                                  end tell -- menu item mm
                        end if -- theApp is …
              end tell -- System Events…
              return ms - 1
    end countXers
    --=====
    --[/SCRIPT]
    --{code}
    --{code}
    --[SCRIPT select-to-left]
    Enregistrer le script en tant que Script : select-to-left.scpt
    déplacer le fichier ainsi créé dans le dossier
    <VolumeDeDémarrage>:Utilisateurs:<votreCompte>:Bibliothèque:Scripts:Applications :Numbers:
    Il vous faudra peut-être créer le dossier Numbers et peut-être même le dossier Applications.
    Sélectionner une ou plusieurs cellules d'une colonne dans une table de Numbers
    Aller au menu Scripts , choisir Numbers puis choisir “select-to-left”
    Il étendra la sélection jusqu'à la première colonne standard de la table (ne sélectionne pas les colonnes d’en tête).
    Bien entendu, ce script sera plus intéressant si vous le dotez d'un raccourci clavier à l’aide, par exemple, de FastScripts.
    --=====
    L’aide du Finder explique:
    L’Utilitaire AppleScript permet d’activer le Menu des scripts :
    Ouvrez l’Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
    Cochez la case “Afficher le menu des scripts dans la barre de menus”.
    Sous 10.6.x,
    aller dans le panneau “Général” du dialogue Préférences de l’Éditeur Applescript
    puis cocher la case “Afficher le menu des scripts dans la barre des menus”.
    --=====
    Save the script as a Script: select-to-left.scpt
    Move the newly created file into the folder:
    <startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Numbers:
    Maybe you would have to create the folder Numbers and even the folder Applications by yourself.
    Select one or several cells in a column of a Numbers table.
    Go to the Scripts Menu, choose Numbers, then choose “select-to-left”
    It will expand the selection to the first standard colomn of the table (minus fheader columns).
    Of course, it would be more useful if you attach a shortcut thanks to a tool like FastScripts.
    --=====
    The Finder’s Help explains:
    To make the Script menu appear:
    Open the AppleScript utility located in Applications/AppleScript.
    Select the “Show Script Menu in menu bar” checkbox.
    Under 10.6.x,
    go to the General panel of AppleScript Editor’s Preferences dialog box
    and check the “Show Script menu in menu bar” option.
    --=====
    Yvan KOENIG (VALLAURIS, France)
    2012/02/09
    --=====
    on run
              my activateGUIscripting()
              set {dName, sName, tName, rowNum1, colNum1, rowNum2, colNum2} to my get_SelParams()
              tell application "Numbers" to tell document dName to tell sheet sName to tell table tName
                        set count_ColHeaders to my countXers("Numbers", "C")
                        set selection range to range ((name of cell (1 + count_ColHeaders) of row rowNum1) & " : " & (name of cell colNum1 of row rowNum2))
              end tell
    end run
    --=====
    set { dName, sName, tName,  rowNum1, colNum1, rowNum2, colNum2} to my get_SelParams()
    tell application "Numbers" to tell document dName to tell sheet sName to tell table tName
    on get_SelParams()
              local d_Name, s_Name, t_Name, row_Num1, col_Num1, row_Num2, col_Num2
              tell application "Numbers" to tell document 1
                        set d_Name to its name
                        set s_Name to ""
                        repeat with i from 1 to the count of sheets
                                  tell sheet i to set maybe to the count of (tables whose selection range is not missing value)
                                  if maybe is not 0 then
                                            set s_Name to name of sheet i
                                            exit repeat
                                  end if -- maybe is not 0
                        end repeat
                        if s_Name is "" then
                                  if my parleAnglais() then
                                            error "No sheet has a selected table embedding at least one selected cell !"
                                  else
                                            error "Aucune feuille ne contient une table ayant au moins une cellule sélectionnée !"
                                  end if
                        end if
                        tell sheet s_Name to tell (first table where selection range is not missing value)
                                  tell selection range
                                            set {top_left, left_right} to {name of first cell, name of last cell}
                                  end tell
                                  set t_Name to its name
                                  tell cell top_left to set {row_Num1, col_Num1} to {address of its row, address of its column}
                                  if top_left is left_right then
                                            set {row_Num2, col_Num2} to {row_Num1, col_Num1}
                                  else
                                            tell cell left_right to set {row_Num2, col_Num2} to {address of its row, address of its column}
                                  end if
                        end tell -- sheet…
                        return {d_Name, s_Name, t_Name, row_Num1, col_Num1, row_Num2, col_Num2}
              end tell -- Numbers
    end get_SelParams
    --=====
    on parleAnglais()
              local z
              try
                        tell application "Numbers" to set z to localized string "Cancel"
              on error
                        set z to "Cancel"
              end try
              return (z is not "Annuler")
    end parleAnglais
    --=====
    on activateGUIscripting()
      (* to be sure than GUI scripting will be active *)
              tell application "System Events"
                        if not (UI elements enabled

  • Number of rows returned by SELECT LAST(column)

    I have about 50,000 rows in my MS Acess database table so I have used SELECT LAST(column) AS newField FROM table... to retrieve the last data in the column however when I check the number of rows in the resultset using
    resultset.last();
         int rowcount = rs.getRow();
    rowcnt returns the total no.rows (about 50,000) in the table.
    I thought it should just return one.
    Is it normal?

    Thanks again dcminta. I'll try with your code.
    I just wanted to know why resultset returned the number of all records in that column when I only selected the last.
    I had the �Invalid Cursor Position� error with "while(rs.next())" as I (thought I) had only one record in the resultset and I was fiddling with my code.
    They are all fine now.
    Thanks guys.
    Booh1(old lady)

  • SQL Loader Inserts chr(13) and chr(10) in the first column of every row.

    Hi,
    I have exported a data in a pipe delimited file using TOAD in one database. Now I want to load the data in my local database using SQL Loader. However every time I try to load the data a double quote followed by a new line is entered for the first column of each row. Unfortunately the delimited file is very big and hence can't be posted here. However I tried the same with a customized table and its data and found the same problem. Below are the table structures and control file that I used.
    create table test_sql
    a varchar2(30),
    b date
    insert into test_sql values('51146263',sysdate-3);
    insert into test_sql values('51146261,sysdate-1);
    EXPORTED PIPE DELIMITED FILE_
    A|B|!##!
    51146261|04/14/13 4:55:18 PM|!##!
    51146263|04/12/13 4:55:32 PM|!##!
    create table test_sql1 as select * from test_sql where 1=2;
    CONTROL FILE_
    OPTIONS(SKIP=1)
    LOAD DATA
    INFILE 'C:\Users\Prithwish\Desktop\Test.txt' "str '!##!'"
    PRESERVE BLANKS
    INTO TABLE TEST_SQL1
    FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '"'
    TRAILING NULLCOLS
    A CHAR(2000),
    B DATE "MM/DD/YYYY HH12:MI:SS AM"
    select * from TEST_SQL1;
    After this when I paste it in notepad I get the following result
    A B
    51146261"     14-APR-0013 16:55:18
    51146263"     12-APR-0013 16:55:32.
    I have no idea how the quotes or the newline appear. Is this a Toad bug? Any help would be greatly appreciated. Really urgent.
    Thanks in advance
    Regards

    Hi Harry,
    I actually thought that the str !##! was causing the problem. Actually my original export has some new lines in some specific columns so I can't keep the new line as my line terminator and hence I kept the !##! as my terminator.
    When I put the same data in a notepad and load it there is no problem at all. For e.g I just typed the following in a notepad and the data loaded just fine.
    A|B|!##!
    51146261|01-01-01 10:10:10 AM|!##!
    51146263|01-01-01 11:11:11 AM|!##!
    Its just when I load the exported file there the problem arises though I have verified the file using UNIX as well using octal dump and found no hidden characters.
    Regards,
    Prithwish

  • Multiple values from same column in diffetent columns in same row??

    Hi all,
    I am wondering how you can display different values from the same column into different columns on same row. For example using a CASE statement I can:
    CASE WHEN CODE IN ('1', '3') THEN COUNT( ID) END as "Y"
    CASE WHEN CODE NOT IN ('1', 'M') THEN COUNT( ID) END as "N"
    Yes this will produce two columns needed but will also produce two separate records and null values for the empty's.
    Any ideas?
    Thanks

    It's not clear what you want.
    Can you post some examples as described in the FAQ: {message:id=9360002}
    As my first guess, I would think you're looking for something like...
    SQL> select * from emp;
         EMPNO ENAME      JOB              MGR HIREDATE                    SAL       COMM     DEPTNO
          7369 SMITH      CLERK           7902 17-DEC-1980 00:00:00        800                    20
          7499 ALLEN      SALESMAN        7698 20-FEB-1981 00:00:00       1600        300         30
          7521 WARD       SALESMAN        7698 22-FEB-1981 00:00:00       1250        500         30
          7566 JONES      MANAGER         7839 02-APR-1981 00:00:00       2975                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-1981 00:00:00       1250       1400         30
          7698 BLAKE      MANAGER         7839 01-MAY-1981 00:00:00       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-1981 00:00:00       2450                    10
          7788 SCOTT      ANALYST         7566 19-APR-1987 00:00:00       3000                    20
          7839 KING       PRESIDENT            17-NOV-1981 00:00:00       5000                    10
          7844 TURNER     SALESMAN        7698 08-SEP-1981 00:00:00       1500          0         30
          7876 ADAMS      CLERK           7788 23-MAY-1987 00:00:00       1100                    20
          7900 JAMES      CLERK           7698 03-DEC-1981 00:00:00        950                    30
          7902 FORD       ANALYST         7566 03-DEC-1981 00:00:00       3000                    20
          7934 MILLER     CLERK           7782 23-JAN-1982 00:00:00       1300                    10
    14 rows selected.
    SQL> select count(case when deptno in (10,20) then deptno end) as deptno_10_20
      2        ,count(case when deptno > 20 then deptno end) as deptno_30plus
      3  from emp;
    DEPTNO_10_20 DEPTNO_30PLUS
               8             6

  • How to remove gaps/null values from set of columns in a row

    Im trying to implement a solution for removing null value columns from a row.
    Basically in below example i have five codes and corresponding id's for that codes.What im trying to achive here is if
    i have a null code then i have to move next not null code and id into its new location.
    Example:
    'A1'cd1,'A2'cd2,null cd3,'A4'cd4,null cd5,'i1'id1,'i2'id2,null id3,'i4' id4,null id5 So here cd4 and id4 should take positions of cd3 and id3.
    Output should look like this
    cd1 cd2 cd3 cd4 cd5     id1 id2 id3 id4 id5
    A1  A2   A4              i1  i2  i4Any help would be highly appreciated for below example:
    with temp_table as
    (select 'A1'cd1,'A2'cd2,null cd3,'A4'cd4,null cd5,'i1'id1,'i2'id2,null id3,'i4' id4,null id5 from dual union all
    select 'A11',null,null,'A44','A55','id11',null,null, 'id44','id55' from dual union all
    select null,'A111',null,null,'A555',null,'id111',null, null,'id555' from dual union all
    select 'A',null,null,'A1111','E55','id11',null,null, 'id111','id1111' from dual )
    select * from temp_table;Edited by: GVR on Dec 1, 2010 8:27 AM

    I like case expression B-)
    The same question of my homepage http://www.geocities.jp/oraclesqlpuzzle/7-81.html
    with temp_table(cd1,cd2,cd3,cd4,cd5,id1,id2,id3,id4,id5) as(
    select 'A1' ,'A2' ,null,'A4'   ,null  ,'i1'  ,'i2'   ,null,'i4'   ,null     from dual union all
    select 'A11',null ,null,'A44'  ,'A55' ,'id11',null   ,null,'id44' ,'id55'   from dual union all
    select null,'A111',null,null   ,'A555',null  ,'id111',null,null   ,'id555'  from dual union all
    select 'A'  ,null ,null,'A1111','E55' ,'id11',null   ,null,'id111','id1111' from dual)
    select
    case when SumCD1 = 1 then CD1
         when SumCD1+SumCD2 = 1 then CD2
         when SumCD1+SumCD2+SumCD3 = 1 then CD3
         when SumCD1+SumCD2+SumCD3+SumCD4 = 1 then CD4
         when SumCD1+SumCD2+SumCD3+SumCD4+SumCD5 = 1 then CD5 end as CD1,
    case when SumCD1+SumCD2 = 2 then CD2
         when SumCD1+SumCD2+SumCD3 = 2 then CD3
         when SumCD1+SumCD2+SumCD3+SumCD4 = 2 then CD4
         when SumCD1+SumCD2+SumCD3+SumCD4+SumCD5 = 2 then CD5 end as CD2,
    case when SumCD1+SumCD2+SumCD3 = 3 then CD3
         when SumCD1+SumCD2+SumCD3+SumCD4 = 3 then CD4
         when SumCD1+SumCD2+SumCD3+SumCD4+SumCD5 = 3 then CD5 end as CD3,
    case when SumCD1+SumCD2+SumCD3+SumCD4 = 4 then CD4
         when SumCD1+SumCD2+SumCD3+SumCD4+SumCD5 = 4 then CD5 end as CD4,
    case when SumCD1+SumCD2+SumCD3+SumCD4+SumCD5 = 5 then CD5 end as CD5,
    case when SumID1 = 1 then ID1
         when SumID1+SumID2 = 1 then ID2
         when SumID1+SumID2+SumID3 = 1 then ID3
         when SumID1+SumID2+SumID3+SumID4 = 1 then ID4
         when SumID1+SumID2+SumID3+SumID4+SumID5 = 1 then ID5 end as ID1,
    case when SumID1+SumID2 = 2 then ID2
         when SumID1+SumID2+SumID3 = 2 then ID3
         when SumID1+SumID2+SumID3+SumID4 = 2 then ID4
         when SumID1+SumID2+SumID3+SumID4+SumID5 = 2 then ID5 end as ID2,
    case when SumID1+SumID2+SumID3 = 3 then ID3
         when SumID1+SumID2+SumID3+SumID4 = 3 then ID4
         when SumID1+SumID2+SumID3+SumID4+SumID5 = 3 then ID5 end as ID3,
    case when SumID1+SumID2+SumID3+SumID4 = 4 then ID4
         when SumID1+SumID2+SumID3+SumID4+SumID5 = 4 then ID5 end as ID4,
    case when SumID1+SumID2+SumID3+SumID4+SumID5 = 5 then ID5 end as ID5
    from (select cd1,cd2,cd3,cd4,cd5,id1,id2,id3,id4,id5,
          nvl2(cd1,1,0) as SumCD1,
          nvl2(cd2,1,0) as SumCD2,
          nvl2(cd3,1,0) as SumCD3,
          nvl2(cd4,1,0) as SumCD4,
          nvl2(cd5,1,0) as SumCD5,
          nvl2(id1,1,0) as SumID1,
          nvl2(id2,1,0) as SumID2,
          nvl2(id3,1,0) as SumID3,
          nvl2(id4,1,0) as SumID4,
          nvl2(id5,1,0) as SumID5
          from temp_table)
    order by cd1,cd2,cd3,cd4,cd5;
    CD1   CD2    CD3   CD4   CD5   ID1    ID2    ID3     ID4   ID5
    A     A1111  E55   null  null  id11   id111  id1111  null  null
    A1    A2     A4    null  null  i1     i2     i4      null  null
    A11   A44    A55   null  null  id11   id44   id55    null  null
    A111  A555   null  null  null  id111  id555  null    null  nullMy SQL articles of OTN-Japan
    http://www.oracle.com/technology/global/jp/pub/jp/ace/sql_image/1/otnj-sql-image1.html
    http://www.oracle.com/technology/global/jp/pub/jp/ace/sql_image/2/otnj-sql-image2.html

  • How to select all columns in a trigger?

    I add a "before delete" trigger on a table, in order to insert the records to a backup table before they are deleted.
    but I cannot write like this : insert into t_backup select * from :old;
    The table has more than 30 columns so I don't want to select them one by one, how can I select all columns?

    Yes, it is possible by writing something like this :
    where col1 = :old.col1; But it is not directly supported. First, we need a package to remember all the OLD records:.... and please see below link for complete code in action :
    http://www.dbforums.com/oracle/925729-trigger-back-up-data.html
    What I am doing here, just copying the code and replacing "emp" with "test" (The table name on which I am going to apply this using notepad find and replace):
    SQL> select * from test_backup;
    no rows selected
    SQL> select * from test;
             A
             1
             2
             4
             5
    SQL> select * from test_backup;
    no rows selected
    SQL>
    create or replace package test_trg_pkg as
      type test_type is table of test%ROWTYPE index by binary_integer;
      test_tab test_type;
    end;
    create or replace trigger test_bds before delete on test
    begin
      test_trg_pkg.test_tab.delete;
    end;
    create or replace trigger test_adr after delete on test
    for each row
    declare
      -- To allow us to select the old values
      pragma autonomous_transaction;
    begin
      select *
      into   test_trg_pkg.test_tab(test_trg_pkg.test_tab.COUNT+1)
      from   test
      where  a = :old.a;  <----- Here you have to give your column name.
    end;
    create or replace trigger test_ads after delete on test
    begin
      for i in 1..test_trg_pkg.test_tab.COUNT loop
        insert into test_backup values test_trg_pkg.test_tab(i);
      end loop;
    end;
    SQL> delete from test where a=1;
    1 row deleted.
    SQL> select * from test_backup;
             A
             1
    SQL> delete from test where a=2;
    1 row deleted.
    SQL> select * from test_backup;
             A
             1
             2
    SQL>Regards
    Girish Sharma

  • How to get Select All or select Multiple columns  in OOALV

    HI Experts
    i'm assignig internal table to dynamic internal table(FS_IST_TABLE) for to display the output.
    but i'm not geting the Select ALL Option. and i can't select multiple columns at a time.
    where i can select only one column.
    how can i select multiple columns.
    please any one help me.
    regrads,
    rathan.

    Hi,
      If we want to select the multiple columns in the alv by using ooabap
    so in the class CL_GUI_ALV_GRID  it is having one method SET_TABLE_FOR_FIRST_DISPLAY
    it is having one importing parameter IS_LAYOUT of type lvc_s_layo type
    and this structure contains one field SEL_MODE and set that field value as 'A'.
    then we can select the multiple rows in alv grid

  • What is the difference betwwen SELECT ALL Column and Select Speceific Colum

    Hi All,
    If the block size of the database is 8K and average row length is 2K and if we select all column of the table the I/O show that it had read more blocks then compare to
    specific column of the same table. Why is this?
    Secondly if Oracle brings a complete block is the db buffer cache, while reading block from disk, they why there is a difference of block count in two queries.
    This difference reveals to me when I check the EXPLAIN PLAN for two different queries against the same table but one select all columns and the other one select specific column.
    Kindly help me in clearing this confusion.
    Regards,
    Kamran

    user1514587 wrote:
    >
    Usually, indexes are smaller (contain fewer blocks) than the table - ergo, select empno from emp could be satisfied by reading fewer blocks.
    what if there is a composite Index on a table containing 3 to 4 columns and the size of table is in 100 of GB and Index size itself is vey large then I think Oracle will go for FTS and small Index scan will be expensive. Kindly Share your thoughts.
    Regards,
    KamranHandle:     user1514587
    Status Level:     Newbie (5)
    Registered:     May 9, 2011
    Total Posts:     21
    Total Questions:     13 (12 unresolved)
    I think you wastes everyone's time here since you rarely get answer to any posted question

  • How to create a Type Object with Dynamic select query columns in a Function

    Hi Every One,
    I'm trying to figure out how to write a piplined function that executes a dynamic select query and construct a Type Object in order to assigned it to the pipe row.
    I have tried by
    SELECT a.DB_QUERY INTO actual_query FROM mytable a WHERE a.country_code = 'US';
    c :=DBMS_SQL.OPEN_CURSOR;
    DBMS_SQL.PARSE(c,actual_query,DBMS_SQL.NATIVE);
    l_status := DBMS_SQL.EXECUTE(c);
    DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
    FOR j in 1..col_cnt LOOP
    DBMS_SQL.DEFINE_COLUMN(c,j,v_val,2000);
    END LOOP;
    FOR j in 1..col_cnt LOOP
    DBMS_SQL.COLUMN_VALUE(c,j,v_val);
    END LOOP;
    But got stuck, how to iterate the values and assign to a Type Object from the cursor. Can any one guide me how to do the process.
    Thanks,
    mallikj2

    Hi Justin,
    First of thanks for your reply, and coming to my requirement, I need to report the list of items which are there in the dynamic select statement what am getting from the DB. The select statement number of columns may vary in my example for different countries the select item columns count is different. For US its '15', for UK it may be 10 ...like so, and some of the column value might be a combination or calculation part of other table columns (The select query contains more than one table in the from clause).
    In order to execute the dynamic select statement and return the result i choose to write a function which will parse the cursor for dynamic query and then iterate the values and construct a Type Object and append it to the pipe row.
    Am relatively very new for these sort of things, welcome in case of any suggestions to make it simple (Instead of the function what i thought to work with) also a sample narrating the new procedure will be appreciated.
    Thanks in Advance,
    mallikj2.

  • Selecting all columns from table in a model query

    I have written a model query which joins 4 tables, applies some rules and returns updated rows by selecting 4 columns out of this. Currently it works fine because all 4 columns are from MODEL aliases. Now I need to select 16 more columns in the same query but none of these columns is added in MODEL aliases. When I tried selecting these columns I got oracle error ORA - 32614. Can someone please guide me to include these columns in the same model query?
    I tried couple of options but no luck. Here are those options for ready reference:
    1. I cannot nest existing model query into another select because there are no columns avaiable to join in output of current query to map with other records.
    2. I cannot include all 16 columns in MODEL aliases because some of these columns are actually output of user defined functions.
    I am using Oracle database version 11g Release 11.2.0.1.0.
    Edited by: Anirudha Dhopate on Jan 23, 2011 5:43 PM

    Thank you Avijit for your reply. There is a syntax error on the ON in this part of the statement which I don't know how to fix - I tried messing around with another INNER JOIN but am not confident that I'm doing the right thing:
    SENAlertType.SENAlertTypeIDONClassMember.ClassMemberStudentID
    Thanks for your help! I will need to do some more bedtime reading on joins.
    Daniel

  • Execute a DML process after user selects a column link in a report

    APEX 3.2 / RDBMS 10GR2
    I have written a non IRR report that displays several rows of data. The first column of each row has a defined column link uniquely identifying the row. When a user selects one of the rows via the column link, a "hi fidelity" report is generated for that displayed row using a (RTF) report layout created in the shared components section of APEX.
    This is working well but I also need to execute a DML process after the user selects a row but prior to displaying the hi fidelity report using the selected column link value of the displayed row.
    As a URL is used to call hi fidelity report via the column link, it does not appear that the process section of the APEX page component is available to execute the DML prior to displaying the report.
    Any ideas on where to define the DML process?
    Thanks in advance.
    Barry D

    Hi Barry,
    Not knowing exactly what your URL calls, this is what I do for PL/SQL procedures that create HTML output:
    Create a blank page with no template and call the procedure inside a PL/SQL region with no template.
    Alternatively, if your URL opens in a new window:
    run some javascript for your link and pass a unique request through.
    The javascript needs to find the ApEx form, update it's target attribute and submit it with the unique request, then set the target back to blank.
    The form will submit into a new window.
    You can then have a process and branch allocated to this unique request to do what you want.
    Hope this helps
    Regards
    Michael

  • Problem selecting a column

    According to the user guide:
    "1. Select any table cell so that the reference tabs are showing.
    2. To select a column, click its reference tab (above the column)."
    When I do that the whole table is selected. Is this a bug or am I doing something wrong?

    the image doesn't help me any. i can't select a column and centre it, without all cells in the table being centred.
    I can do it by manually selecting all the cells in the column, but I have 500 + cells to scroll down through and it takes too long.
    I just want to select a column or row and apply a format to it, and I can't do it.
    OK, just found out what my problem was. I had merged several cells to create a row near the top. this was preventing selecting anything below. i took out the merged cells and was able to select a column by clicking on the lower, darker shaded portion of the header.
    Message was edited by: justgetoutandride

  • Order By Columns in a Row

    Hi,
    I'm struggling to solve a problem. I want to sort the values of fields in each row.
    RDBMS : 11.2.0.3
    CREATE TABLE test_order
      (a NUMBER, b NUMBER ,c NUMBER ,d NUMBER
    REM INSERTING into test_order
    Insert into "test_order" (A,B,C,D) values ('18','29','14','21');
    Insert into "test_order" (A,B,C,D) values ('40','11','29','12');
    Insert into "test_order" (A,B,C,D) values ('22','20','19','24');
    select * from test_order
             A          B          C          D
            18         29         14         21
            40         11         29         12
            22         20         19         24 I'm trying get result in order as shown below DOES NOT matter column name.
    Each row ordered by its own columns.
             A          B          C          D
            14         18         21         29
            11         12         29         40
            19         20         22         24 Note: my real table have more than one million records.
    Any helps is welcome.

    Seeing as Frank is also having fun with this, and I'm bored watching a data pump import ticking over partition by partition, I thought about creating a SQL data type called TSortedNumbers - allowing you to create/store a set of numbers as a sorted list, and providing a method for returning a specific item in the set.
    As PL/SQL code needs to be used to override the default constructor, I decided to use a PL/SQL quicksort on the number list - as oppose to an expensive context switch to SQL to have SQL doing the sort for you. No idea what (if any) performance improvements there are using a PL/SQL quicksort.
    However, this does demonstrate the really kewl and awesome functionality Oracle provides by enabling one to define custom SQL types.
    // TNumbers is an array/collection of numbers
    SQL> create or replace type TNumbers as table of number;
      2  /
    Type created.
    // package Lib, implements the well-known Quick Sort algorithm - and sorts an
    // array of numbers, where the array is of data type TNumbers
    SQL> create or replace package Lib is
      2          procedure QuickSort( array in out nocopy TNumbers );
      3  end;
      4  /
    Package created.
    SQL>
    SQL> create or replace package body Lib is
      2          procedure SwapPivots( array in out nocopy TNumbers, pivot1 number, pivot2 number ) is
      3                  pivotValue      number;
      4          begin
      5                  pivotValue := array(pivot1);
      6                  array(pivot1) := array(pivot2);
      7                  array(pivot2) := pivotValue;
      8          end;
      9
    10          procedure  Partition( array in out nocopy TNumbers, left number, right number, pivotIndex number, storeIndex out number ) is
    11                  pivotValue      number;
    12          begin
    13                  pivotValue := array(pivotIndex);
    14                  SwapPivots( array, pivotIndex, right );
    15                  storeIndex := left;
    16                  for i in left..right - 1 loop
    17                          if array(i) < pivotValue then
    18                                  SwapPivots( array, i, storeIndex );
    19                                  storeIndex := storeIndex + 1;
    20                          end if;
    21                  end loop;
    22                  SwapPivots( array, storeIndex, right );
    23          end;
    24
    25          procedure QuickSort( array in out nocopy TNumbers, left number, right number ) is
    26                  pivotIndex      number;
    27                  pivotNewIndex   number;
    28          begin
    29                  if left < right then
    30                          pivotIndex := trunc( DBMS_RANDOM.value( left, right ) );
    31
    32                          Partition( array, left, right, pivotIndex, pivotNewIndex );
    33                          QuickSort( array, left, pivotNewIndex-1 );
    34                          QuickSort( array, pivotNewIndex+1, right );
    35                  end if;
    36          end;
    37
    38          procedure QuickSort( array in out nocopy TNumbers ) is
    39          begin
    40                   QuickSort( array, 1, array.Count );
    41          end;
    42
    43  end;
    44  /
    Package body created.
    // We define a a custom SQL data type that contains a single property called n,
    // where n is of type TNumber.
    // The default constructor for this type is: TSortedNumbers ( <array-of-numbers )
    // We create a custom constructor with the same signature, in order to override
    // the default constructor.
    SQL> create or replace type TSortedNumbers is object(
      2          n       TNumbers,
      3
      4          constructor function TSortedNumbers(n TNumbers) return self as result,
      5          member function Get(i integer) return number
      6  );
      7  /
    Type created.
    // Using our custom constructor, we accept the array-of-numbers parameter,
    // assign it to our  TSortedNumbers property n, and quick sort our property so
    // that the array-of-numbers is in ascending values.
    // We also provide a method called Get(), that allows the caller to get a value
    // from our sorted array, by index number.
    SQL> create or replace type body TSortedNumbers as
      2          constructor function TSortedNumbers(n TNumbers) return self as result is
      3          begin
      4                  self.n := n;
      5                  Lib.QuickSort(self.n);
      6                  return;
      7          end;
      8
      9          member function Get(i integer) return number is
    10          begin
    11                  return( self.n(i) );
    12          end;
    13
    14  end;
    15  /
    Type body created.
    // Create sample table and populate it with data
    SQL> create table testtab( a number, b number, c number, d number );
    Table created.
    SQL>
    SQL> insert into testtab (A,B,C,D) values ('18','29','14','21');
    1 row created.
    SQL> insert into testtab (A,B,C,D) values ('40','11','29','12');
    1 row created.
    SQL> insert into testtab (A,B,C,D) values ('22','20','19','24');
    1 row created.
    // To create an array of numbers, we use the TNumbers() data type. Its
    // constructor  is TNumbers( num1, num2, .., numn ). We pass the columns of
    // the rows as parameters into this constructor and it creates an array of our
    // column values. As we now have an array-of-numbers, we can instantiate a
    // TSortedNumbers object. Its constructor required an array-of-numbers
    // parameter. Which is what we have created using our row's columns.
    // As the TSortedNumbers object contains a sorted array-of-numbers of our
    // columns, we can display the numbers in the array using the Get() method
    // and index position in the array of the number we want to display.
    SQL> with results as(
      2  select
      3          rownum,
      4          t.*,
      5          TSortedNumbers( TNumbers(a,b,c,d) ) as NUMBER_SET
      6  from       testtab t
      7  )
      8  select
      9          r.number_set.Get(1)     as "1",
    10          r.number_set.Get(2)     as "2",
    11          r.number_set.Get(3)     as "3",
    12          r.number_set.Get(4)     as "4"
    13  from       results r
    14  /
             1          2          3          4
            14         18         21         29
            11         12         29         40
            19         20         22         24
    SQL>
    Edited by: Billy  Verreynne  on Apr 13, 2013 6:04 PM. (Added comments to example)

Maybe you are looking for