Select a set of random rows

I don't understand how the sample clause works on the select statement. Eg. SELECT * FROM clients SAMPLE(50) should return half of all rows in the table, but it's unstable. Sometimes it returns 4, sometimes 3 and even 2 (SELECT COUNT(*) FROM clients returns 6). Why???
So, if it's really unstable, how do I select a random number of rows from a query? Is there other way?

As noted, the number of rows returned by SAMPLE can vary. The approach I use is to set the sample number high enough so that the minimum number of rows it returns is always higher than what you want, and then chop off the excess with a rownum filter:
sql>select empno, ename, job
  2    from emp sample (50)
  3   where rownum <= 3;
    EMPNO ENAME      JOB
     7499 ALLEN      SALESMAN
     7654 MARTIN     SALESMAN
     7839 KING       PRESIDENT
3 rows selected.
sql>/
    EMPNO ENAME      JOB
     7566 JONES      MANAGER
     7698 BLAKE      MANAGER
     7782 CLARK      MANAGER
3 rows selected.
sql>/
    EMPNO ENAME      JOB
     7499 ALLEN      SALESMAN
     7566 JONES      MANAGER
     7782 CLARK      MANAGER
3 rows selected.
sql>/
    EMPNO ENAME      JOB
     7369 SMITH      CLERK
     7521 WARD       SALESMAN
     7839 KING       PRESIDENT
3 rows selected.

