How to sort a random number without using the command by

Hello

How must be sorted, 5 random number without the use of order by in PLSQL
for example.
amount of ID
1 2
2 9
3 3
4 5
5 7

Edited by: sake1 1-dec-2010 08:16

I used Altavista and found an example, how is it?

DECLARE

  /* there is no built array in oracle, you must declare
  your own */
  TYPE Numarray IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;

  /* the array of numbers - using assoc array because I can start
  with zero like traditional arrays */
  Nums Numarray;

  n NUMBER := 0;

  Temp NUMBER;

BEGIN

  /* load up the array, put 20 random values in the array,
  in array indicies 0 to 19 */
  FOR i IN 0 .. 19

   LOOP
    Nums(i) :=  Round(Dbms_Random.Value(1, 1000));
  END LOOP;

  /* get the array size */
  n :=  Nums.Count();

  /* display the unsorted values - loop through the whole array and
  print out the values */
  Dbms_Output.Put_Line('unsorted:');
  FOR i IN Nums.First .. Nums.Last LOOP
    Dbms_Output.Put_Line(Nums(i));
  END LOOP;

  /* bubble sort - using two loops, compare each value with the one
  after it
  if the one after the current one is smaller , then

  switch their locations in the array, this is just like standard
  bubble sorts
  in other languages. The only real diff is the syntax.
  */

  FOR i IN 0 .. n - 1 LOOP
    FOR j IN 0 .. n - (i + 1) - 1 LOOP

      IF (Nums(j) > Nums(j + 1)) THEN
        Temp := Nums(j);
        Nums(j) :=  Nums(j + 1);
        Nums(j + 1) :=  Temp;
      END IF;

    END LOOP;
  END LOOP;

  /* display the values sorted */
  Dbms_Output.Put_Line('sorted');
  FOR i IN Nums.First .. Nums.Last LOOP
    Dbms_Output.Put_Line(Chr(9) || Nums(i));
  END LOOP;
END;
/*
unsorted:
155
909
795
977
942
214
105
269
283
820
108
594
784
921
856
736
802
457
951
411
sorted
     105
     108
     155
     214
     269
     283
     411
     457
     594
     736
     784
     795
     802
     820
     856
     909
     921
     942
     951
     977

*/

In the code the first comment is wrong in fact, I think, this one:
"There is no table built in oracle, you must declare your own."
I remember there are some types of collection of the system, if I not mix with something, I remember there was a sort of like they were undocumented, so we can say legally that the comment in the code has always been right.

Tags: Database

