PL/SQL :: Previous Record Find?

Jun 25, 2013

CREATE TABLE F_TIME(  PERIOD_ID      NUMBER,  PERIOD_NAME    VARCHAR2(30 CHAR),  PERIOD_YEAR    NUMBER,  PERIOD_TYPE    VARCHAR2(30 CHAR),  CREATION_DATE  DATE,  UPDATE_DATE    DATE,  UPDATE_BY      NUMBER); SET DEFINE OFF;Insert into F_TIME   (PERIOD_ID, PERIOD_NAME, PERIOD_YEAR, PERIOD_TYPE, CREATION_DATE,     UPDATE_DATE) Values   (16, 'Q4', 2012, 'q', TO_DATE('04/20/2013 17:41:28', 'MM/DD/YYYY HH24:MI:SS'),     TO_DATE('04/20/2013 17:41:28', 'MM/DD/YYYY HH24:MI:SS'));Insert into F_TIME  

[code]...

if i pass 30 then it will return period id=16 data

View 3 Replies


ADVERTISEMENT

PL/SQL :: Code Erases Previous Month Record While Updating Current Month Record

May 16, 2013

Using 11gR2, windows 7 client machine. I need to update the table missing_volume (below), where I need to calculate the estimated_missing column. The calculation of estimated_missing column for current month needs previous month numbers (as commented inside the code below). I want the output like the first table. Notice the records start from January, hence estimated_missing for January can't be calculated, but for the the rest of the months it can be done by simply changing 'yr' and 'mnth' (commented inside the code towards the end).

yr          mnth          location     volume          actual_missing          expected_missing     estimated_missing
---------------------------------------------------------------------------------------------------------------------------------
2013            January          loc1          48037          24               57                         
2013             February     loc1          47960          3660               53                      24
2013             March          loc1          55007          78               57                      28
2013             April          loc1          54345          72               58                  77The code:

UPDATE missing_volume g

[Code]....

The code does calculate correct number for 'estimated_missing' as I run the code for each month, but the problem is while updating the current month it also erases the record for previous month. E.g. as can be seen below, after I updated April the column only has the record for April, previous month record is gone, similarly updating March removed February, etc. I can't understand why it's happening!! Here is the output I get:

yr          mnth          location     volume          actual_missing          expected_missing     estimated_missing
---------------------------------------------------------------------------------------------------------------------------------
2013            January          loc1          48037          24               57                         
2013             February     loc1          47960          3660               53
2013             March          loc1          55007          78               57
2013             April          loc1          54345          72               58                   77

why it's happening (I mean where is the flaw in the code) and how to get the desired output (first table).

View 5 Replies View Related

SQL & PL/SQL :: Previous Record For Multiple Combination

Aug 17, 2012

How to achieve "Prev_Value" column as shown below without using ORACLE analytic functions

I have records stored in table for various categories and based on ID / Name / Office / Product / Category combination I want to achieve previous value column through efficient SQL query

Test Scripts as below

CREATE TABLE TEST_Prev
(
ID1 NUMBER(3),
Name1 VARCHAR2(10),
OFFICE VARCHAR2(20),
PRODUCT VARCHAR2(20),
Overall VARCHAR2(20),
DATE1 DATE,
VALUE1 NUMBER(1)
);
commit;
[code]......

Expected output as in attached sheet.

View 11 Replies View Related

SQL & PL/SQL :: Find Previous Cursor Loop Value

Dec 15, 2011

I take a select into a cursor and process it record by record.I have to do sum based on a column and display row by row by using dbms_output.put_line .... So the sum has to happen based on a column. Based on the column value i need to display the cumulative sum as well.

Example:-

col1 col2 amount
DL AADD 25
DL BBCC 10
DL BBRR 15

Sum value for DL ----- 50

TX ADED 20
TX EDWW 60

Sum value for TX ----- 80

All the above data should be displayed using DBMS_OUTPUT.PUT_LINE in a pl/sql code. I use cursor to take the values from the table but the problem i face is .... I am not able to display the sum based in the col1 values.

Since i use the cursor .. i took the col1 values in to a variable and checked every time
old_variable = new_variable
if yes then continue the sum
else
display the sum value.

