PL/SQL :: Compare Two Rows From Same Table And Show Field And Difference?

Aug 28, 2013

How can I compare two rows from the same table and show the field and the difference?

Example:

select ename, job, mgr, hiredate, sal, deptno
from EMP t
where t.empno = 7782
or t.empno = 7788

ENAME JOB MGR HIREDATE SAL DEPTNO
1 CLARK MANAGER 7839 6/9/1981 2450.00 10
2 SCOTT ANALYST 7566 6/9/1981 3000.00 20

My report comparing fields should be:

FIELD BASE COMPARE DIFFERENCE
ENAME CLARK SCOTT --
JOB MANAGER ANALYST --
MGR 7839 7566 --
SAL 2450 3000 550 --(Show difference only for numbers)
DEPTNO 10 20 --

View 9 Replies


ADVERTISEMENT

PL/SQL :: Compare A Row Of A Table With Its Previous Row / Rows In A Query

Oct 1, 2013

create table a(sourcerow number(2),  test_level number(2),  dpn varchar2(1),  qty number(5)); T

he insert scripts are as follows:  

insert into a  values(1,3,'Y',5); insert into a values(2,2,'Y',4);  insert into a values(3,3,'N',3); insert into a  values(4,4,'Y',3);  insert into a  values(5,1,'N',6);  insert into a values(6,2,'N',5);  insert into a  values(7,2,'Y',4);  insert into a  values(8,3,'N',2);  insert into a values(9,4,'Y',2);  insert into a  values(10,1,'Y',3); .  SQL>select * from v$version;  Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production 

My logic should have the output as follows without 5th column:  sourcerowleveldpnqtyremark13Y522Y4This row in main table shouldn't be displayed in the query result as it has

dpn='N'44Y3*3=9In this row qty=9 will bedisplayed.

It will compare the value of level column with its previous row level col,if it is the parent of the current(ex.current is 4 and previous is 3 parent of 4),then it will check the dpn of previous row ,if dpn='N' then qty of parent will be multiplied with qty of current row and displayed under qty column.this row will not be displayed as dpn='N'this row will not be displayed as dpn='N'72Y4*6=24in its previous row level value is same so it will check the previous to previous row  where level is 1(parent of current row) and dpn='N' ,then it will multiply the qty of that row with current row and display the value in qty column.this row will not be displayed as dpn='N'94Y2*2=4In this row qty=4 will be displayed.It will compare the value of level column with its previous row level col,if it is the parent of the current(ex.current is 4 and previous is 3 parent of 4),then it will check the dpn of previous row ,if dpn='N' then qty of parent will be multiplied with qty of current row and displayed under qty column.101Y3It will not check for the previous rows as level 1 doesn't have any parent. 

View 5 Replies View Related

PL/SQL :: Compare Two Tables And Delete The Common Rows From Table 1

Jul 23, 2012

I want to compare two tables , and delete the common rows from the first table

Here is what i have done :

Create table test1(Test1C1 Number,
Test1C2 varchar2(50));

Create table test2(Test2C1 Number,
Test2C2 varchar2(50));

Insert into test1 values(1,'testdata1');
Insert into test1 values(2,'testdata2');
Insert into test1 values(3,'testdata3');
[code].......

it deletes all the records from Table test1. What should I modify here ? or should I write a different query ?

The desired contents in table test1 will be

2 testdata2
4 testdata4
6 testdata6
8 testdata8
10 testdata10

View 5 Replies View Related

Application Express :: How To Show Alert When Data Not Exist In Table And Clear Field

Jun 8, 2012

Recently i created a form which contains emp_name,deptno,supervisor_name.For emp_name if i type the emp name (eg:allen) it will show me a list of employees named allen as a select list.For that i used a jquery script on page header

<link rel="stylesheet" href="URL.....
<script type="text/javascript" src="URL....
<script type="text/javascript">
[code]....

and i have created a dynamic action for emp name to fetch the deptno,supervisor_name if select the employee name it is working fine is if i type a emp_name which doesn't exist in the employee table it will show me a alert message employee does not exist and it will clears all the fields.

