How effectively select rows randomly a large table?
HelloThe following code selects 5 lines of a random set of rows in the table emp (employee)
select *
from (
select ename, job
from emp
order by dbms_random.value()
)
where rownum <= 5
My concern is that the internal selection causes a table scan in order to assign a random value to each line. This code when it is used against a large table can be a performance issue.Is there an effective way to random selection rows in a table without having to do a table scan? (I'm new to Oracle, so it is possible that miss me a very simple way to perform this task.)
Thank you for your help,
John.
Published by: 440bx on July 10, 2010 18:18
Take a look at the clause of the select statement. The number in brackets is a percentage of the table.
SQL> create table t as select * from dba_objects;
Table created.
SQL> explain plan for select * from t sample (1);
Explained.
SQL> @xp
PLAN_TABLE_OUTPUT
-------------------------------------------------------------------------------
Plan hash value: 2767392432
----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 725 | 70325 | 289 (1)| 00:00:04 |
| 1 | TABLE ACCESS SAMPLE| T | 725 | 70325 | 289 (1)| 00:00:04 |
----------------------------------------------------------------------------
8 rows selected.
Tags: Database
Similar Questions
-
How to select rows randomly by the percentage of lines by specific column
I need to select exactly 20% of lines by Department randomly. Ex, table composed of 50 records for the Sales Department, 60 discs for the Department of human resources. I need to get 10 records of the Department sales and 12 records of Department of human resources. but records should be chosen at random. How to get out of it? Thanks in advance.
Select
DEPTNO
count (*) NTC
WCP
Deptno group
DEPTNO CNT
30 6
20 5
3 of 10
Choose 50% in every department at random
expected (round up to the next integer)
DEPTNO CNT
30 3
20 3
2 of 10
Select * from)
Select
EmpNo
deptno
, count (*) during the (partition deptno) cnt
row_number() over (partition by deptno arrested by dbms_random.random) rn
WCP
)
where rn<=>=>
order by deptno
EMPNO DEPTNO CNT RN
7782 10 3 1
7934 10 3 2
7566 20 5 1
7876 20 5 2
7902 20 5 3
7900 30 6 1
7521 30 6 2
7654 30 6 3
-
How to select all text in a table with a single click cell?
How to select all text in a table with a single click cell? I use TextField.selectAll () when you implement a table cell factory. But when I select a line with a single click, then a click on a table cell again: see the result image
The text in the table cell is not all selected. What I simply selects all the text in a table cell when there is a click on it. How to realize that? Thank you
Thanks for help ~.
-
Hi all
We use JDeveloper Studio Edition Version 12.1.3.0.0 and deployed on GlassFish Server Open Source Edition 3.1.2.2 (build 5) and connect to the SQLServer database.
How to get the selected line in a programmatic (using a SortableModel custom not a display object) ADF table (generated from a bean)?
We are trying to get the selected row in a bean of a programmatic ADF table to retrieve data based on the selected line.
Any idea?
Well, you can use selectionListener to set the selected line to a variable of bean (but this bean must be in extended view or some superiors)
Something like this: http://www.awasthiashish.com/2015/07/get-selected-row-singlemultiple-from.html
Dario
-
How to select a random line with update?
Hello
I have a package to assign a number at random and reusable (ID) that is not currently in use - a procedure.
I'm trying to simulate a set of numbers (IDs) using a table that has a column ID and IS_USED.
How to:
The update is to lock the line to be picked up by another process calling the package.select a random ID (random row) from pool_table where IS_USED is 0 (not taken) FOR UPDATE
GOLD:
I can simulate a set of numbers with another object (not a table)?
I need the numbers to be consistent between sessions (as well as package variables do not work) and only a single session using the same code at any time. When it finishes the number becomes available to the other races.
Thank you.
Published by: Pyrocks on November 7, 2010 10:45I completely forgot to SKIP LOCKED. You need not a sequence. Try:
declare cursor pool_cur is select * from ( select * from pool_tbl order by round(dbms_random.value(1,cycle_value)) ) for update skip locked; id_to_use number; begin while id_to_use is null loop for rec in pool_cur loop id_to_use := rec.id; exit; end loop; end loop; end; /
SY.
-
How to select a record in one table to manipulate data in a database?
Hello community,
Using 32-bit Labview 2015.
I created a user interface that runs a query and retrieves my table from a sql database.
I want to be able to manage only one record at a time by selecting the record in my table and then manipulate the data according to the needs.
Whenever the user runs a query, I want as the first record in the table to be selected / highlighted.
I want an indicator that is currently active.
Then a click of a button, to be able to scroll the actively selected record.
Once I have the selected record, I want a way to write a query to edit or delete the record.
Is attached a photo of my query to select all of my table and connect data in my table (results).
Attached a photo of my painting showing the timeline of my sql database.
What is the best way to go on a record selection in a table and the modification of data with a query?
Any help would be greatly appreciated.
Thank you
I guess that's not a table, but multi-column listbox.
Right click, select--> highlight whole line selection Mode
The value of the multicolumn listbox is the row index - you can write a local variable to highlight the line, the event structure to handle the user clicking on, etc.
If you enable the property editable ListBox cells, you can allow users to edit the items of the listbox.
If you want to get the data in row, you hint REF table and work with the array of strings in row - convert it to cluster, etc..
I don't know, what type of data, it is, how you structure the database looks like, I don't even know if you use the wrapper to work with the database, I can't write queries for you.
Something like Update Tablica Set Serial = '5' where ID = '22';
-
How to select rows whose column contains specific characters?
It is a telling of the T1 table with say column C1
Either the C1 field values:
1st row) OF/SPT/A/FWD
line 2) G/SPT/DE/OF/SPT
rank 3) R/FWD/SPT/A/FWD/FWD
rank 4) A/A/OF/SPT/FWD
rank 5) FWD/SPT/E/OF/A
How to get only the lines whose C1 column contains FWD last?We can solve this problem with the simple use of a wildcard character:
select * from t1 where c1 like '%FWD' /
Note that this query runs a full table scan, because any index you can have on C1 will be ignored: the indexes are organized on the main characters.
Cheers, APC
-
How to select rows as some passes?
Hi all
11.2.0.1
I have two tables
Emp1 (name1) contain values:
=================
Justin bieber peralta
Bruno March minoza
EMP2 (name2) contain values:
=============
Bieber
March
I want to choose emp1 name1 where name1 like ' % | name2. %' of emp2.
I'm confused about the syntax
Thank you
pK
Select e1.*
from emp1 e1
emp2 e2
where e1.name1 like '% "| E2.name2 | '%'
Ery Plan
Operation Options Object Rows Time Cost Bytes Filter
Predicates *access
PredicatesSELECT STATEMENT31 015 1 796 527 255 NESTED LOOPS
31 015 1 796 527 255 ACCESS TABLE
STORAGE FULL EMP2 8 1 4 40 ACCESS TABLE
STORAGE FULL EMP1 3 877 1 99 46 524 'E1 '. "' NAME1 ' LIKE '%" | ' ' E2 '. "' NAME2 ' | " %' 'E1 '. "' NAME1 ' LIKE '%" | ' ' E2 '. "' NAME2 ' | " %' Columns not indexed are marked in red
Columns in index
Not found indexColumns in the table
Table Owner Table Name Column Name Data Type ETBIN EMP1 NAME1 VARCHAR2 EMP2 NAME2 VARCHAR2 Select *.
from emp1
where exists (select 1 from emp2 where emp1.name1 like '%' | name2 |) '%')
Query plan
Operation Options Object Rows Time Cost Bytes Filter
Predicates *Access
PredicatesSELECT STATEMENT32 13 9 850 384 FILTER
THERE ARE (SELECT "EMP2" 0 'EMP2' WHERE: B1 LIKE '%' |) "' NAME2 ' | " %') ACCESS TABLE
STORAGE FULL EMP1 77 537 1 101 930 444 ACCESS TABLE
STORAGE FULL RANKS FIRST EMP2 1 1 4 5 : B1 LIKE "%" | "' NAME2 ' | " %' Columns not indexed are marked in red
bars
Not found indexColumns in the table
Table Owner Table Name Column Name Data Type ETBIN EMP1 NAME1 VARCHAR2 EMP2 NAME2 VARCHAR2 Select *.
from emp1
where to trim (substr (name1,
InStr (name1,' ', 1, 1) + 1.
InStr (name1,' ', 1, 1)-instr (name1,' ', 1, 1)
)
) in select (separate name2
from emp2
)
Query plan
Query plan
Operation Options Object Rows Time Cost Bytes Filter
Predicates *Access
PredicatesSELECT STATEMENT77 537 1 109 1 318 129 HASH JOIN
77 537 1 109 1 318 129 'NAME2' = TRIM (SUBSTR ('NAME1', INSTR ("NAME1",' ', 1, 1) + 1, INSTR ('NAME1',' ',(-1), 1)-INSTR ("NAME1", "", 1.1))) VIEW
VW_NSO_1 2 1 5 10 HASH
UNIQUE 2 1 5 10 ACCESS TABLE
STORAGE FULL EMP2 8 1 4 40 ACCESS TABLE
STORAGE FULL EMP1 77 537 1 101 930 444 Columns not indexed are marked in red
Ndex columns
Not found indexColumns in the table
Table Owner Table Name Column Name Data Type ETBIN EMP1 NAME1 VARCHAR2 EMP2 NAME2 VARCHAR2 According to very different plans, it must be a difference any.
(ascheffer posted before cardinalities were known)
Concerning
Etbin
-
How to select an image in a table for direct view DW 20141
can someone explain to me how do I choose an image inside a table element, so I can apply css to it?
I already tried application css class and ID in vain.
I can select all other elements inside the table, except the picture. Why would it be?
Once a post is replied to, you can no longer change it. But if you need to edit your post before anyone answered, you will find under Actions under your message.
Nancy O.
-
(CS3; JavaScript) how effectively "select all" / performing an action
Hi all
while I found little code to run applescript action I need to be able to do from JavaScript. The documentation does not mention at all of the shares.
It would save me a lot of work if I could just perform an action that changes the color of the document to CMYK instead of having to duplicate all objects in a new document (I have already created the action and it works)
This brings me to my other question: are there really no "select all"? It takes almost 2 seconds (at least if the Profiler is right) just to select a simple 300 objects in my test file. I need to batch process something like 30 records that could prove more complex and I don't like the idea to say to my colleagues that they should wait for so long...
Is there a better way that a loop through pageItems and setting .selected = true?
I could imagine performs an action that selects all objects (how to copy actions to others machines. btw?) or to run the shortcut (Ctrl + a).
Thank you very much
Mike
Good evening
Void test_ai()
Set myAi = CreateObject ("illustrator.application.CS4")
Set myDocAi = myAi.ActiveDocument' - An idea is to show, as a first step, the layers on which you want to select all objects.
myDocAi.Layers ("myLayerWithObjects"). Visible = True
myDocAi.ActiveLayer.Locked = FalsemyDocAi.Layers ("mySecondLayerWithObjects"). Visible = True
myDocAi.ActiveLayer.Locked = False' - In a second step, you select all
For each myLayers in myDocAi.Layers
If myLayers.Visible = True Then myLayers.HasSelectedArtwork = True
Next' - and finally, you define a variable with your selection
myselexion = myAi.Selection
End Sub
After that, you will probably identify each item of your choice.
Best regards
Patrice
-
How do I get the selected row in the table (FacesCtrlHierBinding).
I am trying to get the data of the selected row in the table:
RowBinding () (FacesCtrlHierBinding) tab.getSelectedRow = FacesCtrlHierBinding;
Line rw = rowBinding.getRow ();
But for oracle.adfinternal.view.faces.model.binding.FacesCtrlHierBinding be found since my 11 JDev to import.
What is a good package for FacesCtrlHierBinding?Hello
This is the code I use to get the selected rows in a rich table of adf:public void deleteMarkedRows() { RichTable table = this.getImportTable(); //get table bound to UI Table RowKeySet rowKeys = table.getSelectedRowKeys(); Iterator selection = table.getSelectedRowKeys().iterator(); while (selection.hasNext()) { Object key = selection.next(); table.setRowKey(key); Object o = table.getRowData(); JUCtrlHierNodeBinding rowData = (JUCtrlHierNodeBinding) o; Row row = rowData.getRow(); row.remove(); } //prepare table to show changes table.setFirst(0); RequestContext.getCurrentInstance().addPartialTarget(table); }
Hope this helps
Timo
-
How to select the lines/odd table...
How to select lines / odd in a table?
Help, please.
Published by: vaibhav on May 7, 2012 05:30This can be done by using the function mod like this:
For even rows
Select * from (select rownum rn, nom_table.* from tableName) where mod (rn, 2) = 0;For the odd lines
Select * from (select rownum rn, nom_table.* from tableName) where mod (rn, 2) = 1; -
How to create the column of the table for long-form Master detail relationship
Apex 4.1
Oracle 11g
I created a form master detail and see the main table hotel_list and table hotel_mapping as detailed below.
Hotel_list
ID HOTEL_NAME
1 Holiday Inn
Hotel Hilton 2
Hotel_mapping
ID HOTEL_NAME MAPPING_NAME
1 Inn Holiday Inn Select hotel
2 holiday hotel Holiday Inn Select
3 hotel Holiday Inn Holiday Inn Hotel
4 Hilton Hotel Hilton Hotel chain
Hotel Hilton 5 HiltonHotel
Table Hotel_name Hotel_list is a linked table Hotel_mapping
When I add a line to the Hotel_mapping table for the selected row in the hotel_list table, mapping_name of column is null, therefore impossible to create the relationship between the main table and the secondary table.
I would like to know, how to create the relationship?
Thank you very much
Best regards
Yong Huang,
simple step see creating a form detailed master with APEX - Assistant Master retail
and check how to maintain the relationship between two tables,
simple return the packaged application «Sample of Masters details»
and try to understand this concept...
In your example, use Hotel_list.ID as a foreign key in the table Hotel_mapping
and maintain the relationship with the column ID...
and choose the display type of the column Hotel_list.ID in table Hotel_mapping as List(Query Based LOV) select.
otherwise the best way is to create sample on oracle.apex.com
I hope this helps...
Leave.
-
Insert rows checked in the table
Hi all
How to insert rows checked in another table. I've created an interactive report with the query as follows
Select apex_item.checkbox(1,id,'unchecked') ", Column1, Column2 from table. Now when I check the boxes to check off and hit the Insert button it should get stored in another table in DB (table1).
Process:
DECLARE
IDX number;
BEGIN
BECAUSE me in 1.APEX_APPLICATION. G_F01. COUNTY
LOOP
IDX: = apex_application. G_F01 (i);
Insert into step3_table (ID, TASK_NAME, TASK_DESCRIPTION, CATEGORY, TASK_INFO, TASK_STATUS, TO_WORKGROUP, IMPACT, FILE)
values (apex_application. G_F02 (idx), apex_application. G_F03 (idx), apex_application. G_F04 (idx), apex_application. G_F05 (idx), apex_application. G_F06 (idx), apex_application. G_F07 (idx), apex_application. G_F08 (idx), apex_application. G_F09 (idx), apex_application. G_F10 (idx));
END LOOP;
END;
Thanks for the help!Hello
You don't have a F02 - F04 berries in your query.
Even you, your insert statement do not have enough source columns.
Also I do not know you could get all the data tables in this way... table F01 value maybe not array index value.Try
BEGIN FOR i in 1..APEX_APPLICATION.G_F01.COUNT LOOP INSERT INTO step3_table (ID,TASK_NAME,TASK_DESCRIPTION,CATEGORY,TASK_INFO,TASK_STATUS,TO_WORKGROUP,IMPACT,FOLDER) SELECT id,column2,column2,column3,column4,column5,column6,column7,column8 FROM table WHERE id = apex_application.G_F01(i) ; END LOOP; END;
Kind regards
Jari -
ADF Table how to change the color Selected row in the array unfocuse.
Hi all
I have a requirment where I select the row of the table ADF and unfocuse on the table.
According to the framework it gives me the light yellow color.
How can I change this color with another color.
Pls suggest.
Thanks to Advans
Barry Mucheli.
Hello, Barry Mucheli.
To change the color of the selected row when it loses focus, add the following code in your skin css file.
AF | : the table-row data: selected: inactive af | : the column cell data
{
background-color: Green;
}
RFH.
Maybe you are looking for
-
A new tab opens whenever I open firefox in addition to the homepage, I want to get rid of this page of tile in total. There is no gear icon click on in the upper right corner of the page
-
Get a pop up message saying that I have a Firefox security problem
I started to receive messages pop up saying that my Firefox browser has a problem of serious security and for me to give a phone number.!. It is a real message of Mozilla, or is it a phishing message?2 should Whtat action I take in the future?
-
But Bluetooth does not work on Realtek RTL8188CEB8 on Pavilion g7-2275dx
My G7 did not support the bluetooth so I got half of the bgn/bluetooth mini-pci Realtek card and installed. I installed the drivers from the web site of Realtek for Windows 8. The adapter works for wifi, fine and in the Device Manager, the generic
-
Qosmio F60 - 10K: Win 7 64 bit recognizes all the devices connected to the USB
Hello I have a problem. I do not know this first run my Toshiba which was before 6 months or since...Some USB are recognized some are not, but many not a few USB are recognized I mean on USB, External hard drive USB too. I have 2 USB hard drive is re
-
HP laptop - 15-ac110na: is it possible to upgrade the processor?
Hi I was wondering if it would be possible to upgrade the CPU on my laptop. It's a HP for laptop - 15-ac110na (ENERGY STAR). It is the CPU Intel(r) Pentium (r) CPU 3825U 1.90 GHz but I would exceed 3.0 GHz. If this is possible, is - could anyone reco