once i get the above check satisfied i am loosing a new col1 row in the check. The next loop only run for the new col1 values -1( which is used in the check loop).So is there any better way to get the solution or is there a facility to store the previous loop values in a cursor ? so that i dont have to loose that one row of data.

I am not able to come up with proper loop so which can identify that the col1 has changed and you have to display the sum value.

View 17 Replies View Related

PL/SQL :: Find Previous Value From Oracle Table

Jun 4, 2013

I have a stat table that got info like login_date,user_id etc.For a specific user, i have a requirement based on the no of days difference between the current login date and last login date.

For example, Tom logged in on June 4th 2013. His previous login was May 31. So no_of_days_difference is 5 days.How to programmatically get this for each user inside a pl-sql sub block.

View 2 Replies View Related

Forms :: Repeat Same Values To Next Record From Previous?

Jun 16, 2011

How do you repeat the same values to the next record from the previous record to reduce the user entry in d2k ??

View 1 Replies View Related

How To Find Previous Path Location Of Archive Log

Apr 15, 2013

Practicing in VM. My question is, I deleted the physical files of the database on Sunday but I'm having physical files backup on Friday. firstly i done restore, Performing incomplete recovery , I'm getting error like "Cannot open Archive log"

On Saturday, I changed path of archive log but I'm not aware of archive previous path location. How can we find previous path location of archive log?

View 6 Replies View Related

Forms :: Retrieving Previous Record Value Of Same Item In A Block

Jul 17, 2012

I am creating a record with the items - S_No, Product_Name, Selling_Qty, Price.

Checking the total qty (Tot_Qty) from the purchase stock - table1 and already sold out qty (Sold_Qty) of the product from table2.

Consider the following values: Tot_Qty = 200; Sold_Qty = 50;

Now i create a first record of the form as follows: here on selecting the Product_name from LOV, will display the Selling_Qty item - which can be edited (Selling_Qty = Tot_Qty - Sold_Qty) and its price.

S_No Product_Name Selling_Qty Price
1. KeyBoard 50(150) 200
2. KeyBoard 30(150) 200
3. KeyBoard 50(150) 200

Note:
[value given within () are displayed automatically after selecting the prod]

My prob is, when i am entering next record, it displays the same 150 as qty, which have to be 100. After selecting the product from LOV, it should calculate & validate as shown below: which means, previous record value of Selling_Qty also have to be subtracted and displayed.

S_No Product_Name Selling_Qty Price
1. KeyBoard 50(150) 200
2. KeyBoard 30(100) 200
3. KeyBoard 50(70) 200

Is there any built-in functions to retrieve previous record value?

View 6 Replies View Related

SQL & PL/SQL :: Return Most Recent Record Previous To Start Date?

Nov 18, 2011

I have a sub query (already dervived from several other tables) that has a list of children in with the date they started their course (tableofchildren). Child IDs may be duplicated in this query but each record will have unique start dates per child ID.

I have a second sub query which lists workers involved with the children in the first query (tableofworkers). A worker may be responsible for more than one child but has the unique child in the record to identify involvement with the child.

I need to join these queries together to return the child's record with the WorkerName and the AllocatedStartDate of the worker who was most recently involved with the child prior to the date (EnteredCourseDate) the child started their course (OutputWanted) - the worker associated with the child when they started their course.

A couple of points - I need to deploy this into another reporting application that doesn't support cursors etc or the 'With' operator. Also, I tend to join tables/queries in the Where clause so if it's possible that way that would be great.

