How to find Similar rows?
Dear All,
I have table with location data , which having around 2 million records, So performance is
huge factor. Please see the table structure
sl
Street
City
Zip code
state
Country
longitude
latitude
Mvalue
Logic 1
logic 2
Logic 3
1
2
3
4
5
6
I want do compare this location with following logic...
1) First comparing street name , city ,zip ,state & country
( Update logic1 as 1
2) by geographical co-ordinate ( if distance between the location
50 meter , update logic 2 as 1)
3) Based on Mvalue ( if difference between the Mvalue
less than 10% , update logic 3 as
1)
-Sajid
Hello,
Did you compare records in the table by join another table, or you want to compare the adjacent rows in the same table with inner join or compare all rows with cross join?
Supposing that you want to compare the adjacent rows order by the "SL" column, You can refer to the following statement to update the column "logic1":
UPDATE compare
SET logic1= CASE
WHEN EXISTS(
SELECT 1 FROM compare c1 INNER JOIN compare c2 ON c1.sl=c2.cl-1
WHERE c1.street=c2.street AND c1.city=c2.city AND c1.[zip code]=c2.[zip code] AND c1.state=c2.state AND c1.country=c2.country)
THEN 1
ELSE NULL
END
If I have any misunderstanding, please post more details for further analysis.
Regards,
Fanny Liu
If you have any feedback on our support, please click here.
Fanny Liu
TechNet Community Support
Similar Messages
-
How to find duplicate row in sql query?
Hi All,
Please solve my query, find duplicate row and how to count its. your suggestion would be greatly appreciated.You can use group by and having.
SQL> WITH t
2 AS (SELECT LEVEL id
3 FROM DUAL
4 CONNECT BY LEVEL <= 5
5 UNION ALL
6 SELECT LEVEL + 2
7 FROM DUAL
8 CONNECT BY LEVEL <= 3)
9 SELECT *
10 FROM t;
ID
1
2
3
4
5
3
4
5
8 rows selected.
SQL> WITH t
2 AS (SELECT LEVEL id
3 FROM DUAL
4 CONNECT BY LEVEL <= 5
5 UNION ALL
6 SELECT LEVEL + 2
7 FROM DUAL
8 CONNECT BY LEVEL <= 3)
9 SELECT id, COUNT (*)
10 FROM t
11 GROUP BY id
12 HAVING COUNT (*) > 1;
ID COUNT(*)
3 2
4 2
5 2
SQL> -
How to find Tuple(row) size in a Data Block
hi,
I want to find out the size of 1 row and total size of a table in a data block in Oracle 11g. For Example I've a Employee table with 300 rows. I want to find out how much space these rows are occupying in a data block (8192 default) and also the size of 1 individual row.
I'll appreciate the valuable suggestions.
Thanks alot.
Regards,
KamranHi,
Welcome to the forum!
See [Calculating Oracle average row length|http://www.dba-oracle.com/t_average_row_length.htm], I hope it helps
Regards, -
How to find selected rows in REUSE_ALV_GRID_DISPLAY
HEllo All,
In OO we have a method to find get_selected_rows but i am unable to what is the way to find selected rows in REUSE_ALV_GRID_DISPLAY.
I am able to find a single row but i have to find multiple cleans in ALV. How can i do this.
Please help me with some ideas or please post some sample codes.
Regards,
LisaHi,
Check this code..
REPORT zdayatest1.
TABLES :t247.
TYPE-POOLS slis. "Type definitions for alv report
TYPES: BEGIN OF ty_func_tab,
fcode TYPE rsmpe-func,
END OF ty_func_tab.
DATA: it_fieldcat TYPE lvc_t_fcat,
wa_fieldcat TYPE lvc_s_fcat.
DATA: is_lvc_s_glay TYPE lvc_s_glay.
DATA: wa_layout TYPE lvc_s_layo.
DATA: is_rxtab TYPE ty_func_tab.
DATA: BEGIN OF it_final OCCURS 0,
check(1),
mnr LIKE t247-mnr,
ltx LIKE t247-ltx,
END OF it_final.
DATA: wa_final LIKE it_final.
DATA: w_repid LIKE sy-repid.
START-OF-SELECTION.
w_repid = sy-repid.
REFRESH it_final.
SELECT mnr ltx
FROM t247
INTO CORRESPONDING FIELDS OF TABLE it_final
WHERE spras EQ 'E'.
wa_fieldcat-fieldname = 'CHECK'.
wa_fieldcat-tabname = 'IT_FINAL'.
wa_fieldcat-checkbox = 'X'.
wa_fieldcat-edit = 'X'.
wa_fieldcat-outputlen = '3'.
wa_fieldcat-col_pos = '1'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'MNR'.
wa_fieldcat-tabname = 'IT_FINAL'.
wa_fieldcat-outputlen = '8'.
wa_fieldcat-col_pos = '2'.
wa_fieldcat-coltext = 'Month'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'LTX'.
wa_fieldcat-tabname = 'IT_FINAL'.
wa_fieldcat-outputlen = '20'.
wa_fieldcat-col_pos = '3'.
wa_fieldcat-coltext = 'Month Desc'.
APPEND wa_fieldcat TO it_fieldcat.
CLEAR wa_fieldcat.
wa_layout-zebra = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = w_repid
i_callback_pf_status_set = 'SUB_PF_STATUS'
i_callback_user_command = 'USER_COMMAND'
i_grid_title = 'TESTING'
is_layout_lvc = wa_layout
it_fieldcat_lvc = it_fieldcat
TABLES
t_outtab = it_final
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*& Form USER_COMMAND
FORM user_command USING ucomm LIKE sy-ucomm
selfield TYPE slis_selfield.
IF selfield-fieldname = 'CHECK'.
DATA ref1 TYPE REF TO cl_gui_alv_grid.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = ref1.
CALL METHOD ref1->check_changed_data.
LOOP AT it_final WHERE check = 'X'.
IF it_final-check IS INITIAL.
it_final-check = 'X'.
ELSE.
CLEAR it_final-check.
ENDIF.
MODIFY it_final.
ENDLOOP.
selfield-refresh = 'X'.
ENDIF.
ENDFORM. "USER_COMMAND
*& Form sub_pf_status
* text
* -->RT_EXTAB text
FORM sub_pf_status USING rt_extab TYPE slis_t_extab. "#EC CALLED
CLEAR is_rxtab.
is_rxtab-fcode = 'TEST'.
APPEND is_rxtab TO rt_extab.
SET PF-STATUS 'PF_STATUS' ."EXCLUDING rt_extab.
ENDFORM. "sub_pf_status -
How to find last row in itab?
hi experts,
How to find the last row or item in an itab.I am using if statement for which i have to check the last row and if it is the last row some set of statements should trigger.
thanks
maniJust, find the last record :
* Standard table
DESCRIBE TABLE itab LINES n.
READ TABLE itab INDEX n.
Check on the table with special work at last record :
* Loop
LOOP AT itab.
MOVE itab TO wa_itab.
AT LAST.
* here wa_itab is the last record (itab is *****)
ENDAT.
ENDLOOP.
Regards -
How to find middle row in a table ?
Hi Friends,
Is it possible to find middle row in a table by SQL Query.
KarTiK.Solution: sort the rows in order to create an ordered
sequence and then there will be a "middle row".Well, not quite.
If there are an odd number of rows then, yes, there will be a middle row in an ordered sequence, however if there is an even number of rows then the middle is between two rows... or... you could take it as the two rows either side of the middle....
SQL> select * from emp order by empno;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17/12/1980 00:00:00 800 20
7499 ALLEN SALESMAN 7698 20/02/1981 00:00:00 1600 300 30
7521 WARD SALESMAN 7698 22/02/1981 00:00:00 1250 500 30
7566 JONES MANAGER 7839 02/04/1981 00:00:00 2975 20
7654 MARTIN SALESMAN 7698 28/09/1981 00:00:00 1250 1400 30
7698 BLAKE MANAGER 7839 01/05/1981 00:00:00 2850 30
7782 CLARK MANAGER 7839 09/06/1981 00:00:00 2450 10
7788 SCOTT ANALYST 7566 19/04/1987 00:00:00 3000 20
7839 KING PRESIDENT 17/11/1981 00:00:00 5000 10
7844 TURNER SALESMAN 7698 08/09/1981 00:00:00 1500 0 30
7876 ADAMS CLERK 7788 23/05/1987 00:00:00 1100 20
7900 JAMES CLERK 7698 03/12/1981 00:00:00 950 30
7902 FORD ANALYST 7566 03/12/1981 00:00:00 3000 20
7934 MILLER CLERK 7782 23/01/1982 00:00:00 1300 10
14 rows selected.
SQL> select e.empno, e.ename, e.job, e.mgr, e.hiredate, e.sal, e.comm, e.deptno
2 from (select emp.*, row_number() over (order by empno) as rn from emp) e
3 ,(select round(count(*)/2) as middle, round(((count(*)+1)/2)) as middle2 from emp) m
4 where e.rn in (m.middle, m.middle2)
5 /
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7782 CLARK MANAGER 7839 09/06/1981 00:00:00 2450 10
7788 SCOTT ANALYST 7566 19/04/1987 00:00:00 3000 20
SQL> insert into emp values (1111, 'WILLIS', 'CLERK', 7902, sysdate, 900, null, 20);
1 row created.
SQL> select * from emp order by empno;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
1111 WILLIS CLERK 7902 18/01/2008 12:18:14 900 20
7369 SMITH CLERK 7902 17/12/1980 00:00:00 800 20
7499 ALLEN SALESMAN 7698 20/02/1981 00:00:00 1600 300 30
7521 WARD SALESMAN 7698 22/02/1981 00:00:00 1250 500 30
7566 JONES MANAGER 7839 02/04/1981 00:00:00 2975 20
7654 MARTIN SALESMAN 7698 28/09/1981 00:00:00 1250 1400 30
7698 BLAKE MANAGER 7839 01/05/1981 00:00:00 2850 30
7782 CLARK MANAGER 7839 09/06/1981 00:00:00 2450 10
7788 SCOTT ANALYST 7566 19/04/1987 00:00:00 3000 20
7839 KING PRESIDENT 17/11/1981 00:00:00 5000 10
7844 TURNER SALESMAN 7698 08/09/1981 00:00:00 1500 0 30
7876 ADAMS CLERK 7788 23/05/1987 00:00:00 1100 20
7900 JAMES CLERK 7698 03/12/1981 00:00:00 950 30
7902 FORD ANALYST 7566 03/12/1981 00:00:00 3000 20
7934 MILLER CLERK 7782 23/01/1982 00:00:00 1300 10
15 rows selected.
SQL> select e.empno, e.ename, e.job, e.mgr, e.hiredate, e.sal, e.comm, e.deptno
2 from (select emp.*, row_number() over (order by empno) as rn from emp) e
3 ,(select round(count(*)/2) as middle, round(((count(*)+1)/2)) as middle2 from emp) m
4 where e.rn in (m.middle, m.middle2)
5 /
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7782 CLARK MANAGER 7839 09/06/1981 00:00:00 2450 10
SQL> -
How to find out row that was clicked in DataTable?
Hi there,
i have a dataTable component which renders a list from database. In the last column of this table you can click a link for further processing for this row.
How to identify which row was clicked?
<f:view>
<h3>Subtitel</h3>
<h:form>
<h:dataTable headerClass="tableheader"
var="list"
value="#{Uebersicht.uebersichtsliste}">
<h:column>
<f:facet name="header">
<f:verbatim>KW</f:verbatim>
</f:facet>
<h:outputText value="#{list.cal.kw}" />
</h:column>
<h:column >
<f:facet name="header">
<f:verbatim>Bemerkung</f:verbatim>
</f:facet>
<h:outputText value="#{list.cal.feiertagNat}" />
</h:column>
<h:column >
<f:facet name="header">
<f:verbatim>Start</f:verbatim>
</f:facet>
<h:commandLink action="#{Uebersicht.start}" value="setzen"/>
</h:column>
</h:dataTable>
</h:form>
</f:view>How to identify the row to process in action methed "uebersicht.start"?
Regards,
akthe easiest way is you can send the parameters for the command link and the
output link.this parameters will be the unique id of the rows ur r populating .
get those parameters by:
request.getParameter(keep the id u kept in the parameters list);
I worked it out before ,its perfect.
regards,
raju reddy -
PSE 4.0: How to find similar photos amongst thousands of photos
I'm looking for a method to find similar (for instance duplicated) photos, amongst my 7000 photos. I have PSE 4.0, and it looks like only 4 photos can be specified. I do not want to specify any number.
Do I have to use another programme, like ImageDupeless, PhotoSort etc? Or does PSE 5.0 handle this better? Or ... is there something I haven't understood?Yes, I could probably do that, if I checked the names as well.
In a way, I have solved the problem by using the try out version of ImageDupeless (It found 81 photos, and I deleted 79 of those. Only about 20 had the same name and size.)
But I would prefer to use PSE. Its better to delete pictures in PSE, as well. If PSE 4.0 / 5.0 don't have things like this, I guess I would buy ImageDupeless (or another programme). -
How to find the row being deleted in a Tabular Form?
version 3.2.1
How do I find out what row is being deleted in a Tabular Form (SQL Query (updateable report) )?
I have a process to delete records from another table when the record in the report is deleted. I need to capture the primary key to pass to the process that deletes the record from the other table.
Thanks,
JoeHm,
The best thing is to do this using triggers before delete. Looping through the list of checked checkboxes is not an optimal solution. If the standard MRD process fails for whatever reason, your delete process for the rows in the other table will still delte the records with the selected primary key.
Denes Kubicek
http://deneskubicek.blogspot.com/
http://www.opal-consulting.de/training
http://apex.oracle.com/pls/otn/f?p=31517:1
http://www.amazon.de/Oracle-APEX-XE-Praxis/dp/3826655494
------------------------------------------------------------------- -
Oracle tuning: How to find percentage rows being accessed from a table
Oracle recommends that full table scan on a large table is good if the number of rows being accessed is more than 20%. My question is how to I find out how many rows of the table is being accessed if I have a complex SQL which involves 10 other tables.
Hi,
there are two approaches to SQL tuning. One is to list all things that could possibly be wrong with the database, search for typical solutions, and try them all one by one.
The other is to find out what is taking all the time and work on it.
As I'm sure you've already figured by now, the first approach is unreliable, error-prone, inefficient. In one word, wrong. The only reason it's still around is because:
1) 10 years ago Oracle diagnostic tools weren't as advanced as they are now,
2) some people never learn
3) there's no way to stop these people from writing stupid things on the internet.
So forget all about these unreset HWM, low ratios and other dreadful things that could be wrong with your database code, and focus on things that are wrong. Follow instructions in this forum's FAQ to find the root cause of the problem (if you have questions along the way, post them here, we'd be happy to help). If this leads you to HWM, then fix it. If it doesn't, don't waste your time on it.
Best regards,
Nikolay -
How to find rejected rows using External Table
Hi all,
I had written a stored procedure to read comma(,) separated flat file using External Tables in oracle 9i with Reject Limit "Unlimited" Option. Sometimes all rows are successfully loaded into external table and sometimes some rows are failed, I can find out those rows from logfile created by oracle. I want to inserted those rows key values into some other table. Can any body suggest/links how to write this.
Thanking you in advance"Is there a way to have the system truncate the log files besides some O/S utility that will scour the directory every night, week, etc.?"
You can use UTL_FILE.FREMOVE to delete the file, if you have sufficient privileges. You can schedule it using DBMS_JOB if you like or run it before you recreate the file, as demonstrated below. The pl/sql block to check whether the file exists is used for demonstration purposes only and is not necessary. This is just one method. There are various ways to delete or truncate a file. This just seems like the simplest.
scott@ORA92> CREATE OR REPLACE DIRECTORY mydir AS 'c:\oracle'
2 /
Directory created.
scott@ORA92> DECLARE
2 v_bfile BFILE := BFILENAME ('MY_DIR', 'test_tab.log');
3 BEGIN
4 IF DBMS_LOB.FILEEXISTS (v_bfile) = 1
5 THEN DBMS_OUTPUT.PUT_LINE ('test_tab.log exists');
6 ELSE DBMS_OUTPUT.PUT_line ('test_tab.log does not exist');
7 END IF;
8 END;
9 /
test_tab.log exists
PL/SQL procedure successfully completed.
scott@ORA92> EXECUTE UTL_FILE.FREMOVE ('MY_DIR', 'test_tab.log')
PL/SQL procedure successfully completed.
scott@ORA92> DECLARE
2 v_bfile BFILE := BFILENAME ('MY_DIR', 'test_tab.log');
3 BEGIN
4 IF DBMS_LOB.FILEEXISTS (v_bfile) = 1
5 THEN DBMS_OUTPUT.PUT_LINE ('test_tab.log exists');
6 ELSE DBMS_OUTPUT.PUT_line ('test_tab.log does not exist');
7 END IF;
8 END;
9 /
test_tab.log does not exist
PL/SQL procedure successfully completed.
scott@ORA92> CREATE TABLE test_tab
2 (col1 NUMBER,
3 col2 VARCHAR2(4))
4 ORGANIZATION external
5 (TYPE ORACLE_LOADER
6 DEFAULT DIRECTORY mydir
7 ACCESS PARAMETERS
8 (RECORDS DELIMITED BY NEWLINE
9 BADFILE 'MYDIR':'test_bad.bad'
10 LOGFILE 'MYDIR':'test_tab.log'
11 FIELDS TERMINATED BY ","
12 (col1,
13 col2))
14 LOCATION ('test.dat'))
15 REJECT LIMIT UNLIMITED
16 /
Table created.
scott@ORA92> SELECT * FROM test_tab
2 /
COL1 COL2
1 a
2 b
scott@ORA92> "Or is there a way to prevent the log from being written to every time it's accessed?"
You can use NOLOGFILE as an access parameter to prevent it from being written to, as shown below.
scott@ORA92> CREATE OR REPLACE DIRECTORY mydir AS 'c:\oracle'
2 /
Directory created.
scott@ORA92> CREATE TABLE test_tab
2 (col1 NUMBER,
3 col2 VARCHAR2(4))
4 ORGANIZATION external
5 (TYPE ORACLE_LOADER
6 DEFAULT DIRECTORY mydir
7 ACCESS PARAMETERS
8 (RECORDS DELIMITED BY NEWLINE
9 BADFILE 'MYDIR':'test_bad.bad'
10 NOLOGFILE
11 FIELDS TERMINATED BY ","
12 (col1,
13 col2))
14 LOCATION ('test.dat'))
15 REJECT LIMIT UNLIMITED
16 /
Table created.
scott@ORA92> SELECT * FROM test_tab
2 /
COL1 COL2
1 a
2 b
scott@ORA92> "Is there a way to have the log written only when an error occurs?"
Not that I know of, but that does not mean that somebody else doesn't know how or isn't able to figure out a way. If you do find a way, please post it for the benefit of the rest of us. -
I create VO, EO, AM. I create a form based on VO. It shows the data of the first row. How to set the AM that the form can shows a specific row?
For example, after adding some code (set getting the 5th row) in AM, the form can show the data of the 5th row.
Can I do that? If I can, how to write the code? Please past the detail steps, code sample and tutorial address.
Thanks a lot.this might help
*028. How-to scroll an ADF bound ADF Faces Table using a Keyboard Shortcut*
http://www.oracle.com/technetwork/developer-tools/adf/learnmore/index-101235.html -
How to find different rows in two tables which have same schema.
There are two tables t1 and t2, they have same schema. Table t1 includes the informtion of students last month,table t2 incude the information of the students this month. I want to find the difference of the same student between two months. What should I do and How to do?
Look a the following example:
Table TEST_1 TEST_2
ID ID_TX ID ID_TX
1 a 1 a
2 b 2 b
4 d 4 d
6 f 6 f
7 g 7 g
10 j 10 j
10 Z 10 x --- DIFFERENT
12 x --- DIFFERENT
20 x ---- DIFFERENT
Query:
Select * FROM
( (SELECT '1', ID, ID_TXT FROM TEST_1 MINUS SELECT '1', ID, ID_TXT FROM TEST_2)
UNION
(SELECT '2', ID, ID_TXT FROM TEST_2 MINUS SELECT '2', ID, ID_TXT FROM TEST_1) )
Order By ID
RESULTS:
' ID ID_TXT
1 10 Z
2 10 x
1 12 x
2 20 x -
How To Find Last Row With Data +2, Then Format?
I need to find the last row +2, select the range A:L, then format.
Could someone please supply the code? I can handle the format part.
Thanks!
A. WolfWorks great!
I need to do 2 other things:
1) Add a text value to r in A: & center over selection A:L
Dim r As Long
r = Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
USED THIS BUT ENDING UP IN MIDDLE OF L:!
ActiveCell = Range("A" & r)
ActiveCell.Value = "Estimated True Up Total"
2) 2) Format a total in r as currency/2 decimels/aligned to right.
THANKS AGAIN!!!
A. Wolf -
How to find Random Row using SQL
In Scott.emp table (oracle default) there are fourteen rows
I want to select employee with salary at second (eg if 2000, 3000, 5000, 2500 )
then second no salary is 3000.?Re: how we select 3 rd max salary from given salaries
But.....
How the title is related to the topic ?
Maybe you are looking for
-
Visual Composer 7.0 - Change the Y-axis from decimal scale to integer
Hi Experts, I'm new in Visual Composer 7.0, my report is work fine, but when I want to show the data in bar-chart, the values on y-axis are 0.0, 0.4.0.8,1.2,1.6.2.0 but i want like 1,2,3,4. Normally, this happen when values on y-axis less than 5, if
-
How can I get a Mac to redo the new machine setup?
Hey gang- Is there a way to get a Mac to redo the new machine setup dialogs the way a Mac does the first time it is started out of the box? I'm selling my iBook and it would be nice for the new owner to be presented with that. I know I could do it by
-
Modifying Existing css of a theme
Hi I connected to http://127.0.0.1:8080/images/themes/theme_1/css then copied the theme_4_0.css ...made some changes and again copied back the modified css in http://127.0.0.1:8080/images/themes/theme_1/css. but now when i switch theme, there is no c
-
Why is the log larger than the normal mdf file
I have SAP installation that has a log that is more than ten times larger than the normal mdf file. This rapid growth happen in the past year. running 8.81
-
How to recover when Delta Queues have been emptied by error ?
Hi All, Here is our problem : the ECC Delta Qs have been emptied by error some days ago, and for the moment we have frozen every BW updates from ECC, but the Delta Queues have been being filled in ECC since that. We have so smart ideas so far... Thx