SQL how to choose random values where clause?

Hello guys,.

for example, I want to choose 25 numbers in the answer column which is end 6?



Select the number of numbers where regexp_like (number, $ 6 '); Like that, but I don't want every number that ends with 6 I want to only 25 of them?


Thank you very much.

953116 wrote:
How can I choose at random?

SELECT *
  FROM (  SELECT number
            FROM numbers
           WHERE REGEXP_LIKE (number, '6$')
        ORDER BY DBMS_RANDOM.VALUE)
 WHERE ROWNUM < 26

Tags: Database

Similar Questions

  • How to choose the value of a string are numeric together and words of letters (for example, TEST)

    Hi all

    How to choose the value of a string are letters (for example, TEST) and all numeric...

    for example
    TEST 123456
    TEST 34567
    123456 ABCD
    1234 TEST
    TESTING 12345
    TEST 1@234$
    YOUR T 123456

    I want the results of the query as below.
    TEST 123456
    TEST 34567

    And I tried to use regexp_like in this case but without success. See the code below.
    SELECT * FROM TABLE WHERE regexp_like (Description, ' [TEST] % & [[: digit:]] + $');

    How can I do this, please answer.

    Thank you

    WF

    If you want to return only the rows that contain the string 'TEST', followed by zero or more space characters, followed by one or more digits?

    How about this:

    SELECT *.

    FROM my_table

    WHERE REGEXP_LIKE(description,'^TEST\s*\d+$')

  • How to choose the value null

    Hi all

    I use oracle 9i.
    I have a Book table and there column: book_id, book_name, book_rating etc.
    Books are rated on a scale of 1 to 10, and the database is associated with a book.
    There are books that are not yet rated and these recordings has a null value in this column to book_rating.

    I want to write a cursor that can browse this book_rating.
    I started with a loop for iteration of 1.10 (because I in 1.10 loop)
    and in this loop, I declare my cursor and where clause wrote:

    where book_rating = i;

    This condition will take care of the sides with a value of 1 to 10, but this custom work for null values.

    How can I write this code so that I can understand the books that are not rated so far (null in the column book_rating)?

    Thank you

    Will be something like this help

    FOR I IN 0..10
    LOOP
         SELECT ..
           FROM ..
          WHERE NVL(BOOK_RATE,0) = i;
    END LOOP;
    
  • How to go from LOV where clause Page CO params

    Dear members,

    I have an OFA Page for which I have defined a CO.

    I also have a LOV for which I have two parameters in where clause.

    Now my requirement is to pass the two values in the where clause of LOV to the co of the corresponding page parameters.

    Anyone can guide me please in implementing this requirement.

    Best regards
    Arun Reddy

    Hi Arun

    as gyan, suggested trying attching a new controller of lov or extend its existing controller.

    In the CO page
    store the parameter which must be transmitted to lov in pageContext.putSessionValue (paramName, paramValue)

    In the Lov CO page, processrequest
    retrieve the stored values using pageContext.getSessionValue (paramName)

    Concerning
    Ravi

  • How to choose only values in double

    Hi guys,.

    How can I retrieve only duplicate values in a column?
    Then,
    How can I remove duplicate values?

    Best wishes
    Fateh

    PLEASE CHECK THIS:

    Select * from TABLENAME
    WHERE DUPLICATECOLNAME = (select DUPLICATECOLNAME from TABLENAME ANY
    where rowid NOT in (select max (rowid) of the TABLENAME of DUPLICATECOLNAME group))

  • How to choose a song where I left off?

    I'm sure there must be a simple answer to this, but if I turn off my Sansa Connect, while he plays a song, how to pick up where it left off when I turn it back?

    Have you tried to just sleep (quick press of the button / stop) rather than stop it (hold power for about 8 seconds)?

    I don't really know who does not work as I don't have my connection with me right now.  I'm sure that it will play the same song, but I don't know if she'll resume exactly where you left it.

  • How to use DATE in where clause

    I need to select the list of records in a table where the available date is greater than or equal to the current date. This is the structure of the table and
    Select the query that is used to get the list of records
    CREATE TABLE TEMP (ITEM_ID NUMBER(20),ITEM_NAME VARCHAR2(100),CREATION_DATE DATE,AVAILABLE_DATE DATE);
    
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(1,'ITEM1',SYSDATE,SYSDATE);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(2,'ITEM2',SYSDATE,SYSDATE+10);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(3,'ITEM3',SYSDATE,SYSDATE-10);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(4,'ITEM4',SYSDATE,SYSDATE);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(5,'ITEM5',SYSDATE,SYSDATE+5);
    
    SELECT ITEM_NAME, available_date FROM TEMP WHERE available_date > SYSDATE OR available_date LIKE SYSDATE;
    I get the documents expected but I'm not able to find a condition where I can use * > = * a query as the below a date data type, is
    do not return only documents not expected
    SELECT ITEM_NAME, available_date FROM TEMP WHERE available_date >= SYSDATE ;
    Published by: Barro on March 19, 2012 21:13

    Hello

    Barros says:
    I need to select the list of records in a table where the available date is greater than or equal to the current date. This is the structure of the table and
    Select the query that is used to get the list of records

    CREATE TABLE TEMP (ITEM_ID NUMBER(20),ITEM_NAME VARCHAR2(100),CREATION_DATE DATE,AVAILABLE_DATE DATE);
    
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(1,'ITEM1',SYSDATE,SYSDATE);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(2,'ITEM2',SYSDATE,SYSDATE+10);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(3,'ITEM3',SYSDATE,SYSDATE-10);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(4,'ITEM4',SYSDATE,SYSDATE);
    INSERT INTO TEMP (ITEM_ID,ITEM_NAME,CREATION_DATE,AVAILABLE_DATE) VALUES(5,'ITEM5',SYSDATE,SYSDATE+5);
    
    SELECT ITEM_NAME, available_date FROM TEMP WHERE available_date > SYSDATE OR available_date LIKE SYSDATE;
    

    Both operands for AS are supposed to be strings. Do not try to use a DATE, such as SYSDATE, with AS.

    I get the documents expected but I'm not able to find a condition where I can use * > = * a query as the below a date data type, is
    do not return only documents not expected

    SELECT ITEM_NAME, available_date FROM TEMP WHERE available_date >= SYSDATE ;
    

    It returns the results I expect.
    If you'd say what results you expected, could someone help you wite a query to get.

    Assuming that 1 second elapses between the time "ITEM4" is inserted and that 2nd query execution, then, running, available_date will be 1 second less than SYSDATE, so it shouldn't be included.
    If you want to find lines that are on the same calendar day as SYSDATE or later, then use

    WHERE    available_date >= TRUNC (SYSDATE)
    
  • How to choose Download preferences (where to send ' em, etc.)?

    When I download a photo of gmail, the list is empty, and the winds of the photo upward buried. I want it on my desk as a first step.

    == Question (mine, I guess - not firefox)

    If you look at the menu options (Firefox > Options), there should be a downloads section under the general tab you can change to anything you download go to the desktop.

    I'm using Firefox on Linux right now, but there should be a menu similar to the screenshot I attached.

  • How to define a WHERE clause of the subquery in a bean managed?

    Hi people,

    is it possible to define the place where clause of a subquery in a bean managed?
    For example, it is more SQL charly:

    SELECT * FROM
    (SELECT Person.Name
    OF the person)

    To change or add a WHERE clause, I use following code for the 'viewObject: view

    String whereClause = "ROWNUM < =: numberOfRows;
    viewObject.setWhereClause (whereClause);

    viewObject.defineNamedWhereClauseParam ("numberOfRows", null, null);
    viewObject.setNamedWhereClauseParam ("numberOfRows", new Number (100));

    AttributeList myattr = this.getNamedWhereClauseParams ();
    viewObject.setNamedWhereClauseParams (myattr);

    For example, this code works well for the first SELECT statement limit the output to the first 100 results. But how do I add a WHERE clause of the subquery in a managed bean? For example, when I want to limit the names of people that begin with the letter "A"?
    The query should look like this:

    SELECT * FROM
    (SELECT Person.Name
    OF the person
    WHERE Person.Name LIKE 'A %')

    Anyone know more?

    Thank you!

    Put a variable binding in your query, something like:

    where (: bv is null) or (xxx love: bv)

    John

  • Statement UPDATE of SQL TIP about WHERE CLAUSE

    (1) Oracle does support SQL UPDATE statement of SUSPICION for WHERE CLAUSE
    (2) if so, then please give example.
    Thank you.

    Hello

    Yes, it is possible to use the "tips" in the Update statement

    Sake example

    Update
    / * + rowid * /.
    tableX
    Set char_date = '19' | char_date
    where nvl (length (char_date), 0) = 6
    and rowid between chartorowid ('000927.0000.0008')
    and chartorowid('000A3F.) FFFF.0008');

    http://Stanford.edu/dept/ITSS/docs/Oracle/10G/server.101/b10752/hintsref.htm#27647

    -Pavan Kumar N

  • where clause to query the hierarchy in the tree Apex area does not

    Hi all

    I am building a tree Menu in Apex 5.0.3 (Oracle 11 g XE), when using when the clause, it does show all the data, but without him, showing all the data.

    I'm trying to populate Tree Menu with data specific to a user successfully logged on.

    (A) table created as HR2. TREE_MENU

    menu_name varchar2 (50).

    number of menu_parent

    number of menu_child

    menu_id varchar2 (12),

    menu_path varchar2 (100),

    number of user_no

    (B) SQL statement for the tree in the Apex region

    Select case when connect_by_isleaf = 1 then 0

    When level = 1 then 1

    else                           -1

    end the status,

    level,

    'Menu_name' as the title,

    NULL as an icon,

    "MENU_CHILD" as a value.

    NULL as ToolTip,

    NULL as link

    to HR2. "" TREE_MENU ".

    -WHERE USER_NO =: P_USERNO

    Start with 'MENU_CHILD' is null

    connect prior "MENU_PARENT" = "MENU_CHILD."

    brothers and sisters of order by 'MENU_ID '.

    Note: also used static value where clause but is not workd.

    that the mistake of me or something else? When using the wizard, she asks (possibly) where clause, this means that when the clause can be used in the SQL statement.

    Help, please.

    Kind regards.

    If you want to prune your tree to show only the elements of the No. 7 usermenu, copy the following code helps you

    select case when connect_by_isleaf = 1 then 0
                when level = 1             then 1
                else                           -1
           end as status,
           level,
           "MENU_NAME" as title,
           null as icon,
           "MENU_CHILD" as value,
           null as tooltip,
           null as link
    from HR2."TREE_MENU"
    start with "MENU_CHILD" is null
    connect by
        prior "MENU_PARENT" = "MENU_CHILD"
        and "USER_NO" = 7
    order siblings by "MENU_ID"
    

    Concerning

    Mahmoud

  • DECODE inside the WHERE clause

    Hi all:

    I can't get the DECODE statement to work inside my WHERE clause. I have read the information on
    Tahiti.Oracle.com
    http://download.Oracle.com/docs/CD/E11882_01/server.112/e17118/functions049.htm#i1017437

    But still can not get it to work. Initially, I had he works as dynamic SQL and then run that string, but I am not allowed to use dynamic SQL statements and to do 'Real' PL/SQL.

    I have the following WHERE clause (more info after the WHERE clause)
    WHERE 
         a.ebiz_asn_no(+) = te.ebiz_cntrl_no
         AND w.ebiz_work_no(+) = te.ebiz_cntrl_no
         AND o.ebiz_ord_no(+) = ebiz_cntrl_no
         AND t.ebiz_trailer_no(+) = te.ebiz_trailer_no
         AND ms.ebiz_sku_no(+) = te.ebiz_sku_no 
         AND NVL(ms.ebiz_sku_no, -1) = NVL(p_SKU, nvl(ms.ebiz_sku_no, -1))
         AND tl.ebiz_lp_no(+) = te.ebiz_lp_no 
         AND NVL(te.ebiz_lp_no, -1) = NVL(p_LP, nvl(te.ebiz_lp_no, -1))
         AND eu.ebiz_user_no(+) = te.act_ebiz_user_no 
         AND NVL(te.act_ebiz_user_no, -1) = NVL(p_UserID, NVL(te.act_ebiz_user_no, -1))
         AND NVL(te.begin_location, '~') = NVL(p_BeginLocation, NVL(te.begin_location, '~')) 
         AND NVL(te.end_location, '~') = NVL(p_EndLocation, NVL(te.end_location, '~')) 
         AND te.comp_id = p_CompID 
         AND te.site_id = p_SiteID 
         AND INSTR('' || p_TaskType || '', te.task_type) > 0 
         AND NVL(task_priority, -1) = NVL(p_Priority, NVL(task_priority, -1)) 
         AND NVL(te.ebiz_cntrl_no, -1) = DECODE(te.task_type, 'IULD', DECODE(p_Order, null, te.ebiz_cntrl_no, ebiz_po2asn.get_ebiz_po_no(p_Order)), NVL(p_Order, NVL
                           (te.ebiz_cntrl_no,-1)))
         AND NVL(te.batch_no,'~') = NVL(p_Batch, NVL(te.batch_no, '~'))
         AND NVL(te.ebiz_wave_no, -1) = NVL(p_Wave, NVL(te.ebiz_wave_no, -1)) 
         || whereClauseStatus 
         || whereClauseFromDate 
         || whereClauseToDate;
    As you can see, initially I was adding values of "whereClauseStatus, whereClauseFromDate, whereClauseToDate" and it has been defined with the following PL/SQL code:
         IF(p_TaskStatus = 'C') THEN
              -------------------------------------------------------------------------------------------
              --     Set From Date Clause
              -------------------------------------------------------------------------------------------
              IF(p_FromShipDate IS NOT NULL) THEN
                   whereClauseFromDate := ' AND TRUNC(te.act_end_date) >= TO_DATE(''' || p_FromShipDate || ''',''MM/dd/yyyy'') ';
              END IF;
              -------------------------------------------------------------------------------------------
              --     Set To Date Clause
              -------------------------------------------------------------------------------------------
              IF (p_ToShipDate IS NOT NULL) THEN
                   whereClauseToDate := ' AND TRUNC(te.act_end_date) <= TO_DATE(''' || p_ToShipDate || ''',''MM/dd/yyyy'') ';
              END IF;
         ELSE
              -------------------------------------------------------------------------------------------
              --     Incomplete and All statuses are filtered on the currdate
              -------------------------------------------------------------------------------------------
              -------------------------------------------------------------------------------------------
              --     Set From Date Clause
              -------------------------------------------------------------------------------------------
              IF(p_FromShipDate IS NOT NULL) THEN
                   whereClauseFromDate := ' AND TRUNC(te.currdate) >= TO_DATE(''' || p_FromShipDate || ''',''MM/dd/yyyy'') ';
              END IF;
              -------------------------------------------------------------------------------------------
              --     Set To Date Clause
              -------------------------------------------------------------------------------------------
              IF (p_ToShipDate IS NOT NULL) THEN
                   whereClauseToDate := ' AND TRUNC(te.currdate) <= TO_DATE(''' || p_ToShipDate || ''',''MM/dd/yyyy'') ';
              END IF;
         END IF;
         
    
         IF (p_TaskStatus = 'I') THEN
              whereClauseStatus := ' AND act_end_date IS NULL ';
         ELSIF (p_TaskStatus = 'C') THEN
              whereClauseStatus := ' AND act_end_date IS NOT NULL ';
         ELSE
              whereClauseStatus := '';
         END IF;
    I have serious problems getting the DECODE statement to replace the three variables in the annex.

    Any help would be greatly appreciated.

    Thank you
    Andy

    Published by: BluShadow on August 2, 2011 15:11
    addition of {noformat}
    {noformat} tags for clarity. Please read {message:id=9360002} and learn to do this yourself.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

    I'll take a wild shot in the dark, and suggests that it is perhaps what you are looking for...

    WHERE
         a.ebiz_asn_no(+) = te.ebiz_cntrl_no
         AND w.ebiz_work_no(+) = te.ebiz_cntrl_no
         AND o.ebiz_ord_no(+) = ebiz_cntrl_no
         AND t.ebiz_trailer_no(+) = te.ebiz_trailer_no
         AND ms.ebiz_sku_no(+) = te.ebiz_sku_no
         AND NVL(ms.ebiz_sku_no, -1) = NVL(p_SKU, nvl(ms.ebiz_sku_no, -1))
         AND tl.ebiz_lp_no(+) = te.ebiz_lp_no
         AND NVL(te.ebiz_lp_no, -1) = NVL(p_LP, nvl(te.ebiz_lp_no, -1))
         AND eu.ebiz_user_no(+) = te.act_ebiz_user_no
         AND NVL(te.act_ebiz_user_no, -1) = NVL(p_UserID, NVL(te.act_ebiz_user_no, -1))
         AND NVL(te.begin_location, '~') = NVL(p_BeginLocation, NVL(te.begin_location, '~'))
         AND NVL(te.end_location, '~') = NVL(p_EndLocation, NVL(te.end_location, '~'))
         AND te.comp_id = p_CompID
         AND te.site_id = p_SiteID
         AND INSTR('' || p_TaskType || '', te.task_type) > 0
         AND NVL(task_priority, -1) = NVL(p_Priority, NVL(task_priority, -1))
         AND NVL(te.ebiz_cntrl_no, -1) = DECODE(te.task_type, 'IULD', DECODE(p_Order, null, te.ebiz_cntrl_no, ebiz_po2asn.get_ebiz_po_no(p_Order)), NVL(p_Order, NVL
                           (te.ebiz_cntrl_no,-1)))
         AND NVL(te.batch_no,'~') = NVL(p_Batch, NVL(te.batch_no, '~'))
         AND NVL(te.ebiz_wave_no, -1) = NVL(p_Wave, NVL(te.ebiz_wave_no, -1))
         AND TRUNC(te.act_end_date) >= NVL(TO_DATE(p_FromShipDate,'MM/dd/yyyy'),TRUNC(te.act_end_date))
            AND TRUNC(te.act_end_date) <= NVL(TO_DATE(p_ToShipDate,'MM/dd/yyyy'),TRUNC(tw.act_end_date))
            AND TRUNC(te.currdate) >= NVL(TO_DATE(p_FromShipDate,'MM/dd/yyyy'),TRUNC(te.currdate))
         AND TRUNC(te.currdate) <= NVL(TO_DATE(p_ToShipDate,'MM/dd/yyyy'),TRUNC(te.currdate))
            AND (  (act_end_date IS NULL AND p_TaskStatus = 'I')
                OR (act_end_date IS NOT NULL AND p_TaskStatus = 'C')
                OR p_TaskStatus NOT IN ('I','C')
                )
    

    Published by: BluShadow on August 2, 2011 16:27
    spleen the last clause. Oops.

  • How to set SQL that contains 'in' where clause in VO?

    I don't want to set "in" would adopt a kind of programatical in VO as below. I want to use a method declariable to set in the clause using bindings varaible.

    It can be implemented?

        private String getInClauseWithParamNames(List termCodes) {
               //logic to form the in clause with multiple bind variables
               StringBuffer inClause = new StringBuffer(); 
               if(termCodes !=null){
                   for (int i = 1; i < termCodes.size() + 1; i++) { 
                       inClause.append(":termC" + (i));
                       if (i < termCodes.size()) { 
                          inClause.append(","); 
                       } 
                   }
               }
               return inClause.toString();
        }
            
        public Row[] getYardFixedSlots(List termCodes) {
            if(termCodes != null && !termCodes.isEmpty()){
                String inClause = getInClauseWithParamNames(termCodes);
                //setting the where cluase to use the generated in clause
                this.setWhereClause("YardFixedSlot.TERMINAL_C in (" + inClause + ")");
                ////clearing all existing where clause params if any 
                this.setWhereClauseParams(null);
                if(getVariableManager() !=null){
                   this.getVariableManager().clearVariables();
                }
                //setting values for all bind variables one by one in the in clause
                for (int i = 0; i < termCodes.size(); i++) { 
                    //defining the named bind variables programatically 
                    this.defineNamedWhereClauseParam("termC" + (i + 1), null, null);
                    //setting the value for each named bind variable 
                    this.setNamedWhereClauseParam("termC" + (i + 1), termCodes.get(i)); 
                }
                this.setRangeSize(-1); 
                //executing the query 
                this.executeQuery(); 
            }
            //returning the rows from query result 
            return this.getAllRowsInRange(); 
        }
    

    You can only use the link as a parameter to the in clause. You must divide the string inside the binding variable. Sample can be found at decompilation binary ADF: using bind variable for SQL statements with the paragraph

    Timo

  • How to pass a value LOV to where clause of another LOV

    Hello

    I have the two LOV project and activity. When I select a value of project LOV this value project to switch to the 2nd activity LOV where clause. How can I achieve this.

    I tried to use the code in the process CO request by getting the value of project with the command below.

    int v_project = Integer.parseInt ((String) passiveCriteria.get ('Project')); grab the critirea project

    and set this value in the setwhereclauseparams of the VO LOV. But the above command is throwing an exception with the exception of null pointer.

    This approach is correct, or should I use any other method.

    Thank you
    HC

    Below you will find the article interesting

    http://oracleanil.blogspot.com/2010/12/dependent-lov-in-OAF.html

    Thank you
    AJ

  • How to solve where clause matter when it can have a value or be null.

    Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production

    Hello, I am trying to understand how a query in which I have a where clause clause that can be null or a value, that is to say:
    SELECT   supply,
                  duration,
                  count,
                  action
    FROM     MDR
    WHERE    (client     = gbl_client OR (group = gbl_group AND section = gbl_section ))
    AND      (prov_code   = gbl_prov_code );
    In the query, the gbl variables can have a value or be null, based on the results of a previous cursor. The problem is that if they have the value NULL, I don't get the correct results because where clause will have to be modified to be checked IS NULL instead of = gbl. Is it possible to do it by modifying select it?

    Hello

    Because these columns are all strings, the CONCAT method will work fine:

    SELECT     *
    FROM     mdr
    WHERE     '?' || grp       = '?' || glb_grp         -- GROUP is not a good column name
    AND     '?' || section    = '?' || glb_section
    AND     '?' || prov_code  = '?' || prov_code
    ;
    

    I think that the code is a little nicer with the '?' before the actual data. No matter whether it is before or after, just be consistent.

    Published by: Frank Kulash, January 25, 2011 15:59

Maybe you are looking for