OC.
create table tableofchildren
(ChildID varchar(20),
ChildName varchar (50),

[Code].....

View 13 Replies View Related

Server Administration :: Find Out Difference Of Data For Some Tables Between Current And Previous Day

May 26, 2011

We want to find out difference of data for some tables between current day & previous day. We can use query with minus operation but it will take lot of time since table size is in range from 200 to 500 GB. We have to do this exercise every day.

View 5 Replies View Related

SQL & PL/SQL :: Update Previous Row Based On Next Row And Update Duplicate Record

Mar 6, 2013

create table test1

( ID NUMBER(11)
,MEMBER_NMBR NUMBER(10)
,CODE_NMBR NUMBER(7)
,ROW_EFCTV_DT DATE
,ROW_TRMNTN_DT DATE

[code]....

insert into test1 values (11007,7462,32,'30/sep/2012','31/dec/9999',3,'25/sep/1998','AUTUMN',1,0,344);
insert into test1 values (11007,7462,32,'30/oct/2012','31/dec/9999',3,'25/sep/1998','AUTUMN',1,0,344);
IDMEMBER_NMBRCODE_NMBRROW_EFCTV_DTROW_TRMNTN_DTFLAG_NMBRBRTH_DTNAMECLAIM_CDAMT1AMT2
1100774623209/30/2012 00:0012/31/9999 00:00309/25/1998 00:00AUTUMN10344
1100774623210/30/2012 00:0012/31/9999 00:00309/25/1998 00:00AUTUMN10344

I have to update the row_trmntn_dt of first row to row_efctv_dt of 2nd row which is 30th Oct 2012 - 1 day i.e. 29th Oct 2012

View 10 Replies View Related

SQL & PL/SQL :: How To Find Which Record Is Inserted First

Mar 25, 2010

I have a table with lot of records.In this table, how do I find, which record is inserted just before a record in my question.

consider this example..
SQL> desc test1
Name Null? Type
------------------------------- -------- ----
SEQ_ID NUMBER
NAME VARCHAR2(1)

[code]....

in the above data, if I want to know what record is inserted before "1018", how can I find it.

Can we find out based on ROWID.?

View 13 Replies View Related

How To Find Last Inserted Record In A Table

Oct 5, 2010

I have a table where there is no sequence maintained and there is no time stamp column to track the inserted record.How do I find the latest inserted record in the table.

View 5 Replies View Related

SQL & PL/SQL :: Query To Find Number Of Nulls For Each Record

Aug 18, 2013

We have data as below in the table. I need the to display the records in the order based on number of NULL values and position for each record.

provide a simple query using case in ORDER BY clause.

ID CLASS NAME DIST_ID DIST_NAME
0 NULL KIRAN 0 AP
0 C1213 NULL 0 AP
0 NULL NULL 0 AP
NULL C1234 NULL 0 AP
0 NULL NULL 0 AP
NULL NULL NULL NULL NULL
0 C123 RAJESH 0 AP
NULL C123 RAVI NULL AP

We have to give the rank based on NULL values and NULL value column position.Let us assume column positions as

1 2 3 4 5
ID CLASS NAME DIST_ID DIST_NAME

for the following three records number of NULL values are same. but positions are different.

0 NULL NULL 0 AP
NULL C1234 NULL 0 AP
0 NULL NULL 0 AP
NULL C123 RAVI NULL AP

Based on the column positions the ranks as
2*2+3*3=13
1*1+3*3=10
2*2+3*3=13
1*1+4*4=17

Which is having high rank (greatest number) that record should come last . The record which is having all values that should come first. The record which is having all NULL values should come last. The out put I want as

ID CLASS NAME DIST_ID DIST_NAME
0 C123 RAJESH 0 AP
0 NULL KIRAN 0 AP
0 C1213 NULL 0 AP
NULL C1234 NULL 0 AP
0 NULL NULL 0 AP
0 NULL NULL 0 AP
NULL C123 RAVI NULL AP
NULL NULL NULL NULL NULL

View 15 Replies View Related

SQL & PL/SQL :: Find The Time Of A Record Inserted Into Table

Oct 20, 2010

I have a table which is getting populated from a source. I dont have a time-stamp column in the table. Is there anyway to find the time when a record was inserted into the table?

View 3 Replies View Related

Forms :: How To Find Sum Of Item From Multi-record Block

Apr 21, 2010

i have form have one multi record block and sing record block. In multi record block having an item namely Excise_value. I want to find the sum of total Excise_Value for all the record. How to accomplish this.

PS: I want to use the Formula/summary property in forms

View 2 Replies View Related

Forms :: Populating Values To Record Group From Multi Record Datablock

Jul 26, 2012

My procedure proc_ex is in when_validate_item trigger

I have one Multi Record data block in my form with values in its items

I need to Populate multi record block values to one Record Group using

add_group_row,
add_group_column,
set_group_char_cell to populate values to record group

Let us suppose my multi record data block looks like

item1 item2 item3 item4
10 20 50 70
25 15 30 45
45 90 47 38
75 25 85 90
30 56 78 80

how to populate these multi record datablock values to Record Group ???..Eagerly waiting for your Replies

View 3 Replies View Related

SQL & PL/SQL :: Query For Previous Day And Day Before

Jan 15, 2013

The main condition in SQL is like this.

SELECT TO_DATE (TO_CHAR (doc_date, 'MON-YY'), 'MON-YY') "INV_MTH",
SUM (inv_amt) INV_TOTAL
FROM table_x
WHERE doc_date BETWEEN TRUNC (SYSDATE, 'YYYY')
AND LAST_DAY (
ADD_MONTHS (TRUNC (SYSDATE, 'YYYY'), 11)
);

My Output from if run in JAN as of now 16 Jan.

INV_MTHINV_TOTAL
Jan-136260830.42

I want an sql until previous day of that month for example 15 Jan and another sql until day before previous day of that month for example 14 Jan.

View 15 Replies View Related

SQL & PL/SQL :: Get Previous Value Of Rows?

Dec 29, 2010

How to get the previous value of row with calling function to add value in SELECT statement for the row value.

Consider the example Table A1 having column a with values 1,NULL,NULL,NULL

SELECT CASE WHEN a IS NULL THEN (prev_row_value+function_return_Value) ELSE a END as A from A1

And my result-set should be like

a
----------------------
1
1+(Return Value Of Function)
Prev_Row_Value+(Return Value Of Function)
Prev_Row_Value+(Return Value Of Function)
Below is sample code but doesn't fulfill my criteria

[code]....

Output is

A A2
---------------------------
1 1
3
3
3

View 8 Replies View Related

SQL & PL/SQL :: How To Know Previous Scn Number

Jun 4, 2012

i want to know the all scn number's that are generated yesterday or in any previous day? how can i achieve it?

View 5 Replies View Related

PL/SQL :: Multiply With Previous Row Value?

Aug 21, 2012

i need to multiply with previous row value?

my table have about to 100 columns and lakhs of rows

Ex:

date adj
------ -----
8/21/2012 1
1/1/2012 1
12/1/2011 0.5
8/1/2011 0.5

[code]....

My requirement is multiply the existing adj by adj

adj value coming as 0.5
present year always 1

Ex:

date adj
------ -----
8/21/2012 1
1/1/2012 1
.
.
12/1/2011 0.5
8/1/2011 0.5

[code]....

View 8 Replies View Related

Server Utilities :: How To Associate Header Record To Its Corresponding Detail Record

May 16, 2012

I am loading data file using SQL Loader in TOAD 10.5.1.3 in Oracle 10g using the control file below and loading data into 2 tables post1.thead and post1.tdetl. THEAD contains item level transaction and TDETL is detail level when a transaction has a discount or promo attached to for that item. When the

LOAD DATA
APPEND
INTO TABLE post1.thead
WHEN (1:5) = 'THEAD'
TRAILING NULLCOLS
(file_type POSITION(1:5)CHAR,

[code]....

A particular THEAD value may have 0, 1 or many TDETL corresponding values.below is a sample data file. When the position 21 in the TTAIL has a value of 1 or 2, then we know that there is a promo or discount applicable to the ITEM (THEAD).

THEAD0000000002201109142011091400000000000002091 1 0 -1
TTAIL0000000003000000
THEAD0000000012201109142011091400000000000002091 1 0 -1 20110914-1
TDETL0000000013CMPSPL1004 0 000000010000P0000000000000019990000000000000000200000
TTAIL0000000014000001
THEAD0000000021201109142011091400000000000002091 1 0 -1
TDETL0000000022EMPDSC1005 0 000
TDETL0000000023SCOUP 1006 0 973452 000
TTAIL0000000024000002

What I want to acheive is to accurately reflect a TDETL to its corresponding THEAD, as both THEAD and TDETL are loaded into separate tables. How can we have the 2 records correlated?

View 11 Replies View Related

PL/SQL :: Selecting Single Record From Multiple Record Based On Date?

Aug 26, 2013

I have a table which contains the multiple records for single ID No. Now i have to select single record which contains the latest date. here is the structure Name  

Null Type  ------ ---- ------------ ID_P        NUMBER       NAME_P      VARCHAR2(12) DATE_P      TIMESTAMP(6) Records---------------------1 loosi     22-AUG-13 01.27.48.000000000 PM1 nammi  26-AUG-13 01.28.10.000000000 PM2 kk        22-AUG-13 01.28.26.000000000 PM2 thej      26-AUG-13 01.28.42.000000000 PM 

now i have to select below 2 rows how can write select qurie for this?

1 loosi 26-AUG-13 01.27.48.000000000 PM2 thej  26-AUG-13 01.28.42.000000000 PM

View 4 Replies View Related

Client IP Of Previous Transaction

Mar 11, 2013

Is it possible for me as a DBA to find IP address of the client who ran a specific transaction or query in past?

Oracle server version I'm using is 11g.

View 4 Replies View Related

SQL & PL/SQL :: Executing Rows With Previous Row

Nov 3, 2010

i have tablestructure like this

empno ename sal
1 sam 1000
2 tom 2000
3 ric 3000
4 mac 4000
5 doy 5000

i want TO WRITE SELECT QRY WHICH WILL GO like this

empno ename sal prevemp prevename presale
1 sam 1000 0 0 0
2 tom 2000 1 sam 1000
3 ric 3000 2 tom 2000
4 mac 4000 3 ric 3000
5 doy 5000 4 mac 4000

means when each current row executes it shld show details from previous row also means when details of tom is executing it also shows sam details

View 4 Replies View Related

SQL & PL/SQL :: Cumulative Sum Of Previous Row In Same Column?

Jun 28, 2013

Is it possible to get cumulative sum of the same column? I am trying to get a value for COL6... it is dependent on the values of previous row

COL6 Formula:

IF COL2 = 'A' THEN
IF 100 - [SUM_COL6] > COL5 THEN
COL5
ELSE
(TRUNC(100 - [SUM_COL6] / COL4) )* COL4
END IF

[code]....

View 6 Replies View Related

SQL & PL/SQL :: Getting Data From Previous Month

Mar 8, 2011

I need to get data from a table in which dates is equal from previous month. The dates in this table has a formula DD-MMM-YY (CRE_DTTM is the name for date column).

I've already achieve getting data from the previous month by using this formula:

(to_char(CRE_DTTM,'MON')) = UPPER(to_char(add_months(trunc(sysdate,'MONTH'),-1), 'Mon'))

My problem now is what if the current month is for example JAN 2011.. I need to get the data from DEC 2010. How can I query the previous year in this case?

View 10 Replies View Related

Forms ::create History Record For Each Record Whether Updated Or Not

Sep 13, 2011

I have a fairly standard Purchase Order form which contains pre-loaded data (been uploaded from an XML file).When the Purchase Order is processed, the form updates a Price History table only if the Price on the PO_Details changes.The code for updating the price history table is contained in a PRE_UPDATE trigger on the PO_Details Data Block.

No other data changes on the PO_Details table.I now want to change this so that the Price History table is updated even if the price does not change i.e I want to create a history record for each record on the PO_Details irrespective of whether it was updated or not.

Is there an alternative trigger that I can move my code to (ie move it from PRE_UPDATE) to some other trigger that is fired for each PO_Details record even if there is no change.

View 4 Replies View Related

SQL & PL/SQL :: Create A Query That Returns Record By Record A Field

Apr 21, 2010

I have the following case to solve:

Example Table:

Nr_ordPos1Pos2Itemqty
O4018510000107 170,00
O4018520000107 30,00
O40651010000107 500,00
O40651020000107 50,00
O4114510000107 300,00
O31141010000107 50,00
O3114520000107 50,00

I need to create a query that returns record by record a field qty_progr with the cumulate qty considering previous records. The result should be the following:

Nr_ordPos1Pos2Itemqty qty_progr
O4018510000107 170,00 170,00
O4018520000107 30,00 200,00
O40651010000107 500,00 700,00
O40651020000107 50,00 750,00
O4114510000107 300,00 1050,00
O31141010000107 50,00 1100,00
O3114520000107 50,00 1150,00

View 8 Replies View Related

Forms :: Only New Record Have Saved Last Record No Longer Exist

Jun 29, 2013

I create a data block on a table when I am inserting new record only one record have been saved. Last record no longer exist.

View 4 Replies View Related







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