Similar Messages

  • How to efficiently select random rows from a large table ?

    Hello,
    The following code will select 5 rows out of a random set of rows from the emp (employee) table
    select *
      from (
           select ename, job
             from emp
           order by dbms_random.value()
    where rownum <= 5my concern is that the inner select will cause a table scan in order to assign a random value to each row. This code when used against a large table can be a performance problem.
    Is there an efficient way of selecting random rows from a table without having to do a table scan ? (I am new to Oracle, therefore it is possible that I am missing a very simple way to perform this task.)
    thank you for your help,
    John.
    Edited by: 440bx on Jul 10, 2010 6:18 PM

    Have a look at the SAMPLE clause of the select statement. The number in parenthesis is a percentage of the table.
    SQL> create table t as select * from dba_objects;
    Table created.
    SQL> explain plan for select * from t sample (1);
    Explained.
    SQL> @xp
    PLAN_TABLE_OUTPUT
    Plan hash value: 2767392432
    | Id  | Operation           | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT    |      |   725 | 70325 |   289   (1)| 00:00:04 |
    |   1 |  TABLE ACCESS SAMPLE| T    |   725 | 70325 |   289   (1)| 00:00:04 |
    8 rows selected.

  • Select a fixed number of random rows

    Hi,
    I just would like to select a fixed number of random rows from a table. That is, I would like to get 5 rows, without specifying the row_id, and the selected rows should "always" be different. Just as picking 5 balls out of a big box (which is filled with many balls).
    Is there a way to easily put it into one sql statement or do I have to write a workaround in the programming language I use?
    Thanks a lot in advance,
    CQ

    AskTom has a discussion on this:
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:6075151195522
    Note that it requires that you
    1) Generate a random number for every row in the table
    2) Sort the table by those random numbers
    which is a significant performance hit if the table is large.
    Justin

  • Select Random Rows in PL/SQL

    I would like to know if anyone has a suggestion fora select statement that would select random rows from a table based on the following:
    The table contains 1-to-many categories. From each of these categories I need to select a 'x' amount of rows based upon the category id, with a total of 25 rows being selected overall. Some categories will have only 1 row selected, some will have more than 1. The rows selected contain questions that are either multiple choice (type=1) or true/false (type=2). The total rows selected (25) cannot contain more than 20% of true/false questions. Anyone have a solution for a select statement? Thanks.

    Not having a database at hand. To be treated as a template
    with
    parameters as
    (select all_rows,
            all_categories,
            :all_questions all_questions,                               -- your 25
            :category_questions category_questions,                     -- your 'x'
            ceil(all_categories / :category_questions) pick_categories,
            :type_2_percentage type_2_percentage                        -- your 20% expressed as 0.2
       from (select count(*) all_rows,
                    count(distinct category) all_categories,
               from your_table
    categories_scrambled as
    (select category,dense_rank() over (order by categories_mix) category_choice
       from (select category,
                    ceil(dbms_random.value(0,1000)) categories_mix
               from your_table
              group by category
    rows_scrambled as
    (select category,question_type,question_text,dense_rank() over (order by rows_mix) row_choice
       from (select category,question_type,question_text,
                    ceil(dbms_random.value(0,10000)) rows_mix
               from your_table
    combination as
    (select r.category,r.question_type,r.question_text,r.row_choice,c.category_choice,
            row_number() over (partition by r.row_choice,r.question_type order by r.row_choice) row_mark
       from rows_scrambled r,categories_scrambled c
      where r.category = c.category
    type_2_questions as
    (select question_text,question_type,category
       from combination
      where category_choice <= (select pick_categories from parameters)
        and row_mark <= floor(:all_questions * :type_2_percentage / (select pick_categories from parameters))
        and question_type = 2
    type_1_questions as
    (select question_text,question_type,category,row_number() over () the_count
       from combination
      where category_choice <= (select pick_categories from parameters)
        and row_mark <= ceil((:all_questions - (select count(*) from type_2_questions)) / (select pick_categories from parameters))
        and question_type = 1
    select question_text,question_type,category
      from type_2_questions
    union all
    select question_text,question_type,category
      from type_1_questions
    where the_count <= :all_questions - (select count(*) from type_2_questions)Regards
    Etbin

  • How to select a random row with for update?

    Hi,
    I have a package that needs to assign a random, reusable number (ID) that is not currently being used - to a procedure.
    I'm trying to simulate a pool of numbers (IDs) using a table that has an ID and IS_USED columns.
    How do I do:
    select a random ID (random row)
    from pool_table
    where IS_USED is 0 (not taken)
    FOR UPDATEThe for update is to lock the row from being taken by another process calling the package.
    OR:
    Can I simulate a pool of numbers with a different object (not a table)?
    I need the numbers to be coherent between sessions (thus package variables will not work) and only one session uses the same ID at any given time. When it finishes the number becomes available for further runs.
    Thanks.
    Edited by: Pyrocks on Nov 7, 2010 10:45 AM

    This works on Oracle 11g (probably on 10g too, but I haven't tested):
    CREATE OR REPLACE PACKAGE REUSABLE_RANDOM_NUMBERS
    IS
      FUNCTION GET_NUMBER RETURN NUMBER;
    END REUSABLE_RANDOM_NUMBERS;
    create or replace
    PACKAGE BODY REUSABLE_RANDOM_NUMBERS
    IS
      TYPE NUM_TABLE_TYPE IS TABLE OF CHAR INDEX BY PLS_INTEGER;
      MIN_VALUE CONSTANT PLS_INTEGER := 0;
      max_value CONSTANT PLS_INTEGER := 10;
      NUM_TABLE NUM_TABLE_TYPE;
      FUNCTION GET_NUMBER RETURN NUMBER
      IS
        num PLS_INTEGER;
      BEGIN
        FOR I IN 1 .. 100 LOOP
           NUM := DBMS_RANDOM.VALUE( min_value, max_value );
           IF NOT NUM_TABLE.EXISTS( NUM ) THEN
              NUM_TABLE( NUM ) := 'X';
              RETURN NUM;
           END IF;
        END LOOP;
        FOR I IN MIN_VALUE .. MAX_VALUE LOOP
          IF NOT NUM_TABLE.EXISTS( i ) THEN
              NUM_TABLE( i ) := 'X';
              RETURN i;
           END IF;
        END LOOP;
        RAISE_APPLICATION_ERROR( -20991, 'All possible values have ben used, cannot assign a new one' );
      END;
    END REUSABLE_RANDOM_NUMBERS;
    SELECT REUSABLE_RANDOM_NUMBERS.GET_NUMBER
    FROM DUAL
    connect by level <= 11;
    GET_NUMBER            
    3                     
    4                     
    6                     
    2                     
    1                     
    7                     
    8                     
    0                     
    9                     
    5                     
    10                    
    11 rows selected
    SELECT REUSABLE_RANDOM_NUMBERS.GET_NUMBER
    FROM DUAL;
    Error starting at line 44 in command:
    SELECT REUSABLE_RANDOM_NUMBERS.GET_NUMBER
    FROM DUAL
    Error report:
    SQL Error: ORA-20991: All possible values have ben used, cannot assign a new one
    ORA-06512: przy "TEST.REUSABLE_RANDOM_NUMBERS", linia 26

  • How to set Datagrid 1st row selected

    I want to set 1st row as selected = true as default in
    datagrid after loading the form which out clicking on any item i
    want to set the 1st row as selected, how can i achieve this.
    Thanks in advance

    Thanks for your help,
    Here's the code which i wrote
    datagrid creationComplete="changeColor();"
    [code]
    private function changeColor():void
    dgrid.selectedIndex = 0;
    dgrid.setStyles("selectionColor","#800f3e");
    [/code]

  • Returning Random Row based on Subset of Data within Table

    Hi,
    Please see below.  Running SQL Server 2008 R2.
    Sample DDL:
    CREATE TABLE [dbo].[TestPersons]
    [TestPersonID] [int] NOT NULL IDENTITY(1,1),
    [FirstName] [varchar](50) NULL,
    [LastName] [varchar](50) NULL,
    [AreaID] [varchar](50) NULL,
    CONSTRAINT [PK_TestPersons_TestPersonID] PRIMARY KEY CLUSTERED ([TestPersonID] ASC)
    WITH
    PAD_INDEX = OFF,
    STATISTICS_NORECOMPUTE = OFF,
    IGNORE_DUP_KEY = OFF,
    ALLOW_ROW_LOCKS = ON,
    ALLOW_PAGE_LOCKS = ON
    ON [PRIMARY]
    ON [PRIMARY]
    GO
    Sample Data:
    INSERT INTO
    [dbo].[TestPersons] ([FirstName], [LastName], [AreaID])
    VALUES
    ('Carlos', 'Matlock', 'A0009'),
    ('William', 'Rivas', 'A0001'),
    ('Kathryn', 'Rice', 'A0008'),
    ('John', 'Ball', 'A0009'),
    ('Robert', 'Barnhill', 'A0009'),
    ('Timothy', 'Stein', 'A0009'),
    ('Christopher', 'Smith', 'A0001'),
    ('Brian', 'Speakman', 'A0001'),
    ('Harold', 'Clark', 'A0009'),
    ('Tim', 'Henson', 'A0009'),
    ('Victor', 'Chilson', 'A0009')
    The above insert statement is a small example of the data contained in this table.  Normally the table would contain several thousand rows.  We use the following query to replace actual data with random rows from our test table:
    UPDATE
    [P]
    SET
    [P].[FirstName] = [T].[FirstName],
    [P].[LastName] = [T].[LastName],
    [P].[AreaID] = [T].[AreaID]
    FROM
    [dbo].[Persons] [P]
    INNER LOOP JOIN
    [dbo].[TestPersons] [T] ON ([T].[TestPersonID] = (1 + ABS(CRYPT_GEN_RANDOM(8)%5000)))
    This query works as it selects a random row from the entire set of data in the table.  However there are cases where we need to specify a restricted subset to randomize from.  For example, we may need to randomize data only for Persons with an AreaID
    of A0001 or A0008.  So in that case, and using the sample data above, we would want the  randomization to only select from rows in TestPersons that have an AreaID of A0001 or A0008.  How would I go about accomplishing this?  I've tried
    adding a WHERE clause but it seems it's ignored because of the INNER LOOP JOIN.  I've also tried including [P].[AreaID] = [T].[AreaID] in the join hint but to no avail.
    I also realize having sample data with only the set that we need would solve this problem but for our needs we need a large test set as our randomization requirements depend on the situation.
    Any assistance is greatly appreciated!
    Best Regards
    Brad

    DECLARE @TestPersons TABLE (TestPersonID int NOT NULL IDENTITY(1,1), FirstName varchar(50), LastName varchar(50), AreaID varchar(50))
    INSERT INTO @TestPersons (FirstName, LastName, AreaID)
    VALUES ('Carlos', 'Matlock', 'A0009'), ('William', 'Rivas', 'A0001'), ('Kathryn', 'Rice', 'A0008'), ('John', 'Ball', 'A0009'), ('Robert', 'Barnhill', 'A0009'), ('Timothy', 'Stein', 'A0009'),
    ('Christopher', 'Smith', 'A0001'), ('Brian', 'Speakman', 'A0001'), ('Harold', 'Clark', 'A0009'), ('Tim', 'Henson', 'A0009'), ('Victor', 'Chilson', 'A0009')
    ;WITH subset AS (
    SELECT ROW_NUMBER() OVER (ORDER BY TestPersonID) AS sID, *
    FROM @TestPersons
    WHERE FirstName LIKE '%e%'
    SELECT *
    FROM subset
    WHERE sID = round((((SELECT COUNT(*) FROM subset) - 1 - 1)*rand())+1,0)
    This will grab a random row from a subset (defined in the CTE).

  • Adf Table with selection as set to NONE

    Hi,
    I having a scenario as explained below:
    I am populating records in to the adf Table
    After that I am using checkbox for selecting multiple records in the table and delete them.
    So I set selection property to None for the table. Because I want user to edit only that record which is checked.
    My multiple delete is working fine.
    Now if i selected one checkbox and and click on edit(which I have placed in the panal collection toolbar) it should show me the record in the which I have selected by check box. But it is showing me the first row.
    Can anybody help me to set the current row of the adf table manually which is having selection property as none. so that I can populate in popup.
    If some other way is available please explain.
    I am using jdeveloper 11.1.2.1
    Thanks,
    Sandeep.

    I don't see why you can't set selection property to "single"? (and don't forget to restore table SelectionListener property - if deleted)
    This will set current row when you click on it.
    If you programmatically iterate through RowSet to find rows with selected checkbox, this will work regardless of value in "selection" property.
    Dario
    Edited by: kdario on Nov 7, 2012 5:20 AM
    Edited by: kdario on Nov 7, 2012 5:22 AM

  • Can we enable "Select record Set Message choice" of Table in left side

    Hi ,
    I have requirement to set the "Select Record Set " Message choice of a table region on left side.
    Ex:If there are more records in a table region and message choice available to select next set of records.
    You can chk in Workflow Status Monitor function.
    Its the Navigation Bar to be @ left side on the table Region whcih allows you to navigate the records set.
    Thanks,Sarath.
    Edited by: SarathL on Dec 13, 2011 4:59 PM

    Hi,
    Not sure what exactly you are looking for.
    The Next link and option to select next set of rows comes to your OA Table by default .. isn't it?
    -Idris

  • 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

  • How to set to display  rows no. in source program

    how to set to display  rows no. in source program ?

    Hi,
    If u r working in 4.5B or older then u ll get it automatically.
    If u want to get numbering in 4.7 or ECC u just do this.
    Utilities -> settings -> ABAP editor
    Then u can select new editor or lod and u can find lot of options there.
    Regards,
    Subbu

  • Delete all rows except 10 random rows

    Hi,
    how can I delete all rows from table JOBS except 10 random rows?
    Someone asked it before (not here..): http://stackoverflow.com/questions/10820105/t-sql-delete-except-top-1
    but I didn't understand the answer, and I don't think it will work in PL/SQL.
    If the answer in StackOverflow does works in PL/SQL, I will glad if someone explains me with better example,
    If the answer in StackOverflow does'nt work in PL/SQL, I will glad if someone gives me an example.
    thanks!

    Actually I found a problem in this solution.
    delete from jobs where rowid not in (select rowid from jobs where rownum<=10) ;I used the above code to delete all rows except 10 in JOB_HISTORY table, but for some reason the rows that were chosen were only in the range in which (144<=EMPLOYEE_ID<=146).
    I tried this several times and always i stayed with rows in this range.
    Here are the queries:
    SQL> select employee_id from job_history;
    EMPLOYEE_ID
    144
    144
    144
    144
    144
    145
    145
    146
    146
    146
    146
    146
    146
    146
    147
    147
    147
    147
    149
    149
    149
    156
    156
    156
    156
    156
    156
    156
    158
    158
    158
    158
    158
    158
    158
    158
    159
    159
    159
    165
    165
    165
    171
    171
    171
    171
    46 rows selected
    SQL> delete from job_history where rowid not in (select rowid from job_history where rownum <= 15);
    31 rows deleted
    SQL> select employee_id from job_history;
    EMPLOYEE_ID
    144
    144
    144
    144
    144
    145
    145
    146
    146
    146
    146
    146
    146
    146
    147
    15 rows selected
    SQL>
    Glad if someone can explain me why I get this result.
    Thanks
    Edited by: 998093 on 05:01 05/04/2013

  • How can i set color some rows in jtable

    hi all,
    i have table with two cols one is id and other name
    i have array of id, i want set color for only those rows in an array
    i tried with the following code but only one row is seting why it is not setting
    the other rows? or this is the worg way what i did?
         model       = new DefaultTableModel(data, header);
            table          = new JTable(model){
                 int mostUsedCols[] = 151,80,185,90,88,95,137,152,153,181,178,179,180,107};
                 public Class getColumnClass(int column)
                        return getValueAt(0, column).getClass();
                   public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
                        Component c = super.prepareRenderer(renderer, row, column);
                               int id = Integer.parseInt(tblLedgerAccounts.getModel().getValueAt(row, 0).toString());
                               for(int j=0; j<mostUsedCols.length;j++){
                                    c.setBackground( id == mostUsedCols[j] ? Color.LIGHT_GRAY : Color.WHITE );
                        return c;
                   }help me to solve this problem
    thanks
    daya

    hello,
    thanks,
    i have table 2 cols(say for ex) 1st column is name and other one is
    id, and i have some array of id's, i need to set the color for these rows
    and remainings rows are defalut color (white).
    I doubt that you need the
    else
    c.setBackground( Color.WHITE );if i did't set like this the entire table get gray.
    >
    since the color should be set to the default by the
    super.prepareRenderer(...) method. In fact this code
    would override the default row selection coloring.
    But maybe I don't understand your requirement. You
    notice my original example always to check to make
    sure the row is not selected before changing the
    background color.here is the demo, i comment this line what will happen c.setBackground( Color.WHITE );
    if not doing right than suggest me.
    import java.awt.Color;
    import java.awt.Component;
    import java.util.Vector;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.ListSelectionModel;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableCellRenderer;
    public class TableColor extends JFrame {
         public TableColor()
              Vector header = new Vector();
              Vector data   = new Vector();
              header.addElement("ID");//0
              header.addElement("Name"); //1
              header.addElement("village"); //2
              Vector v = new Vector();
              v.addElement(new Integer(1));
              v.addElement("daya");
              v.addElement("DVB");
              data.addElement(v);
              Vector v1 = new Vector();
              v1.addElement(new Integer(2));
              v1.addElement("raju");
              v1.addElement("DVBs");
              data.addElement(v1);
              Vector v2 = new Vector();
              v2.addElement(new Integer(3));
              v2.addElement("James");
              v2.addElement("sdf");
              data.addElement(v2);
              Vector v3 = new Vector();
              v3.addElement(new Integer(4));
              v3.addElement("Naga");
              v3.addElement("DVBsadf");
              data.addElement(v3);
              Vector v4 = new Vector();
              v4.addElement(new Integer(5));
              v4.addElement("xyz");
              v4.addElement("asdf");
              data.addElement(v4);
            DefaultTableModel tblModLedgerAccounts      = new DefaultTableModel(data, header);
            JTable tblLedgerAccounts          = new JTable(tblModLedgerAccounts){
                 int mostUsedCols[] = {2,4,5};
                 public Class getColumnClass(int column)
                        return getValueAt(0, column).getClass();
                   public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
                        Component c = super.prepareRenderer(renderer, row, column);
                               int id = Integer.parseInt(getModel().getValueAt(row, 0).toString());
                               for(int j=0; j<mostUsedCols.length;j++){
                                    if(id == mostUsedCols[j]){
                                         c.setBackground(Color.lightGray);
                                         break;
    //                                else
    //                                     c.setBackground(Color.WHITE);
                   return c;
              JScrollPane scrollPaneLedgerAccounts =     new JScrollPane(tblLedgerAccounts);
              tblLedgerAccounts.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
              this.getContentPane().add(scrollPaneLedgerAccounts);
              setVisible(true);
              pack();
              setTitle("Table Color");
              setDefaultCloseOperation(EXIT_ON_CLOSE);
         public static void main(String args[]){
              new TableColor();
    }thanks
    daya

  • How do I change the image used on an movie project icon? iMovie seems to select an image at random from the images I imported.

    How do I change the image used on an movie project icon?
    iMovie seems to select an image at random from the images I imported.

    Not sure I understand how to use what you have posted. Here's what my init() looks like:
    public void init()
    setLayout(new BorderLayout());
    p=new Panel();
    p.setLayout(new GridLayout(1,1));
    callnowButtonURL = getURL(callnowButtonFilename);
    if (callnowButtonURL != null)
    callIcon = new ImageIcon(callnowButtonURL,"call");
    endcallButtonURL = getURL(endcallButtonFilename);
    if (endcallButtonURL != null)
    endIcon = new ImageIcon(endcallButtonURL);
    b=new JButton(callIcon);
    b.setBorder(new EmptyBorder(0,0,0,0));
    b.setBorderPainted(false);
    b.addActionListener(this);
    p.add(b);
    add(p,"Center");
    Now the ActionListener is basically:
    public void actionPerformed(ActionEvent e)
    if (mybool == false)
    <Perform actions here set mybool to true>
    Change JButton b to use EndIcon
    else
    <Perform actions here set mybool to false>
    Change JButton b to use CallIcon
    Can you clarify how to perform the action I require? You can have a couple of Dukes if you can help me sort this out.

  • Diff between select single * or upto one row

    Hi,
    what is the difference between select single *   and   select upto one row.
    regards
    krishna

    Hi,
    According to SAP Performance course the SELECT UP TO 1 ROWS is faster than SELECT SINGLE because you are not using all the primary key fields.
    select single is a construct designed to read database records with primary key. In the absence of the primary key, it might end up doing a sequential search, whereas the select up to 1 rows may assume that there is no primary key supplied and will try to find most suitable index.
    The best way to find out is through sql trace or runtime analysis.
    Use "select up to 1 rows" only if you are sure that all the records returned will have the same value for the field(s) you are interested in. If not, you will be reading only the first record which matches the criteria, but may be the second or the third record has the value you are looking for.
    The System test result showed that the variant Single * takes less time than Up to 1 rows as there is an additional level for COUNT STOP KEY for SELECT ENDSELECT UP TO 1 ROWS.
    The 'SELECT SINGLE' statement selects the first row in the database that it finds that fulfils the 'WHERE' clause If this results in multiple records then only the first one will be returned and therefore may not be unique.
    Mainly:  to read data from
    The 'SELECT .... UP TO 1 ROWS' statement is subtly different. The database selects all of the relevant records that are defined by the WHERE clause, applies any aggregate, ordering or grouping functions to them and then returns the first record of the result set.
    Mainly: to check if entries exist.
    Regards,
    Bhaskar

Maybe you are looking for

  • I have an iPhone 5 that I bought from straight talk about a year ago. And of course with Straight Talk you get what you pay for. Needless to say I was wondering if I can take my iPhone to AT

    Hey you guys. I am new to the iPhone forums. So please forgive me if I messed up. Now I bought and iPhone last year through straight talk, and needless to say the service I got was horrible. And I read online that Staight Talk iPhones come factory un

  • Sales Order Net Value - Round off

    Hi Guru's, I am having a requirement to round off the total value (VBAK - NETWR) in sales order. Condition type DIFF is not fulfilling our requirement because its functioning as an item condition. It's doing round off for each line item. Our requirem

  • Encore CS3 runtime error in Vista

    Hi guys. Just installed CS3 Production and everything installed fine. Premiere and AE work but when I go boot up Encore I get the "C++ Runtime Error" message. I installed and re installed but still the same when I try and get into Encore. My system i

  • Content aware scale

    Hello, I''m new to photoshop and i noticed the new version uses this great technique of content aware scale but i can't get to make it work on a picture i would like to use. I saw a couple of tutorials but the images they use seem a bit simple and i

  • How Do I Copy the Orignial

    I'm brand new to iMovie and there's something that I'm sure is obvious but I can't seem to get. I imported a 2 hour video and need to cut it up. When I make my first crop, it gets rid of the rest of the video. How do I keep the original, so that I ca