View 0 Replies View Related

SQL & PL/SQL :: Count Of Date Difference Using Pending State Value In Table Field

Feb 2, 2012

Find the date difference. I need to find that how many days the task is pending, if ACT_NAME field switching from 'SET PENDING%' to 'RESUME PENDING%' by using ACTIONTAKENDATETEXT field in the History table.

Example as needed:
NoPendingDays = 23 (8+15)

I have attached Create table and Insert table values sample as SQL file.

View 10 Replies View Related

SQL & PL/SQL :: Select Rows From Table With Same Particular Field?

Aug 20, 2012

select the rows from a table with the same particular field in PL/SQL. Actually I don't want to write two loops one inserted into another.

View 7 Replies View Related

SQL & PL/SQL :: Compare Current Rows With Previous Rows

Apr 12, 2013

The Table having 3 columns

col0col1 , col2
P112
P112
P102
P113
P115

I want to retrieve the changes rows only.

Output like
col0col1 , col2
P112
P102
P113
P115

View 5 Replies View Related

SQL & PL/SQL :: Generate The Number Of Rows Based On Table Field?

Mar 29, 2013

generate the number of rows based on table field.

Sample code is given below.

CREATE TABLE T
(
docno VARCHAR2(10),
CODE VARCHAR2(8),
QTY NUMBER(3)
)
LOGGING

View 4 Replies View Related

SQL & PL/SQL :: Delete Last N Sets Of Rows Of A Table With Same Dates In Sort Field

Mar 15, 2013

I know how to select the last N sets of rows, using DENSE_RANK - where multiple rows have the same timestamp but I want to only select those rows which do NOT have the top 2 unique timestamps.

i.e.:

SELECT *
FROM ( SELECT DENSE_RANK() OVER (ORDER BY myTimestamp DESC) DENSE_RANK, HISTORYID, USER_ID, myTimestamp, STATUS, FROM TXN_HIST)
WHERE DENSE_RANK > 2 order by myTimestamp DESC, HISTORYID, USER_ID;

But how do I DELETE these same rows?

View 3 Replies View Related

Application Express :: Export Table Rows To Excel And Save To BLOB Field?

Sep 26, 2012

I try to find out how export data from table to Excel file format and save the result to BLOB field in some other table.I know how to download report from Page by submit, but I need to process data and instead of returning result to user as Excel file - save it in BLOB.

Also I found implementation on JAVA for the issue but actually I wanna study out - Is it possible to resolve this issue by PL/SQL and APEX API methods?

View 4 Replies View Related

SQL & PL/SQL :: Compare Two Rows Of Cursor?

Oct 6, 2010

I have an audit table FEE_RULE_AUD with the following structure.

FEE_RULEVARCHAR2(10 BYTE)
AUDIT_DATETIMESTAMP(6)
AUDIT_ACTIONVARCHAR2(30 BYTE)
AUDIT_USERVARCHAR2(8 BYTE)
NAMEVARCHAR2(30 BYTE)
FEE_BASISCHAR(1 BYTE)
FEES_ONCHAR(1 BYTE)
SECURITYCHAR(10 BYTE)

I have to generate a report for the audit with in the dates specified(range). I got the set of record for the specified date range by using the following query:

select * from fee_rule_aud where TO_NUMBER(TO_CHAR(TRUNC(audit_date),'YYYYMMDD'))>20090629
and TO_NUMBER(TO_CHAR(TRUNC(audit_date),'YYYYMMDD'))<=20100710 order by fee_rule,audit_date

this query returned some five records, now I have to iterate through this and compare 1st and 2nd row in first iteration (1st row will have the new value and 2nd row will have old vale). If there is any difference then insert into audit_log table which has the following structure:

Fee_rule , column_name, old_value,new_value

This process has to repeat for all the 5 rows like comparing 1st,2nd rows and 2nd,3rd rows and 3rd,4th rows and so on if it has more rows.

get the two rows and compare ?

View 16 Replies View Related

PL/SQL :: How To Compare Two Rows And Retrieve The Values

