Interview Answer

In C++ itís harder to shoot yourself in the foot, but when you do, you blow off your whole leg. Bjarne Stroustrup

select random 5 records

January 1, 1970 12:00 am

Comments



select random 5 records



												desc HR.employees;
												
												Name           Null     Type         
												-------------- -------- ------------ 
												EMPLOYEE_ID    NOT NULL NUMBER(6)    
												FIRST_NAME              VARCHAR2(20) 
												LAST_NAME      NOT NULL VARCHAR2(25) 
												EMAIL          NOT NULL VARCHAR2(25) 
												PHONE_NUMBER            VARCHAR2(20) 
												HIRE_DATE      NOT NULL DATE         
												JOB_ID         NOT NULL VARCHAR2(10) 
												SALARY                  NUMBER(8,2)  
												COMMISSION_PCT          NUMBER(2,2)  
												MANAGER_ID              NUMBER(6)    
												DEPARTMENT_ID           NUMBER(4)   
												

dbms_random.value returns the random value from the result set.


Solution

   					 
												select * from (select first_name, last_name from hr.employees 
													order by  dbms_random.value) where rownum <=5;
																    

Comments



Please login to add comments.