Multiple rows returned trying to select specific row in Oracle SQL

前端 未结 1 1913
南旧
南旧 2021-01-26 01:09

I am trying to return a value from field tid in a specific row in Oracle SQL but I am getting a weird behavior.

First, I tried this:

 select tid from
 (         


        
相关标签:
1条回答
  • 2021-01-26 01:41

    That is because dbms_random() is called for each row, so it can generate duplicate results. Instead, if you want one random row, try something like this:

    select tid
    from (select tid,
                 row_number() over (order by dbms_random.value()) as seqnum
          from Train
         ) t
    where seqnum = 1;
    

    This will always return the row with "seqnum = 1", but it will be a random tid.

    0 讨论(0)
提交回复
热议问题