Aug 15, 2012

I have two tables which have identical schemas, one table (tbl_store) is used to hold the latest version, and the other table (tbl_store_audit) holds previous versions. When the latest record is updated, it is inserted into the tbl_store_audit table as a revision, and the updated details are used as the latest record.

For example: The latest version is held in tbl_store, however the tbl_store_audit may hold 5 records which are the past records used before changes were made - these are seen as revisions.

I want to be able to compare what has changed between each revision in the tbl_store_audit table. For example: Out of the 10 columns, the change between revision 1 and revision 2 was the size from XL to XXL. The change between revision 3 and revision 4 was the size XS to M and price 4.99 to 10.99, and so on.

Eventually i will create an APEX report that will show the user the revision number and what was changed from and to.

I seen in a previous post i need to note my oracle version: Oracle version 10.2.0.4.0

View 16 Replies View Related

Forms :: One Column Show Two Field Also Update

Jun 23, 2012

I have a table in which three field.

1)empid (Save employee code)
2)attendace_time (Save Date and inout time)
3)status. (Save in out Status).

I generate new form. which have four field.

1)empid
2)attendance_date base on attendance_time 3
3)Attendace_time base on attendance_time
4)Status .

Problem is that when i update the Attendace_time . date save first date of the month. when i update the attendance_date time save 12:00

View 1 Replies View Related

Forms :: Show Increasing Digit 1 To 100 In Text Field After Pressing One By One

Aug 26, 2013

the code for show increasing digit 1 to 100 in a text field after pressing a button 100 times?

View 26 Replies View Related

SQL & PL/SQL :: Show Missing Rows In Query

Feb 7, 2012

SQL> select * from t1;

NAME
----------
JACK
JOHN
JENN

SQL> select * from t2;

NAME
----------
JACK
PAUL

SQL> select a.name from t1 a, t2 b where a.name <> b.name
2 order by name;

NAME
----------
JACK
JENN
JENN
JOHN
JOHN

I would have expected to see the following:

name
-----
JOHN
JENN
PAUL

how to fix this query? In additon, is there a way to print the table name or some arrows (>>, <<) to show which table the values came from

I.e

name
=====
JOHN t1 or <<
JENN t1 or <<
PAUL t2 or >>

View 14 Replies View Related

SQL & PL/SQL :: How To Get Difference Between Two Rows Of Same Column

Aug 3, 2013

Calculating the difference between the two rows of same columns? Example of my Scenario is as follows

I have a table as shown below, there are checks thats has been issued per week (to tell how its been issued per week ,if you see the week number ,there is a change in week no for period of 7 days i.e. what i have to show on my results tables based on week no and probably we may need to take into account for check no too.)

wekno ! checkno ! end date
------ ! ------ ! ------
1 ! 1 ! 1/7/2012
1 ! 2 ! 1/8/2012
1 ! 3 !1/9/2012
2 ! 1 ! 1/14/2012
2 ! 2 ! 1/15/2012
3 ! 1 ! 1/21/2012

result table and date range i picked up was 1/1/2012-1/31/2012

wekno ! checkno ! end date ! previous period ! Daysin period
------ ! ------ ! ------ ! ------------- ! ------------
1 ! 1 ! 1/7/2012 ! null (as previous period is 2011 and so prvs year i dont count) ! 7 this because we see change in wkno per 7 days
1 ! 2 ! 1/8/2012 !null becoz this one falls same week and therefore previous peroid would be the same as above ! 7 above reason
1 ! 3 ! 1/9/2012 ! null becoz this one falls same week and therefore previous peroid would be the same as above ! 7 above reason
2 ! 1 ! 1/14/2012 ! 1/7/2012 becoz this a second week as you see the change in wekno and therefore its previosu period is 1/7/2012 ! 7 above reason
2 ! 2 ! 1/15/2012 ! 1/7/2012 becoz this check falls on the same second week so previosu would be 1/7/2012 ! 7 above reason
3 ! 1 ! 1/21/2012 ! 1/14/2012 as a new week no starts this gonn be 1/4/2012 ! 7 above reason

