Compare two rows in same table
Hi,
I want to compare two rows (some columns) in the same table, and if the data in the data columns is different, I want to pick the latest one. The table is date tracked. For instance I have an address table with different addresses for an employee with effective date. I want to be able to pick the latest row if the postal code is different for the 2 rows. Is this possible in sql. I can do this in Pl/sql, but dont want to use it. Eg
address_id, postal_code, person_id,last_update_date
123, pn123,1,12-JAN-01
124,pu124,1,13-JAN-01
I want to be able to retrieve just the second line.
Any help is appreciated
Welcome to the forum!
Whenever you post please provide your 4 digit Oracle version (result of SELECT * FROM V$VERSION).
>
The table is date tracked. For instance I have an address table with different addresses for an employee with effective date. I want to be able to pick the latest row if the postal code is different for the 2 rows.
>
Your question is a little confusing because you are using terms like 'date tracked' and 'effective date' without explaining exactly what your definitions of those terms is.
Why do you want the latest record ONLY if the postal code is different? What if the address is different? Then which record do you want?
Why not just take the record for each person/company that has the latest date? If the data is the same then it doesn't which record you get so the one with the latest date will do. And if the data is different taking the one with the latest date gives you the latest data.
The classic definition of effective date is 'the date the information becomes effective'. Information with a given effective date is NOT in effect before that date and is SUPERCEDED when data is entered with a later effective date if the actual date is later than or equal to the effective date. Using your data
>
123, pn123,1,12-JAN-01
124,pu124,1,13-JAN-01
>
The first record IS NOT effective for dates prior to 12-JAN-01. In fact for a query looking for data prior to that date there isn't any data.
The first record is also NOT effective for dates on or after 13-JAN-01. Only the second record is effective.
If you added a record for 14-JAN-01 this record would not be effective until on or after that date (i.e. not for another 4 1/2 months).
So for the classic definition of effective date the query needs to provide the AS OF date to use to obtain the data. If, as in your system, you are not allowed to create records with dates in the future and you just want the latest record then you can just select the record with the MAX(myDate) value for the given person_id, address_id or whatever your key values are.
Edited by: rp0428 on Aug 11, 2012 7:50 AM
Similar Messages
-
Create ViewCriteria comparing two columns from same table
Does anyone know how I can create a ViewCriteria where clause that compares two columns from the same table?
For example if I had two integer columns (MINSAL and MAXSAL) and wanted to see if they are equal. I would normally do the following SQL below.
SELECT * FROM EMPL
WHERE MINSAL = MAXSALIt works, but it is not ideal.
Setup a Transient column that performs a groovy evaluation of MINSAL=MAXSAL and then my ViewCriteria evaluates the column to true and I set Query Execution Mode to Both. -
How to Concatenate two rows of same table
Hi Friends
I have table
No Name Id
1 Raju 6
2 Dhanshree 7
3 Shital 6
4 Priya 7
I want the query that should display
Raju Dhanshree.
Shital Priya
That Means whenever 6,7 number come the query should Concatenate The name colume1 150 IEEE TRANSA CTIONS ON MICR O W A V E THEOR Y AND TECHNIQ UES, V OL. 50, NO. 1, J ANU AR Y 2002
Times-Roman 4
2 A Miniaturized MMIC Analog Phase Shifter Using
Times-Roman 16
3 T w o Quarter-W a v e-Length T ransmission Lines
Times-Roman 16
4 Hitoshi Hayashi
Times-Roman 7
5 , Member , IEEE
Times-Italic 7
6 , T adao Nakaga w a
Times-Roman 7
7 , Member , IEEE
Times-Italic 7
8 , and Katsuhik o Araki
Times-Roman 7
9 Abstract—
Times-BoldItalic 6
10 This paper describes a miniaturized monolithic-mi-
Times-Bold 6
11 cr o w a v e integrated-cir cuit (MMIC) analog phase shifter using tw o
Times-Bold 6
12 quarter-wa v e-length transmission lines. A con v entional analog
Times-Bold 6
13 phase shifter employs an analog phase-shifter topology using a
Times-Bold 6
14 3-dB 90
Times-Bold 6
15 branch-line h ybrid r equiring f our quarter-wa v e-length
Times-Bold 6
16 transmission lines. Thus, in the f irst stage of our study , w e
Times-Bold 6
17 pr esent a new analog phase-shifter topology using only tw o
Times-Bold 6
18 quarter-wa v e-length transmission lines. The phase shifter her e
Times-Bold 6
19 has only one-half as many transmission lines as a con v entional
Times-Bold 6
20 analog phase shifter using a 3-dB 90
Times-Bold 6
21 branch-line h ybrid, and the
Times-Bold 6
22 cir cuit can be miniaturized to less than one-f ourth as compar ed to
Times-Bold 6
23 the con v entional analog phase shifter . Furthermor e, we sho w that
Times-Bold 6
24 the operating fr equency range of the phase shifter is v ery wide and
Times-Bold 6
25 can obtain lar ge phase v ariation with small capacitance v ariation.
Times-Bold 6
26 Next, an experimental
Times-Bold 6
27 -band MMIC analog phase shifter is
Times-Bold 6
28 pr esented. A phase shift of mor e than 180
Times-Bold 6
29 and an insertion loss
Times-Bold 6
30 of 3.6
Times-Bold 6
31 1.1 dB ar e obtained at the fr equency range fr om 12 to
Times-Bold 6
32 14 GHz. The chip size of the experimental MMIC phase shifter is
Times-Bold 6
33 less than 3.0 mm
Times-Bold 6
34
How will use on this data -
Compare two rows in a same table
Dear all
I need to compare two rows in the same table, I dont know hoe to do it in pl/sql. Some one please help me on this.
example:
tr br price
xya0001 ama7 12
xya0003 ama6 14
xya0004 ama7 16
in the table tr is a unique value for each row, I need to compare price column and see whether the first value is less or greater than the next value and, if it is greater put the corresponding br value to a variable and if it is smaller put the corresponding br value to another variable. I dont know a method to do it, as I'm new to pl/sql. Some one please help me in thisnot sure what you intend to do as you have mentioned that "TR" is unique and you just want to compare each record with just the next record. Hope below query helps. The value "G" or "L" in flag would indicate if the current records price is greater than or less than the price in next record.
select tr,br,price,col4, case when price> col4 then 'G' when price< col4 then 'L' end flag from (
select tr,br,price,lag(price,1,0) over(order by tr) col4 from testcomp
) -
How to compare two rows from two table with different data
how to compare two rows from two table with different data
e.g.
Table 1
ID DESC
1 aaa
2 bbb
3 ccc
Table 2
ID DESC
1 aaa
2 xxx
3 ccc
Result
2Create
table tab1(ID
int ,DE char(10))
Create
table tab2(ID
int ,DE char(10))
Insert
into tab1 Values
(1,'aaa')
Insert
into tab1 Values
(2,'bbb')
Insert
into tab1 Values(3,'ccc')
Insert
into tab1 Values(4,'dfe')
Insert
into tab2 Values
(1,'aaa')
Insert
into tab2 Values
(2,'xx')
Insert
into tab2 Values(3,'ccc')
Insert
into tab2 Values(6,'wdr')
SELECT
tab1.ID,tab2.ID
As T2 from tab1
FULL
join tab2 on tab1.ID
= tab2.ID
WHERE
BINARY_CHECKSUM(tab1.ID,tab1.DE)
<> BINARY_CHECKSUM(tab2.ID,tab2.DE)
OR tab1.ID
IS NULL
OR
tab2.ID IS
NULL
ID column considered as a primary Key
Apart from different record,Above query populate missing record in both tables.
Result Set
ID ID
2 2
4 NULL
NULL 6
ganeshk -
How to compare two rows in PL/SQL?
Hi All,
How to compare two rows in PL/SQL? Is there any method that I can use instead of comparing them column by column?
Any feedback would be highly appreciated.PhoenixBai wrote:
Hi All,
How to compare two rows in PL/SQL? Is there any method that I can use instead of comparing them column by column?What "rows" are you referring to?
If you're talking of rows within a PL/SQL associative array there are techniques as described in the documentation... e.g.
SQL> ed
Wrote file afiedt.buf
1 declare
2 type v1 is table of number;
3 r1 v1 := v1(1,2,4);
4 r2 v1 := v1(1,2,3);
5 begin
6 if r1 MULTISET EXCEPT DISTINCT r2 = v1() then
7 dbms_output.put_line('Same');
8 else
9 dbms_output.put_line('Different');
10 end if;
11* end;
SQL> /
Different
PL/SQL procedure successfully completed.
SQL> ed
Wrote file afiedt.buf
1 declare
2 type v1 is table of number;
3 r1 v1 := v1(1,2,3);
4 r2 v1 := v1(1,2,3);
5 begin
6 if r1 MULTISET EXCEPT DISTINCT r2 = v1() then
7 dbms_output.put_line('Same');
8 else
9 dbms_output.put_line('Different');
10 end if;
11* end;
SQL> /
Same
PL/SQL procedure successfully completed.
SQL>If you're talking about rows on a table then you can use the MINUS set operator to find the rows that differ between two sets of data...
SQL> select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-1980 00:00:00 800 20
7499 ALLEN SALESMAN 7698 20-FEB-1981 00:00:00 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-1981 00:00:00 1250 500 30
7566 JONES MANAGER 7839 02-APR-1981 00:00:00 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-1981 00:00:00 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-1981 00:00:00 2850 30
7782 CLARK MANAGER 7839 09-JUN-1981 00:00:00 2450 10
7788 SCOTT ANALYST 7566 19-APR-1987 00:00:00 3000 20
7839 KING PRESIDENT 17-NOV-1981 00:00:00 5000 10
7844 TURNER SALESMAN 7698 08-SEP-1981 00:00:00 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-1987 00:00:00 1100 20
7900 JAMES CLERK 7698 03-DEC-1981 00:00:00 950 30
7902 FORD ANALYST 7566 03-DEC-1981 00:00:00 3000 20
7934 MILLER CLERK 7782 23-JAN-1982 00:00:00 1300 10
14 rows selected.
SQL> select * from emp2;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7521 WARD SALESMAN 7698 22-FEB-1981 00:00:00 1250 500 30
7566 JONES MANAGER 7839 02-APR-1981 00:00:00 2975 20
7782 CLARK MANAGER 7839 09-JUN-1981 00:00:00 2450 10
7788 SCOTT ANALYST 7566 19-APR-1987 00:00:00 3000 20
7839 KING PRESIDENT 17-NOV-1981 00:00:00 5000 10
7900 JAMES CLERK 7698 03-DEC-1981 00:00:00 950 30
7934 MILLER CLERK 7782 23-JAN-1982 00:00:00 1300 10
7 rows selected.
SQL> select * from emp
2 minus
3 select * from emp2;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-1980 00:00:00 800 20
7499 ALLEN SALESMAN 7698 20-FEB-1981 00:00:00 1600 300 30
7654 MARTIN SALESMAN 7698 28-SEP-1981 00:00:00 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-1981 00:00:00 2850 30
7844 TURNER SALESMAN 7698 08-SEP-1981 00:00:00 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-1987 00:00:00 1100 20
7902 FORD ANALYST 7566 03-DEC-1981 00:00:00 3000 20
7 rows selected.If you actually need to know what columns data is different on "non-matching" rows (based on your primary key) then you'll have to compare column by column. -
Comparing two rows field by field through a loop
Hi all,
I've got a tricky issue:
There are two tables (almost) identically designed;
In the first one there are lets say some new data and in the 2nd one there is data to be hold & adjusted;
I built up a third table, which contains the meta informations about the two other tables (i.e. it describes the tables, so for each field of these tables, there is the field name, field type, primary key marker, etc.);
The challenge now is, how can I compare two rows (of the same primary key) field by field and get out the differences (and adjusting the target table row) using PL/SQL procedures/functions.
I thought a create a cursor over the 3rd table and call functions to get the fields out (given by the field name of the cursor), compare the two fields and return if it's equal or different...
As I've seen, there is now direct way to replace a field name in a statement - but how to resolve this with a cool workaround?
In addition, there are about 120 pairs of such tables, to be compared in the same way - so I decided to prevent creating hard coded design for the software.
Even the selection of a pair of rows from the two tables should be parameterized, 'cause the primary keys are of course different in the 120 table pairs.
Any hints or suggestions?
Thanks in advance & regards,
PeterHi Peter,
I am very far from being an expert in Oracle but, everything I've read so far strongly suggests that PL/SQL is often the fastest among the customized solutions (beating even compiled C code). The reason - from what I've understood - is that PL/SQL is part of the Oracle kernel/engine, other languages simply aren't.
I suggest you do your own research to confirm what I've just said above.
On a completely different note, when I first read your post, I started writing a reply and decided to discard it because, I figured you probably would find it too far off your original thoughts. However, then you wrote:
>
There are some reasons to prevent hard coding, but it may be possible to generate the PL/SQL-code for each pair of tables by an external program.
>
This is exactly what I was mentioning in the post I ended up discarding. The basic step by step process I was going to mention is as follows:
STEP 1: If possible, write one PL/SQL program that does the job properly for one set of tables. Test it thoroughly and identify potential differences in the process if it had to be applied against other tables. Make it as generic as reasonably possible, that is, keeping the code as simple as possible.
STEP 2: turn the working code of step 1 into a template (usually replacing table names, columns, etc by some token that would not be a valid name).
STEP 3: generate a list of the tables and their corresponding columns you need to process. This list may need to be massaged a little to become the generating seed of 120 programs (or so based on what you've said).
STEP 4: if you don't know Perl or AWK then (don't be alarmed...) download AWK (not Perl) and learn it... you can learn the thing in a couple days (maybe even less). It is a very simple and straightforward text processing language, I know non progammers that learned enough in one day to do useful things with it. Using AWK you can easily generate the 120 programs you need from a working template in very little time (a few hours after you've become proficient). By the way, there is AWK, GAWK, NAWK, all pretty much the same thing and all free. The standard manual for AWK is the one written by the authors Aho, Weinberger and Kernigan, about 100 small pages, it's an easy read and no programmer should be without it :) (better than American Express!)
What you've described sounds just like the thing to use AWK for. I once used AWK to generate 27,000 (that's 27 thousand) lines of COBOL code, debugged and fully tested in 2 days! (testing was automated using AWK too!) It would have taken much longer to just type all that code.
Anyway, I hope that gives you something to think about and be of some help.
John. -
Hi Friend.
I have to write two triggers on same table for auditing different columns of different users(may be different modules).
I will have an audit table in which i will insert data such as (user_id,module_id,column_name,old_col_val,new_col_val,timestamp)
Now different users from different modules will update the data on same table may be same columns from different front end forms!
If we write directly, we will not be able to know which column is updated by which user.
My question is in this case how can we control the triggers to raise differently?You can use WHEN clause to fire a trigger only when some condition is true - you can check an user also,
look at simple example:
- suposse we have two users US1 and US2:
C:\>sqlplus sys as sysdba
SQL*Plus: Release 10.2.0.1.0 - Production on Pn Gru 6 13:14:22 2010
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Enter password:
Connected to:
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
SQL> create user us1 identified by us1;
User created.
SQL> create user us2 identified by us2;
User created.
SQL> grant connect, resource to us1, us2;
Grant succeeded.
SQL> grant create public synonym to us1, us2;
Grant succeeded.and suposse we have a table with three columns + audit table:
SQL> connect us1
Enter password:
Connected.
SQL> create table tab123(
2 col1 number,
3 col2 number,
4 col3 number);
Table created.
SQL> create table audit_tab123(
2 username varchar2(100),
3 col1 number,
4 col2 number,
5 col3 number );
Table created.
SQL> grant select, update, insert on tab123 to us2;
Grant succeeded.
SQL> grant select, update, insert on audit_tab123 to us2;
Grant succeeded.
SQL> create public synonym tab123 for tab123;
Synonym created.
SQL> insert into tab123 values( 1, 1, 1 );
1 row created.
SQL> commit;
Commit complete.We want a trigger that is fired only by user US1 and only after update of COL1 and COL2
(COL3 is ignored):
SQL> connect us1/us1
Connected.
SQL> CREATE OR REPLACE TRIGGER Trig_123_US1
2 AFTER UPDATE OF col1, col2 ON tab123
3 FOR EACH ROW
4 WHEN ( user = 'US1' )
5 BEGIN
6 INSERT INTO audit_tab123( username, col1, col2 )
7 VALUES( user, :new.col1, :new.col2 );
8 END;
SQL> /
Trigger created.And we want a second trigger that is fired only by user US2 and only after update of COL2 and COL3
(COL1 is ignored):
SQL> connect us1/us1
Connected.
SQL> CREATE OR REPLACE TRIGGER Trig_123_US2
2 AFTER UPDATE OF col2, col3 ON tab123
3 FOR EACH ROW
4 WHEN ( user = 'US2' )
5 BEGIN
6 INSERT INTO audit_tab123( username, col2, col3 )
7 VALUES( user, :new.col2, :new.col3 );
8 END;
9 /
Trigger created.and now let test our triggers:
SQL> connect us1/us1
Connected.
SQL> update tab123 set col1 = 22;
1 row updated.
SQL> update tab123 set col2 = 22;
1 row updated.
SQL> update tab123 set col3 = 22;
1 row updated.
SQL> commit;
Commit complete.
SQL> select * from audit_tab123;
USERNAME COL1 COL2 COL3
US1 22 1
US1 22 22
SQL> connect us2/us2
Connected.
SQL> update tab123 set col1 = 333;
1 row updated.
SQL> update tab123 set col2 = 333;
1 row updated.
SQL> update tab123 set col3 = 333;
1 row updated.
SQL> commit
2 ;
Commit complete.
SQL> select * from us1.audit_tab123;
USERNAME COL1 COL2 COL3
US1 22 1
US1 22 22
US2 333 22
US2 333 333As you see, each trigger is fired only once, first triger only for user US1 and columns COL1 and COL2,
and second trigger only for user US2 and only after update of COL2 and COL3.
I hope this will help. -
Compare two fields of one table in selection.
Dear Experts,
I want to compare two fields of a table and make selection according to this.
Ex: simply i want to select the rows from table mard where mard-labst>mard-insme. Could you write me the code to make this selection.Yes, Thomas,
Its working:
Sample code:
data: begin of itab occurs 0,
matnr type matnr,
ernam type ernam,
end of itab.
select matnr ernam
into table itab
from mara where brgew > mara~ntgew.
loop at itab.
write: itab-matnr.
endloop.
Or,
Try with inner join once.
Its working: Sample code.
data: begin of itab occurs 0,
matnr type matnr,
ernam type ernam,
end of itab.
select p~matnr q~ernam
into table itab
from mara as p
inner join mara as q
on p~brgew > q~ntgew.
loop at itab.
write: itab-matnr.
endloop.
Thanks,
Naveen.I -
How to write two triggers on same table how it works?
Hello sir..
I have to write two triggers on same table for auditing different columns of different pages (may be different modules).
I will have an audit table in which i will insert data such as (user_id,module_id,column_name,old_col_val,new_col_ val,timestamp)
Now different users from different pages will update the data on same table may be same columns!
If we write directly, we will not be able to know which column is updated from different pages.
My question is how can we control the triggers to raise based on the pagesA trigger is executed whenever the table is inserted / updated / deleted (depend on trigger definition). It won't know what 'page' caused the operation. You can prepare a trigger for one page.
In order to fulfill your need, you need some way to tell the trigger where you are. There are many ways to accomplish this. Some possible methods are (please check the documents for detail)
DBMS_SESSION.SET_IDENTIFIER
DBMS_APPLICATION_INFO.SET_MODULEFor example, you can call DBMS_SESSION.SET_IDENTIFIER to set an ID from your page, and then call sys_context to read the ID back:
In Page:
exec dbms_session.set_identifier('Page1');
...In Trigger
pageid := sys_context('USERENV', 'CLIENT_IDENTIFIER') ;
...Note that if you use a connection pool, you may need to properly reset the session information before return, in order to avoid messing up the session information when the connection is used next time. -
Drag and drop row within same table.
Version 12.1.2
I am trying to implement drag and drop row within same table, and I am trying to follow this sample from Frank:
http://www.oracle.com/technetwork/developer-tools/adf/learnmore/106-reorder-table-rows-1921121.pdf
But, I am getting this cast exception. The code I have in my dropEvent bean is identical to whats on the sample.
oracle.jbo.server.ViewRowImpl cannot be cast to oracle.jbo.uicli.binding.JUCtrlHierNodeBinding
ADF_FACES-60097:For more information, please see the server's error log for an entry beginning with: ADF_FACES-60096:Server Exception during PPR, #1
Not sure if anything has changed on 12c release, or if I am missing anything.
Here is my complete code:
public DnDAction doDnD(DropEvent dropEvent) {
RichTable table = (RichTable) dropEvent.getDragComponent();
List dropRowKey = (List) dropEvent.getDropSite();
if (dropRowKey == null) {
return DnDAction.NONE;
Transferable t = dropEvent.getTransferable();
DataFlavor<RowKeySet> df = DataFlavor.getDataFlavor(RowKeySet.class, "rowmove");
RowKeySet rks = t.getData(df);
Iterator iter = rks.iterator();
List draggedRowKey = (List) iter.next();
JUCtrlHierNodeBinding draggeRowNode = (JUCtrlHierNodeBinding) table.getRowData(draggedRowKey);
Row dragRow = draggeRowNode.getRow();
JUCtrlHierNodeBinding dropRowObject = (JUCtrlHierNodeBinding) table.getRowData(dropRowKey);
Row dropRow = dropRowObject.getRow();
//get the table's ADF JUCtrlHierBinding
CollectionModel collectionModel = (CollectionModel) table.getValue();
JUCtrlHierBinding treeBinding = (JUCtrlHierBinding) collectionModel.getWrappedData();
DCIteratorBinding objectsIterator = treeBinding.getDCIteratorBinding();
RowSetIterator rsi = objectsIterator.getRowSetIterator();
int indexOfDropRow = rsi.getRangeIndexOf(dropRow);
dragRow.removeAndRetain();
rsi.insertRowAtRangeIndex(indexOfDropRow, dragRow);
objectsIterator.setCurrentRowIndexInRange(indexOfDropRow);
AdfFacesContext adfctx = AdfFacesContext.getCurrentInstance();
adfctx.addPartialTarget(table.getParent());
return DnDAction.MOVE;
It does not seem to like this line of code:
JUCtrlHierNodeBinding draggeRowNode = (JUCtrlHierNodeBinding) table.getRowData(draggedRowKey);
I would greatly appreciate any help.
Thanks.Well there has bee a changes somehow. using 12c
table.getRowData(draggedRowKey);
returns a ViewRowImpl and no longer anything which can be convertet to JUCtrlHierNodeBinding. Anyway, the fix is easy:
public DnDAction onDepartmentsRowDrop(DropEvent dropEvent) {
//get the table instance. This information is later used
//to determine the tree binding and the iterator binding
RichTable table = (RichTable) dropEvent.getDragComponent();
List dropRowKey = (List) dropEvent.getDropSite();
//if no dropsite then drop area was not a data area
if (dropRowKey == null) {
return DnDAction.NONE;
//The transferable is the payload that contains the dragged row's
//row key that we use to access the dragged row handle in the ADF
//iterator binding
Transferable t = dropEvent.getTransferable();
//get the row key set of the dragged row. The "rowmove" string is the
//discriminant defined on the drag source and the collectionDrop target.
DataFlavor<RowKeySet> df = DataFlavor.getDataFlavor(RowKeySet.class, "rowmove");
RowKeySet rks = t.getData(df);
Iterator iter = rks.iterator();
//for this use case the re-order of rows is one-by-one, which means that the rowKeySet
//should only contain a single entry. If it contains more then still we only look at a
//singe (first) row key entry
List draggedRowKey = (List) iter.next();
//get access to the oracle.jbo.Row instance represneting this table row
Object objdragg = table.getRowData(draggedRowKey);
Row dragRow = (Row) objdragg;
Object objdrop = table.getRowData(dropRowKey);
Row dropRow = (Row) objdrop;
//get the table's ADF JUCtrlHierBinding
CollectionModel collectionModel = (CollectionModel) table.getValue();
JUCtrlHierBinding treeBinding = (JUCtrlHierBinding) collectionModel.getWrappedData();
//get access to the ADF iterator binding used by the table and the underlying RowSetIterator.
//The RowSetIterator allows us to remove and re-instert the dragged row
DCIteratorBinding departmentsIterator = treeBinding.getDCIteratorBinding();
RowSetIterator rsi = departmentsIterator.getRowSetIterator();
int indexOfDropRow = rsi.getRangeIndexOf(dropRow);
//remove dragged row from collection so it can be added back
dragRow.removeAndRetain();
rsi.insertRowAtRangeIndex(indexOfDropRow, dragRow);
//make row current in ADF iterator.
departmentsIterator.setCurrentRowIndexInRange(indexOfDropRow);
//ppr the table
AdfFacesContext adfctx = AdfFacesContext.getCurrentInstance();
//note that the refresh of the table didn't work when refreshing the table
//so I needed to refresh the container component (af:panelStretchLayout).
adfctx.addPartialTarget(table.getParent());
return DnDAction.MOVE;
does the trick. I changed the line to
//get access to the oracle.jbo.Row instance represneting this table row
Object objdragg = table.getRowData(draggedRowKey);
Row dragRow = (Row) objdragg;
so you don't need the detour through the JUCtrlHierNodeBinding any longer.
Timo -
Comparing totals from the same table
I am trying to compare data from the same table..
i am using an alias of the table to set up the select but i am running into a cartesian set.
I am comparing data (totals) from different dates from the same table ; i have included the query which is giving me a problem:
select a.date_in,b.date_in,a.Table_name,
DECODE(a.schema_name,
'EZLIVE','ITP','EZAC','ACT','OTHER')AS DEPT,
a.type,
a.status,
a.TOTAL,
b.total
from agg_results a,agg_results b
where a.schema_name=b.schema_name
and to_char(a.date_in,'mm/dd/yyyy')='&date_in'
and to_char(b.date_in,'mm/dd/yyyy')='&date_in';
any help thanks
ElleryI think you need to join in-line views instead of the tables directly. something like:
SELECT a.date_in,b.date_in,a.table_name,a.dept,a.type,a.status,a.total,b.total
FROM (SELECT date_in,table_name,
DECODE(schema_name,'EZLIVE','ITP',
'EZAC','ACT','OTHER') dept,
type,status,total
FROM agg_results
WHERE date_in = to_date('&date_in','mm/dd/yyyy') a,
(SELECT date_in,table_name,
DECODE(schema_name,'EZLIVE','ITP',
'EZAC','ACT','OTHER') dept,
type,status,total
FROM agg_results
WHERE date_in = to_date('&date_in','mm/dd/yyyy') b
WHERE a.dept = b.deptTTFN
John -
VORowImpl problem - comparing two ROW[] lists
Hi Everyone,
I have a huge proble right now, I'm trying to compare two VO list with the same values, this is because one it's attached to an advancedtable in the xml page wich the user can change some values, and the other one is from the values of the table but from the DB, the reason is to made a validation to compare the original values from the DB with the list from the tabla and update only the rows that the users made changes in their values, here's my code for a better explain of what I'm doing:
public void saveChanges(){
OADBTransactionImpl oadbtransactionimpl = (OADBTransactionImpl)getDBTransaction();
Row[] rows1 = getAppVO1().getAllRowsInRange();
Row[] rows2 = getDBVO1().getAllRowsInRange();
for(int i = 0; i < rows1.length; i++){
int j = i;
//Colections to compare
//r1: colection from the app
//r2: colection from BD
AppVORowImpl r1 = (AppVORowImpl) rows1;
DBVORowImpl r2 = (DBVORowImpl) rows2[j]; //<--- here in the second iteration appears the following error:
// "oracle.apps.fnd.framework.OAException: java.lang.ArrayIndexOutOfBoundsException: 1"
//variables string to check if got changes in the column
String columnAPP = r1.getId().toString();
String columnBD = r2.getId().toString();
//'if' that validates changes
if(!columnAPP.equals(columnBD)){
//String variable SP
StringBuilder procedureCall = new StringBuilder();
//calling to SP
try{
procedureCall.append("... stored proc...");
OracleCallableStatement oraclecallablestatement = (OracleCallableStatement)oadbtransactionimpl.createCallableStatement(procedureCall.toString(), -1);
oraclecallablestatement.execute();
getOADBTransaction().commit();
}catch(SQLException sqlexception){
System.err.println("SQL Exception: "+ sqlexception.getMessage());
getOADBTransaction().rollback();
throw OAException.wrapperException(sqlexception);
}catch(Exception e){
System.err.println("Exception: "+ e.getMessage());
getOADBTransaction().rollback();
throw OAException.wrapperException(e);
the first iteration works fine, but the second and futher shows an exception error, what can I do to make this method works?
I'll be pending to your answers, I really hope you can help me with this one
Regards,
MentorHere is the dump code for you. Code you have to write in AmImpl and call the same from Controller class.
AMImpl Code
public void executeBothViewObjects() //Calls this method from Controller *ProcessRequest*
OAViewObject vo = (OAViewObject)getMainViewObjectVO1();
OAViewObject dvo = (OAViewObject)getDBViewObjectVO1();
if (vo != null && dvo != null)
//1st VO
dvo.setWhereClauseParams(null);
//Set where clause if Any dvo.setWhereClauseParam(0,xx);
dvo.executeQuery();
//2nd VO
vo.setWhereClauseParams(null);
//Set where clause if Any dvo.setWhereClauseParam(0,xx);
vo.executeQuery();
public void compareViewObject() // Calling this method to compare Attribute of both View Object *Process Form Request*
OAViewObject vo = getMainViewObjectVO1();
OAViewObject OrigVO = getDBViewObjectVO1();
MainViewObjectVORowImpl rowi = null;
DBViewObjectVORowImpl rowii = null;
int fetchedRowCount = vo.getRowCount();
int OriginalfetchedRowCount = OrigVO.getRowCount();
RowSetIterator originalSelectIter = OrigVO.createRowSetIterator("originalSelectIter");
RowSetIterator selectIter = vo.createRowSetIterator("selectIter");
if (fetchedRowCount > 0 && OriginalfetchedRowCount >0)
selectIter.setRangeStart(0);
selectIter.setRangeSize(fetchedRowCount);
originalSelectIter.setRangeStart(0);
originalSelectIter.setRangeSize(OriginalfetchedRowCount);
for (int i = 0; i < fetchedRowCount; i++)
rowi = (MainViewObjectVORowImpl)selectIter.getRowAtRangeIndex(i);
rowii = (DBViewObjectVORowImpl)originalSelectIter.getRowAtRangeIndex(i);
//Compare Attribute here
if((!(rowi.getRoleStartDate().equals(rowii.getRoleStartDate()))
// Comparing Start date here of both View Object
else if(((rowi.getRoleEndDate().equals(rowii.getRoleEndDate()))
// Comparing End date here of both View Object
}Thanks
--Anil
http://oracleanil.blogspot.com/ -
Compare Consecutive Rows in a table
Hi,
I want to compare consecutive rows for each employee. I need to compare SchedulEnd column of the first row with the ScheduleStart of the second row as so on. if both the values are same then i need to generate a sequence like 00 for the first record 01 for
the second record and so on. if the time is not same the the sequence should start with 00.
Example: lets say the data is like:
schedule start
schedule end
10
11
11
12
12
13
15
18
the output should be like
sequence
00
01
02
00Thank you very much for the quick reply.
I have one more scenario now, with the same data, i want the output like this
<table>
<tr>
<th>Employee</th>
<th>Schedule Time</th>
<th>sequence</th>
<th>Remarks</th>
</tr>
<tr>
<td>1</td>
<td>10</td>
<td>00</td>
<td>sequence "00" as schedule time is unique, 10 is the schedule start time</td>
</tr>
<tr>
<td>1</td>
<td>11</td>
<td>00</td>
<td>sequence "00" as schedule time is unique, 11 is the schedule end time for the first record</td>
</tr>
<tr>
<td>1</td>
<td>11</td>
<td>01</td>
<td>sequence "01" as schedule time is unique, 11 is the schedule start time of the next record</td>
</tr>
<tr>
<td>1</td>
<td>12</td>
<td>00</td>
<td>sequence "00" as schedule time is unique, 12 is the schedule end time of the previous record</td>
</tr>
<tr>
<td>1</td>
<td>12</td>
<td>01</td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table> -
I need to retrieve the a set of rows in between two rows from a table.
consider employees table and primary key employee_id.
With out using EMPLOYEE_ID column in the where clause or between clause, I need to get the records between 104 and 116 or a set of records between two rows.
Can any one help me in this... i know this is simple but am just a fresher to oracle development... help me grow....
Thanks,
Arunya at last i got the out put... thank guys for thinking with me....
SELECT rownum, employee_id FROM (SELECT rownum, employee_id FROM employees ORDER BY employee_id)
WHERE ROWNUM <=8
MINUS
SELECT rownum, employee_id FROM (SELECT rownum, employee_id FROM employees ORDER BY employee_id) WHERE ROWNUM <= 4
Maybe you are looking for
-
Alert message error - need help
I'm very poor in the javascript department when developping PDFs and I would need a little help with this issue. On one row, I would need field C to check on exit if Field A is larger than field C. If field A is not larger, then I need an alert messa
-
Trouble using scroll panel in textArea
Hello all, Im kinda stuck again I'm having a small simple problem where I'm reading the results of a search performed from a .txt file and I'm returning the results to a textArea but the only problem is that the textArea will not create a scroll bar
-
ESS-Changing dependent information
Hi gurus, If the employee changes his dependent information on ESS is there any standard workflow which triggers and goes to administration. When administrator approves that informations should be updated on R/3. Can we use BP ERP2004(Clock i
-
Take permission for folder and contents
Is there a way to take permissions for a whole folder and its contents all at once? I transfered hundereds of photos from my old MBP (Snow Leopord) to my new MBP (now Lion) I know how to change permission for a single file, but I'm tired of doing it
-
This probably is not the best place to post this question, but didnt get any reply in WSAD IE forum. Here it goes : I am getting this error when I start any Java Application in profile mode : Can't load "piAgent.dll", because Can't find dependent lib