Oracle function to retrieve the records randomly

I need function to select a random DB folder.

For example, we have 500 records and an input to the function value is 5 ways, it must display the records randomly between 1 to 5

Thank you

Question is not clear, I thought that Oracle has always returned entries in random order... Do you expect the number of records between 1 & 5?

Kind regards

Tags: Database

Similar Questions

  • LOBs and how to retrieve the record inserted with EMPTY_BLOb()

    Hi guys


    How to retrieve the records inserted with EMPTY_BLOb() instead of NULL value.


    Best greetings
    A.G.

    There must be a better way, but these work:

    SELECT... from tableX where length (lob_column) = 0;
    SELECT... from tableX where dbms_lob.getlength (lob_column) = 0;

    Concerning
    Jonathan Lewis
    http://jonathanlewis.WordPress.com
    http://www.jlcomp.demon.co.UK

    "All experts it is a equal and opposite expert."
    Clarke

  • retrieve the records from the oracle sql query

    Hello

    I'm stuck with a requirement where I need to retrieve some recordset based on the conditions. I won't be able to produce the same data and table here, but I can explain the problem with the example statement:

    If col2 contains 'y' to any folder, then select only the records. Where, as if no line contains the value 'y' for col2 then retrieve all records.

    Database version: Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64 bit Production

    with temp (col1,col2)
    as
    (select level,decode(mod(level,2),0,'y',1,'n')
    from dual
    connect by level < 10)
    select * from temp;
    
    

    Please help, if possible through sql.

    Thank you

    Vikram

    Something like below... Considered as non-null column col2...

    with the temp (col1, col2)

    as

    (select level, decode (mod(level,2), 0, 'y', 1,' no))

    of the double

    connect by level<>

    Select * from temp

    WHERE col2 = NVL ((SELECT col2 FROM temp OÙ col2 = 'y' ET rownum = 1), col2);

  • Need to retrieve the records whose salary is higher than the max of avg salar

    I wrote a query to retrieve the data whose salary exceeds the maximum salary of the avg of all departments
    SELECT * FROM EMP WHERE SAL>
    (SELECT MAX(AVG (SAL)) FROM EMP
    GROUP BY DEPTNO)
    I would like to write that this query using the associates.

    I tried
    SELECT EMPNO,ENAME,SAL FROM EMP E1
    WHERE SAL > ANY( SELECT MAX(AVG(SAL)) FROM EMP E2
    WHERE E1.DEPTNO  = E2.DEPTNO)
    It gives me error that we cannot use a function nested in the collateral.

    What is the solution of the present?

    Thnks

    This?

    select * from emp a
    where exists
    (select 1 from emp b
    where a.deptno=b.deptno
    and a.sal>(select round(max(avg(sal))) from emp group by deptno));
    
  • Oracle does not sort the records

    Hello everyone

    When I select two date columns and sort as two columns below
    select  date1,date2
    from table
    order by date1,date2
    Here the date1 is sorting correctly but should apply the date2 date1 sort right? but it does not work...

    my output is
    12-nov-2010         25-nov_2010
    12-nov_2010         15-nov-2010
    WHY this is happening... ?

    version of the client is oracle 8i
    version of the server is oracle 9i

    pls help

    S

    OK, so Oracle is perfectly order per your request: order by date1, date2.

    I suspect, however, that what you want is: order of trunc (date1), trunc (date2) or maybe just trunc (date1), date2.

  • Programming logic needed to retrieve the records for the last month/week

    Hi all

    I need assistance in programming SQL logic.

    Oracle database version: 10.2.0.3.0

    Requirement

    In an environment of DW, I need to program to weekly and monthly automated batch insert the data from Data_tbl to Reporting_tbl to generate reports. Descriptions of paintings are given below.

    Table 1 - Data_tbl (Source of table - this table is updated daily).

    Record_dt first name last name


    Table 2 - Reporting_tbl_ (the target table)

    Cycle_dt first name last name

    1. monthly report

    In the SQL query, I where clause conditions.

    Where Record_dt > = 1 November 08 ' and record_dt < = 30 November 08 '

    Using the above condition in development, I'm pulling over the last months data source table data. This will be repeated every month, and it should be automated.
    that is, if I run this report at any time in December 2008, he should choose documents dates from Nov 01 to November 30, 2008. If I run this report at any time in January 2009, he should choose documents dates to Dec. 01 to December 31, 2008.
    Date values must be assigned for the last month. Value of Cycle_dt in the target table must be the date of the end of last month as on November 30, 2008, 31-dec-2008.


    2 weekly Report

    In the SQL query, I where clause conditions.

    Where Record_dt > ='01-dec-08' and record_dt < ='' 07-dec-08

    Monday week start date and end date is Sunday.
    If I run the report between the 08 Dec-14 Dec, it should make records of the dates of Dec. 01 to December 7, 2008.
    On 15 December, he should seek from 08 Dec-14 Dec.
    Value of Cycle_dt in the target table must be the date of last weekend, as on December 7, 2008, December 14, 2008.
    Please help me with the logic for both monthly and weekly reports.

    Thank you

    Hello

    TRUNC (dt, 'W') is the beginning of the week, which may be different days, according to the NLS parameters in your session. Unless you want something that varies from one session to the next, you should stick with the weeks of ISO.

    TRUNC (SYSDATE + 1, 'IW') - 1
    

    is the Sunday of the week underway Sunday to Saturday, which starts and ends in 1 day before the ISO week.
    To find the precedent of the week from Sunday to Saturday:

    WHERE   record_dt >= TRUNC (SYSDATE - 6, 'IW') - 1
    AND     record_dt <  TRUNC (SYSDATE + 1, 'IW') - 1
    

    If you were interested in a week from Saturday to Friday (either 2 days earlier than the ISO week):

    TRUNC (SYSDATE + 2, 'IW') - 2
    
  • Retrieve the records of the RD-XV47KF HARD drive

    In recent years, I have used my RD-XV47KF recorder without problems, mainly for recording of TV movies.

    Yesterday when I checked my last record on the HARD drive, I saw that it was present in the list of records, but he was the only one and desperately, I realized that all my previous registered films precious disappeared from this list, as if they had been deleted before from the HARD drive.

    Yet I am totally sure of have not controlled the HARD drive by mistake the clearing process.
    Memory, a particular thing happened before this last record, namely the locked recorder itself is not not able to complete a finalized DVD and I had to unplug-> connect the power supply cable to get out of this locked condition. Yet this should not have caused to erase the HARD drive.

    Although the manual States that clear documents cannot be recovered, as these previous records were not deleted on purpose, but apparently by a strange bad

    I wish one could help me to suggest how I could restore the previous state of my folder list, giving me access to my precious previous recorded films.

    Sorry mate. It is a Toshiba * laptop * user-to-user forum.
    Don t think that there are people who would be able to help you with video recorder RD-XV47KF.

  • Bug LV2011 - error wired to Boolean function breaks during the recording of the previous version

    I just download LabVIEW 2011 this morning. I created this VI and recorded for LV2010 see how he would deal with it. I opened the VI in LabVIEW 2010SP1 and the thread of the error is broken. There is no warning about the problems in recording this VI under an earlier version.


  • GetWindowLongPtr function to retrieve the handle to application

    Hello world

    I used the following line to get the handle to the window of my windProc application

    HINSTANCE appHandle = GetWindowLongPtr (hWnd, GWLP_HINSTANCE);

    promptly, which returned an error saying that "a long value cannot be used to initialize an entity of type HINSTANCE. But when I used the word HINSTANCE as return type, it ends up being fine.

    HINSTANCE appHandle = (HINSTANCE) GetWindowLongPtr (hWnd, GWLP_HINSTANCE);

    I know that the return value is changed when I do this. But I'm curious to know why I have to do exclusively. HINSTANCE is not a long_ptr type? In fact the same thing happened earlier when I tried to assign the function of GetStockBrush to app.hbrBackground. He obliged to specify the return type as HBRUSH.

    This issue is beyond the scope of this site (for consumers) and to be sure, you get the best (and fastest) reply, we have to ask either on Technet (for IT Pro) or MSDN (for developers)
    *
  • How to retrieve the records that contains capital letters only?

    Oracle 12 c.

    I have a column named LAST_NAME in a table called USER.  Some last_name entries are capitalized.  I want to know them.  How can I write an SQL to get?

    E.g.  The returned result should be:

    JOHNSON

    BERLIN

    MCPHILSON

    O'NEILL

    WILLSON

    Thank you.

    Scott

    Select user name where upper (last_name) = last_name

  • Do we not have an oracle function to select the non-null columns at the beginning

    Hello

    I have 8 columns. Some of them may be null.

    I want to display all 8 columns in my result. Columns not null will be first and no one at the end.

    Here is an example of data:

    Employee table:
     Employee_id   Emp_fname  emp_lname  emp_mname  dept salary emp_height  emp_weight
       1               aaa        ddd                d1   100      6           180
       2               bbb                ccc             120                 169
       3               dfe                           d2            5.9         223
    The expected result is:
    result1 result2   result3 result4  result5  result6 result7 result8
    1        aaa        ddd     d1       100     6        180
    2        bbb        ccc     120      169
    3        dfe        d2      5.9      223
    Thank you.

    Published by: BluShadow on July 12, 2012 16:12
    addition of {noformat}
    {noformat} tags for readability.  Please read {message:id=9360002} and do this yourself in future.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

    945559 wrote:
    I'm using Oracle Database 11 g Release 11.2.0.3.0.

    Here is my sample data.

    CREATE TABLE saleshist (product VARCHAR2 (30), q1 NUMBER NUMBER of q2, q3 NUMBER, NUMBER of T4);
    INSERT INTO saleshist VALUES ('EE Oracle', 100, 123, null, 128);
    INSERT INTO saleshist VALUES (null, 'Partitioning', 100, 130, 128);

    desired output:
    col1, col2, col3 col4
    'Oracle EE', 100, 123, 128, null
    "Partitioning", 100,130,128, null

    It seems that you have 4 column headers, but 5 columns.

    Assuming that the character ' ~' never occurs in one of the columns:

    WITH   got_list           AS
    (
         SELECT     '~' || product
              || '~' || TO_CHAR (q1)
              || '~' || TO_CHAR (q2)
              || '~' || TO_CHAR (q3)
              || '~' || TO_CHAR (q4)     AS list
         FROM    saleshist
    )
    SELECT  REGEXP_SUBSTR (list,  '[^~]+', 1, 1)     AS col1
    ,       REGEXP_SUBSTR (list,  '[^~]+', 1, 2)     AS col2
    ,       REGEXP_SUBSTR (list,  '[^~]+', 1, 3)     AS col3
    ,       REGEXP_SUBSTR (list,  '[^~]+', 1, 4)     AS col4
    ,       REGEXP_SUBSTR (list,  '[^~]+', 1, 5)     AS col5
    FROM    got_list
    ;
    

    Output:

    COL1            COL2       COL3       COL4       COL5
    --------------- ---------- ---------- ---------- ----------
    Oracle EE       100        123        128
    Partitioning    100        130        128
    

    If you need a multiple character string, such as '? ~', to delimit the columns, then the same basic approach works, but the regular expression is messier.

    Product is just another column in this solution. Can be NULL, and it doesn't have to be unique.

  • Function to retrieve the first day of the month.

    Select (sysdate, 'IW') of double

    I know it takes the date of Monday. Is there a function like above that has the date of return to the first Monday of the month?

    Thanks in advance.

    Hello

    NEXT_DAY is very convenient, but it is dependent on the NLS_DATE_LANGUAGE, and you cannot pass an argument to override that.
    TRUNC (dt, 'IW') is not in the NLS settings, then you may prefer this:

    TRUNC ( 6 + TRUNC (SYSDATE, 'MONTH')
          , 'IW'
          )          AS first_monday
    

    1st Monday of the month is fixed to the Monday or before the 7th of the month.

  • Is it possible to retrieve the record date of maximum in one step?

    Look for not having to create two steps for these data (for example, create a table with the values I want and then in the second stage, link to these maximum values)

    So, what I have is:

    SELECT
    a.mbr_id
    b.address_1
    b.address_start_date

    Of
    Member has,
    b address

    WHERE a.mbr_id = b.member_id

    GROUP BY
    a.mbr_id
    b.address_1


    There may be a mbr_id attached to many address_1 in the address (but only a record of mbr_id by Member to Member). So, I want to, on one line, address_1, which is attached to the maximum address_start_date.

    Is it possible to do in 1 (one) step? Or what I need to create a table with the values maximum address_start_date first, then link to this table in a second time to get the max address_1 values?

    NOTE: in the SQL above, I added address_start_date just to show that this field exists in the address, I know that I must remove this, if there is another way to get what I want.

    Thanks for any help...

    Hello!

    Try the following SQL code:

    SELECT
    a.mbr_id
    substr (MAX (to_char (b.address_start_date, ' ' YYYY/MM/DD HH24:MI:SS) | b.address_1), 20)-if 20 is not OK try 19 or 21

    Of
    Member has,
    b address

    WHERE a.mbr_id = b.member_id

    GROUP BY
    a.mbr_id

    Explanations:
    1. "to_char (b.address_start_date, ' ' YYYY/MM/DD HH24:MI:SS) | b.address_1' allows you to link an address on the date indicated on the same line and the date is in a format that is well ordered as VARCHAR2.
    2 MAX (...) will build on the first 19 characters (the length of the day)
    3 SUBSTR (...) allows you to eliminate the date (which was used only for the order) and have the address only.

    Please please tell me if this solves your problem.

    Published by: user1810145 on October 27, 2010 08:07

  • displaying the records randomly after 24 hours

    Hello
    SQL> desc videos
     Name                                      Null?    Type
     ----------------------------------------- -------- ----------------------------
     V_ID                                      NOT NULL NUMBER(14)
     VIDEODATE                                          TIMESTAMP(0)
     CATEGORY                                           NUMBER(5)
     VIDEOIMAGE                                         VARCHAR2(110)
     VIDEO                                              VARCHAR2(110)
     TITLE                                              VARCHAR2(110)
     ACTIVE                                             NUMBER(2)
    Can I show random files after 24 hours?

    Best regards

    Try this

    select * from videos
    where VIDEODATE <= CAST((sysdate-1) AS TIMESTAMP)
    order by dbms_random.random
    
  • How to retrieve the values of character without using single quotes

    Hi all

    How to retrieve the values of character without the use of single quotes. Its Possible in Oracle SQL

    Please answer me...

    For example

    Is actual query-> Select * from employees where name like in("SCOTT", "JAMES", "ALBERT",...);

    I want to--> Select * from employees where name like(SCOTT, JAMES, ALBERT...); -without the use of single quotes.

    Why I need this application, I need to retrieve the records more than 200 employees in a select statement by using name in where clause.

    shagarmahabubjan wrote:

    Hi all

    How to retrieve the values of character without the use of single quotes. Its Possible in Oracle SQL

    Please answer me...

    For example

    Actual query is---> Select * from employees where name like in("SCOTT", "JAMES", "ALBERT",...);

    I want to---> Select * from employees where name like(SCOTT, JAMES, ALBERT...); -without the use of single quotes.

    Why I need this application, I need to retrieve the records more than 200 employees in a select statement by using name in where clause.

    In short... you can't.  The channels are channels, and SQL and PL languages dictate that the string literals are provided within single quotes.

    I don't see how trying to retrieve more than 200 records of employees in the select statement means that you must get rid of the quotes.

    Be clear in what you ask: Re: 2. How can I ask a question on the forums?

    and take note of the FAQ link davidp provided the solution "variable IN the list.

Maybe you are looking for

  • It is possible to pair your Apple Watch without reset after reset an iPhone

    Do you have a factory reset on an iPhone 6s yesterday and restored my phone from my last iPhone cloud upward. I want to connect my Apple Watch, but I'm afraid to reset.  I read that the watch automatically backup with a back of iCloud, then is safe r

  • How to acquire video lines

    Dear AE I'm working on the acquisition of several consecutive lines of video composite using Multi. Documents with my module PCI-5122. I did it with different ways to program the video trigger with configuration of different line numbers. I attached

  • follow-up of the CPU

    Hello I recently inherited several servers that use BB. Apparently the administrator previous really like BB, but just left default settings. I am now trying to tweak it, so it may be of some use. I have several servers with hot cpu. Normal cpu setti

  • Share a text file

    I would like to share a text file with all the possible objectives, but the invocation will automatically open an email with the file attached. I can click on the attachment and select sharing, but I'd like to get this default selection. What's wrong

  • No scheduled task running in Windows 7

    I am running 32-bit Windows 7 Home Premium. There are about 5 days all tasks stop running scheduled. Task Scheduler says: Summary: 0, total 0-0 running succeeded, 0 stopped, 0 failed The Scheduler and its dependencies are all running and configured t