View 2 Replies View Related

Counting Rows - Difference In Values That Are Returned?

Sep 26, 2010

difference in the values that are returned?

select count(*) from aaa;
COUNT(*)
----------
1000001

select num_rows from dba_tables where table_name = 'AAA';
NUM_ROWS
----------
994202

View 5 Replies View Related

SQL & PL/SQL :: Rows Depends On A Total Field

Feb 24, 2012

I have a table TP having following data (Dashes used for space as i am unable to have proper alignment)

ID1-----TOT
1 ------- 5
2 ------- 7

I need a query that repeat the records depending on the field TP.TOT

e.g.

ID1 -----TOT
1 ------- 5
1 ------- 5
1 ------- 5
1 ------- 5
1 ------- 5
2 ------- 7
2 ------- 7
2 ------- 7
2 ------- 7
2 ------- 7
2 ------- 7
2 ------- 7

View 5 Replies View Related

SQL & PL/SQL :: Updating A Date Field With Field From Another Table?

Nov 14, 2011

I have a table called Customer_Type with following fields

Customer_type ,Active_date, Inactive_date
regular,11/01/2011
daily,11/04/2011
monthly,11/05/2011/11/11/2011

Tbale 2:Customer

Customer_name,Customer_type,Customer_Inactive_date
John,regular,
James,monthly,
Jake,daily,
Jill,monthly

What i wnat is to update the Customer_inactive_date with the Incative_date field from Customer_type based on their Customer_type... So james and Jill would have their rows updated in this scneario ..How can i achive this in pl/Sql

I have teh code using merge function..I want something in traditional old fashion..

The sql statements are below