Similar Questions

  • How can I register my product without using the online process?

    How can I register my product without using the online process?

    He scored finally got.

  • ADD THE AMOUNT WITHOUT USING THE COMMAND

    Hi 2 all...

    the table contains:

    UID billno amount
    1 101 100
    2 102 200
    3 103 300

    the o/p should be:

    UID total amount billno
    1 101 100
    2 102 200 300
    3 103 300 600

    I need the query for this pblm without using the command... Please advice... can someone send immed... Thanks in advance...

    If you still don't bother to write in proper understandable English or probably your keyboard is broken.

    Anyway you can do this

    SQL> WITH t AS (
      2  SELECT 1 col_uid, 101 billno, 100 amount FROM DUAL UNION ALL
      3  SELECT 2, 102, 200 FROM DUAL UNION ALL
      4  SELECT 3, 103, 300 FROM DUAL)
      5  -- end test data
      6  select col_uid, billno, amount, decode(amount, amount_cum, null, amount_cum) amount_cum
      7    from (
      8  select t.*, (select sum(amount) from t t1 where t1.col_uid <= t.col_uid) amount_cum
      9    from t)
     10  /
    
       COL_UID     BILLNO     AMOUNT AMOUNT_CUM
    ---------- ---------- ---------- ----------------------------------------
             1        101        100
             2        102        200 300
             3        103        300 600
    
  • How do Lightroom 4 5 Lightroom without using the creative cloud?

    I have Lightroom 4 and I am interested to upgrade to 5 of Lightroom, but I don't want to use the creative cloud because I can't afford long-term monthly payments. So, how to pass without using the creative cloud? Is it possible to do this through Adobe, or should I buy it elsewhere? Thank you!

    You access this page: products

    and buy the upgrade to LR 5

  • How to get a serial number after using the trial?

    I downloaded the demo of Lightroom 4, and I liked it, so I'll buy it.  However, when I click on the button 'buy' on the Launcher, it redirects me to the purchase page and he asks me if I want to download or have a disk shipped to me.  I just want to buy a serial number to activate my copy for good, since I the trial is essentially the version complete but with a time limit.  How can I do this?

    Click on download.  you don't have to install (or even save the download).  Simply use the serial number to activate the trial you already installed.

    remove the unnecessary download.

  • find the second value of the largset without using the command by

    Hello world

    can tell me, if we can find the second maximum value for a column without using
    order by clause.

    Bye and thanks.

    Hello

    Please see this.

    SQL > select * from emp where sal<(select max(sal)="" from="">

    EMPNO, ENAME, JOB HIREDATE DEPTNO COMM SAL MGR
    ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
    7369 SMITH COMMITTED 7902 17 DECEMBER 20 800 80
    7499 ALLEN 7698 1600 20 FEBRUARY SALESMAN 81 300 30
    7521 WARD 7698 1250 22 FEBRUARY SALESMAN 81 500 30
    7566 JONES MANAGER 7839 2975 2 APRIL 81 20
    7654 MARTIN 7698 28 - SEP - 81 1250 1400 30 SALESMAN
    7698 BLAKE MANAGER 7839 2850 MAY 1, 81 30
    7782 CLARK MANAGER 7839 2450 JUNE 9 81 10
    7788 SCOTT ANALYST 7566 3000 APRIL 19, 87 20
    7844 TURNER 7698 08 - SEP - 81 1500 0 30 SALESMAN
    7876 ADAMS 7788 1100 23 MAY CLERK 87 20
    7900 7698 DECEMBER 3, CLERK JAMES 81 950 30

    EMPNO, ENAME, JOB HIREDATE DEPTNO COMM SAL MGR
    ---------- ---------- --------- ---------- --------- ---------- ---------- ----------
    7902 7566 3000 3 DECEMBER ANALYST FORD 81 20
    7934 MILLER COMMITTED JANUARY 7782 1300 23 82 10
    1-1-10

    14 selected lines.

    SQL > select max (sal) from emp where sal<(select max(sal)="" from="">

    MAX (SAL)
    ----------
    3000

    Concerning

  • How can I do a countdown without use the effects &gt; text &gt; numbers?

    I know how to make a countdown using Effects > text > numbers, but that is limited to "30 000" the number.

    I need to count backwards from 6,500,000,000.

    Any ideas how to remove that (and especially the separation with commas)?

    I was about to try this tutorial , but it has the same limit of number 30000.

    Perhaps misunderstood that, although...

    You probably, but not in a strictly formalistic sense. This problem is a general limitation in how deals AE 16-bit double whole precision that affects all the effects / values of the controls (see here for another such case). When you are missing the obvious, is that you don't recognize that for the Visual result no matter how the numbers are generated mathematically, which means that nothing prevents you to use these multiple effects and stringing together to create the illusion. People have done this for years. As an alternative, try to use layers of text and expressions as explained here.

    Mylenium

  • How to format Satellite A60 302 without using the CD/DVD drive

    Hello

    I have a laptop SATELLITE A60-302, and I had a problem with cd player. I want to format the computer (WIN XP) and I wanned to ask if I can format the computer not by the cd player but another way as disk on key or something...

    Thanks :)

    Hello
    Your best bet might be trying to use an external CD/DVD drive to install Windows XP (must confirm that your laptop can boot from USB CD/DVD). I would not recommend it otherwise because they are pretty complicated and you will encounter other issues.

    Concerning
    Ben

  • How to get a new column without using the update (Please check with the requirment)

    write a query to display the current sal and the new sal for all employees

    condition
    If job = 'MANAGER' and deptno in (10.20) and then newsal has increased by 15% to the current salary.
    If work! = 'MANAGER' and deptno in (10.20) and then newsal has increased by 25% to the current salary.

    Select ename, sal as old_sal,
    -CASE when work = 'MANAGER' and deptno in (10,20) then (sal + (sal * 15) / 100)
    When job! = 'MANAGER' and deptno in (10.20) and then (sal + (sal * 25) / 100)
    Another Sal
    END as new_sal
    EMP;

  • How to view the line of columns without using the pivot keyword

    Hello
    could someone help me how to display lines in columns without using the keyword pivot and actuall is my scenario, iam having two tables with names and examples of data is shown below

    MIDDLE MINAME TASKID TASKNAME IDENTIFICATION PROJECT

    1 PROJ1 1 AA 100 PR1_TASK1
    1 PROJ1 3 CC PR1_TASK3 102
    1 PROJ1 DD 4 103 PR1_TASK4
    1 PROJ1 EE 5 104 PR1_TASK5
    1 PROJ1 6 105 FF PR1_TASK6
    2 PROJ2 EE 5 114 PR2_TASK1
    2 PROJ2 6 115 FF PR2_TASK2
    2 PROJ2 GG 7 116 PR2_TASK3
    2 PROJ2 HH 8 117 PR2_TASK4
    2 PROJ2 9 118 PR2_TASK5 JJ
    2 PROJ2 KK 10 119 PR2_TASK6
    2 PROJ2 1 AA PR2_TASK7 120


    The output should show the project and County of tasks at a given stage as shown below

    project AA BB CC DD EE FF GG HH JJ KK
    1 2 0 1 5 3 2 0 2 1 0
    2 1 2 0 2 1 0 2 4 3 1


    Thanks in advance,
    VVR
    CREATE TABLE pivot_test (
    ID           NUMBER,
    PROJECT      VARCHAR2(10),
    MID          NUMBER,
    MINAME       VARCHAR2(5),
    TASKID       NUMBER,
    TASKNAME     VARCHAR2(10)
    );
    
    INSERT INTO pivot_test VALUES (1, 'PROJ1', 1,  'AA', 100, 'PR1_TASK1');
    INSERT INTO pivot_test VALUES (1, 'PROJ1', 3,  'CC', 102, 'PR1_TASK3');
    INSERT INTO pivot_test VALUES (1, 'PROJ1', 4,  'DD', 103, 'PR1_TASK4');
    INSERT INTO pivot_test VALUES (1, 'PROJ1', 5,  'EE', 104, 'PR1_TASK5');
    INSERT INTO pivot_test VALUES (1, 'PROJ1', 6,  'FF', 105, 'PR1_TASK6');
    INSERT INTO pivot_test VALUES (2, 'PROJ2', 5,  'EE', 114, 'PR2_TASK1');
    INSERT INTO pivot_test VALUES (2, 'PROJ2', 6,  'FF', 115, 'PR2_TASK2');
    INSERT INTO pivot_test VALUES (2, 'PROJ2', 7,  'GG', 116, 'PR2_TASK3');
    INSERT INTO pivot_test VALUES (2, 'PROJ2', 8,  'HH', 117, 'PR2_TASK4');
    INSERT INTO pivot_test VALUES (2, 'PROJ2', 9,  'JJ', 118, 'PR2_TASK5');
    INSERT INTO pivot_test VALUES (2, 'PROJ2', 10, 'KK', 119, 'PR2_TASK6');
    INSERT INTO pivot_test VALUES (2, 'PROJ2', 1,  'AA', 120, 'PR2_TASK7');
    
    SELECT ID as PROJECT,
           SUM(DECODE(miname, 'AA', 1, 0)) AS AA,
           SUM(DECODE(miname, 'BB', 1, 0)) AS BB,
           SUM(DECODE(miname, 'CC', 1, 0)) AS CC,
           SUM(DECODE(miname, 'DD', 1, 0)) AS DD,
           SUM(DECODE(miname, 'EE', 1, 0)) AS EE,
           SUM(DECODE(miname, 'FF', 1, 0)) AS FF,
           SUM(DECODE(miname, 'GG', 1, 0)) AS GG,
           SUM(DECODE(miname, 'HH', 1, 0)) AS HH,
           SUM(DECODE(miname, 'JJ', 1, 0)) AS JJ,
           SUM(DECODE(miname, 'KK', 1, 0)) AS KK
    FROM   pivot_test
    GROUP BY ID;
    
    PROJECT AA BB CC DD EE FF GG HH JJ KK
    ------- -- -- -- -- -- -- -- -- -- --
          1  1  0  1  1  1  1  0  0  0  0
          2  1  0  0  0  1  1  1  1  1  1 
    
  • How to generate a random number within a specified tolerance and control than tolerance.

    I am trying to simulate data without using a data acquisition device using a random number generator and I want to be able to control the "range" the random number generated well.  On the front panel, the user can enter a nominal number, and the random number generator would generate numbers more or less disponibles.003 this number nominal.  The data would be delayed on a chart.  Someone knows how to do this?  Or if it is still possible?

    Just for the sake of information, the random number is supposed to resemble thickness measures, that's why I want to simulate more and less disponibles.003 because the data might be thinner or thicker than the nominal value.

    Thanks in advance!

    Two ways of approaching the issue.  First of all, for even distribution, you can 'Roll the dice', which is the (0,1) random number function, multiply the result by 0.06 and then add Mean - 0.03 to center around average distribution.  If you simulate a real process, my initial guess would be that the results would follow a normal distribution.  In this case, you can use the VI of white noise Gaussian of the palette of generation of signals with a standard deviation of 0.015 if you wanted 0.03 to be the point of 2 sigma, then add average results.

  • I have the table of 3 columns A, B, C. I want to store the sum of columns A B in the C column without using the DML statements. Can anyone help please how to do. ?

    I have the table of 3 columns A, B, C. I want to store the sum of columns A B in the C column without using the DML statements. Can anyone help please how to do. ?

    11.1 and especially you have virtual column

    SQL> create table t
      2  (
      3     a number
      4   , b number
      5   , c generated always as (a+b) virtual
      6  );
    
    Table created.
    
    SQL> insert into t (a, b) values (1, 2);
    
    1 row created.
    
    SQL> select * from t;
    
             A          B          C
    ---------- ---------- ----------
             1          2          3
    

    Before that, a front insert - trigger

    SQL> create table t
      2  (
      3     a number
      4   , b number
      5   , c number
      6  );
    
    Table created.
    
    SQL> create or replace trigger t_default before insert on t for each row
      2  begin
      3    :new.c := :new.a+:new.b;
      4  end;
      5  /
    
    Trigger created.
    
    SQL> insert into t (a, b) values (1, 2);
    
    1 row created.
    
    SQL> select * from t;
    
             A          B          C
    ---------- ---------- ----------
             1          2          3
    
  • How can I download adobe first 11 items without using the DVD?

    How can I download Adobe Premiere elements 11 without using the installer from the DVD

    PE 10, 11, 12, 13 - https://helpx.adobe.com/premiere-elements/kb/premiere-elements-downloads.html

    You can also download the demo version of the software through the page linked below and then use your current serial number to activate it.

    Don't forget to follow the steps described in the Note: very important Instructions in the section on the pages of this site download and have cookies turned on in your browser, otherwise the download will not work correctly.

    Photoshop/Premiere Elements 11: l http://prodesigntools.com/photoshop-elements-11-direct-download-links-pse-premiere-pre.htm

  • How to swap two values without using the third variable using the procedure

    How to exchange the two values without using the third variable using the procedure?

    In a procedure using two mode we pass two values A = x and B = y, and let us pass parameters to receive the output has A = y and B = x without using the third variable

    Published by: Millar on August 19, 2012 11:23

    Your question doesn't seem wise. As written, there is no reason to a third variable, just

    CREATE OR REPLACE PROCEDURE(
      x IN number,
      y IN number,
      a OUT number,
      b OUT number
    )
    AS
    BEGIN
      a := y;
      b := x;
    END;
    

    If it's an interview question, I suspect that the intention was that you had two settings IN OUT and you wanted to swap the values without the help of a third variable.

    Justin

  • count the number of lines without using the count function

    Hello
    How count the number of lines without using the count function?

    Thank you

    Assuming that your statistics table are updated:

    select num_rows
    from   all_tables
    where  table_name = 'YOUR_TABLE_NAME_IN_UPPERCASE';  
    

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14237/statviews_2105.htm#REFRN20286

Maybe you are looking for

  • SCXI-1001/1102/1303

    I have trouble getting accurate readings of my components 1001/1102/1303 thermocouple.  I have 10 channels attached to the device.  All values are not accurate and are negative (in the-300-400 range.)  Moreover, when I unplug a thermocouple of its Pa

  • When you delete a document from the print queue of the printer it says error in command.

    Original title: printer comands There is only one document in that for my printer and I tried remove the document but I can't seem to go the State indicates that it is being deleted but it will not disappear under neath the pages in Quebec there is a

  • 'Radio' using the access point

    Hi all Is it possible to use a radio for mobile users and another radio station for laptop users in AP... ? If possible how do we proceed? Thanks in advance KVS

  • signature. What is 'Initialize communication with RIM® signing authority.

    Hi, as the title suggests, what is 'Initialize communication with RIM® signing authority? It is the number from step 2 by signing the app. These steps has no explanation of how to take the step, he said only: "Initialize communication with RIM® signi

  • Shadow of WordPad menu item "send by e-mail".

    WordPad menu shadow 'Send by email' can I ask, how do I activate the file menu item "Send e-mail". ?