Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6354801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:38:19+00:00 2026-05-24T22:38:19+00:00

I have table which is having about 1000 rows.I have to update a column(X)

  • 0

I have table which is having about 1000 rows.I have to update a column(“X”) in the table to ‘Y’ for n ramdom rows. For this i can have following query

update xyz set X='Y' when m in (
'SELECT m FROM (SELECT m
FROM xyz
order by dbms_random.value
) RNDM 
where rownum < n+1);

Is there another efficient way to write this query. The table has no index.
Please help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:38:21+00:00Added an answer on May 24, 2026 at 10:38 pm

    I would use the ROWID:

    UPDATE xyz SET x='Y' WHERE rowid IN (
        SELECT r FROM (
            SELECT ROWID r FROM xyz ORDER BY dbms_random.value
        ) RNDM WHERE rownum < n+1
    )
    

    The actual reason I would use ROWID isn’t for efficiency though (it will still do a full table scan) – your SQL may not update the number of rows you want if column m isn’t unique.

    With only 1000 rows, you shouldn’t really be worried about efficiency (maybe with a hundred million rows). Without any index on this table, you’re stuck doing a full table scan to select random records.

    [EDIT:] “But what if there are 100,000 rows”

    Well, that’s still 3 orders of magnitude less than 100 million.

    I ran the following:

    create table xyz as select * from all_objects;
    

    [created about 50,000 rows on my system – non-indexed, just like your table]

    UPDATE xyz SET owner='Y' WHERE rowid IN (
         SELECT r FROM (
              SELECT ROWID r FROM xyz ORDER BY dbms_random.value
         ) RNDM WHERE rownum < 10000
    );
    commit;
    

    This took approximately 1.5 seconds. Maybe it was 1 second, maybe up to 3 seconds (didn’t formally time it, it just took about enough time to blink).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to query in SQL server about which table is having maximum data
I have simple table that has about 80 rows, which I populate dynamically using
I have a MySQL table which has about 30 columns. One column has empty
I have a table in database that is having some fields one of which
I'm having a table and i have a row which is initially set to
I have a table which is full of arbitrarily formatted phone numbers, like this
I have a table which has two varchar(Max) columns Column 1 Column 2 -----------------------
I have a table which has a foreign key referencing itself. This would be
Could someone help me with building the following query. I have a table called
I have following procedure which is filling up null values in a column. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.