CREATE TABLE CUSTOMER_TYPE
(
type_code VARCHAR2(10),

[Code]....

View 5 Replies View Related

SQL & PL/SQL :: SELECT With Count Of Rows Depending On Sum Of A Field?

Aug 10, 2011

I want to create a SELECT, that shall give back only a special amount of rows, depending on the sum of one of the selected fields.

At first a code sample of the complete selection:

SELECT DISTINCT mnr, ktxt,
(SELECT Sum(meng_4)FROM reldb d1 WHERE d1.mnr=d.mnr)qty
FROM reldb d
WHERE mnr IN (SELECT mnr FROM relac WHERE Lower(rlnr) NOT LIKE 'platte geprägt%')
AND saext='M'
ORDER BY qty DESC,ktxt;

This selection produces some lines of output (in my case i.e. like 300). What I want to see is only that much lines that the condition 'sum of all items listed below meng_4<=sum of all items meng_4 of the whole selection * 0.9' is fulfilled.

So, if the whole selection produces a total of 10000 as sum for all items meng_4, I want to see only that amount of rows that sums a total of at least 9000 for all items meng_4.
I hope, this specification is exactly enough to understand my intent.

1. Can I do this in a query?

2. If yes, what would this query look like?

View 19 Replies View Related

SQL & PL/SQL :: Compare Two Different Table?

Jul 11, 2011

I want to compare two tables column by column and find out which columns are matching and inserting matching columns value into another table.

View 1 Replies View Related

SQL & PL/SQL :: How To Split Multi-delimited Field Into Several Rows And Add New Fields

Mar 7, 2013

I have a query that produces around 11 fields, and one of which is a multi-delimited field and the other 10 are dimension fields. I would like to split that field into several rows, and have the other 10 fields just repeated for each one. Here is an example of the data in the 11th field :

Column 11
34^56^78,59

There are two delimiters in the field, a carat and a comma. This field is used to reference document numbers that are needed to be sent in. The carat represents the word "Or" and the comma represents the word "And". I would like to have the output of each field to be a repeat of the 10 dimension fields, plus 3 new fields. The first new field would be the document number, the second new field would be the position within the original delimited field(1, 2, 3, etc.) , and the last field would be one of three logic words :First (if it is the first value), Or (if the value followed a carat), And (If the value followed a comma). Example of the output from the above value would be :

Column 11 Column 12 Column 13
34_______ 1_______ First
56_______ 2_______ Or
78_______ 3_______ Or
59_______ 4_______ And

Any thoughts on this? I have found a few solutions online on how to break up the delimited field into rows, but never with multiple delimiters or with extra logic for the added fields.

View 13 Replies View Related

List Count Of Rows Where DATE Field Is Not Null?

Apr 1, 2010

I need to list a count of rows where a DATE field is not null and group those counts by day.

Here's my sql so far...

SELECT
COUNT(DQ_DISTRBTN_DATE) as DQR_DIST,
DQ_DISTRBTN_DATE as DIST_DATE
from
ETL_PROCESS.BATCH
group by
DQ_DISTRBTN_DATE;

Because DQ_DISTRBTN_DATE contains time, how do I modify to achieve the desired result?

View 2 Replies View Related

SQL & PL/SQL :: Compare Columns Of Two Table?

Apr 5, 2013

I need to compare columns of two tables in oracle 10g. If columns of both tables match with each other, then i need to create new table dynamically with matched column name and datatype. For example, table1 contains name, ID, Phone_no and address table2 contains name, Id, address, area and pincode. now , i need to create table3 which will contains name, ID,address, Phone_no, area and pincode as columns( I mean matched columns should not be repeated in table3). how to do this..

View 17 Replies View Related

SQL & PL/SQL :: Compare Two Table Data

Mar 5, 2010

How to identify the columns which are different between two oracle tables. I have nearly 30 columns in each table comprising of million rows

View 11 Replies View Related

SQL & PL/SQL :: How To Compare Data In Nested Table

Mar 12, 2012

create type nesttype as table of clob;

create table emp
(empno number,
ename varchar2(1000),
language_known nesttype
)

I want to check whether language is already there in database or not.

i have written the below query

select * from emp where language_known =nesttype('english','hindi');

i am getting the below error

SQL Error: ORA-22901: cannot compare nested table or VARRAY or LOB attributes of an object type
22901. 00000 - "cannot compare nested table or VARRAY or LOB attributes of an object type"
*Cause: Comparison of nested table or VARRAY or LOB attributes of an
object type was attempted in the absence of a MAP or ORDER
method.
*Action: define a MAP or ORDER method for the object type.

How to compare data in nested table

View 16 Replies View Related

SQL & PL/SQL :: Order By Field Containing Characters And Numbers (split From Convert No Rows Returned To Zero)

Jan 13, 2012

I Want to make a query to select finished goods product in sales having product code greater than 280 but i have face a problem that order by is not working because products column have character code as well as number. how to sort that column.

View 2 Replies View Related

Application Express :: To Change The Default Behavior Of Hide / Show Region To Show

Jun 26, 2012

I am trying to change the default behavior of Hide/Show Region to show, after some attempts i got it partially working but now clicking the icon to toggle hide/show doesn't work also changed the icons and added type="" but its not working.

View 16 Replies View Related

Compare Records In A Table In Both Oracle - MSSQL?

Jan 13, 2009

I am trying to compare records in a table in both Oracle and MSSQL database against a single standard dataset in my test case. However, I'm getting different results for each when I sort using a "order by".

select COL1 from TABLE1 order by COL1

In MSSQL, I get:
COL1
=====
A
A.
A++
A++.

In ORACLE, I get:
COL1
=====
A
A++
A++.
A.

I mean, oracle result some what makes sense, because "." has bigger ascii value than "+". But is there anyway to make the ORACLE sort order look exactly like MSSQL result?

View 1 Replies View Related

PL/SQL :: Create Query To Compare Values From Same Table

Jul 10, 2012

Suppose you have the below table, same ID's occur for same month as well as different month

ID Month Value
--------------------------------------------------------------
226220      201203     100
1660      201204     200
26739      201204     1010
7750     201205     31.1

I need a query to determine the below laid result

ID Month Prior_month_value Prior_Month Value
----------------------------------------------------------------------------
1234 201203 10 201201 100
3456 201206 56.1 201204 78

View 10 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved