SQL & PL/SQL :: Updating Table With Latest Record

Mar 17, 2011

DROP TABLE TESTING CASCADE CONSTRAINTS;
CREATE TABLE TESTING
(
DATAPERIOD DATE,
EMPLID VARCHAR2(20 BYTE),
B_OS_REASON VARCHAR2(9 BYTE)
)
TABLESPACE USERS;

[Code] ........

SQL> select * from testing order by 1;

DATAPERIO EMPLID B_OS_REAS
--------- -------------------- ---------
01-OCT-10 2387972
01-NOV-10 2387972
01-DEC-10 2387972 XXXXXX
01-JAN-11 2387972
01-FEB-11 2387972

In the above result, We need to go from bottom up and when we hit some value we need to update with the lastest record as below.("Blank" space are considered as null.)

DATAPERIO EMPLID B_OS_REAS
--------- -------------------- ---------
01-OCT-10 2387972
01-NOV-10 2387972
01-DEC-10 2387972 XXXXXX
01-JAN-11 2387972
01-FEB-11 2387972 XXXXXX

View 5 Replies


ADVERTISEMENT

SQL & PL/SQL :: How To Select Latest Updated Record From Table

Sep 21, 2011

I want to know like How we can select the latest updated record from xyz table. that record has STATUS column. I also want to check if the status is RED or GREEN query should return if the status is red then 1 and if the status is GREEN then it should return 0

View 8 Replies View Related

Forms :: Updating Skills From Oracle Developer 6 To Latest

Oct 17, 2012

I have not used Oracle Forms and Reports for some time. The last version I used was Developer version 6.

Has there been major changes between Oracle Developer version 6 and Oracle Developer version 11 or is Oracle Developer basically the same with some incremental improvements? What would be a good way to update my skills from Oracle Developer version 6 and Oracle Developer version 11?

View 1 Replies View Related

SQL & PL/SQL :: Getting Latest Record From Different Tables?

Feb 4, 2011

I tried to post this issue earlier but it was not very clear. Well. Let me try to put in more better way.I have four tables storing order & customer information.

For given order number and cust _id I need to display latest record. here are my four tables.

SQL> select * from so;
ORD_NO ORD_DATE CUST_ID
---------- --------- ----------
1 01-JAN-10 10
2 02-JAN-09 20
3 03-FEB-11 30

SQL> select * from sol;

FK_ORD_NO FK_CUST_ID CUST_NAME LOCATION
---------- ---------- ------------------------- ----------
1 10 abc MA
2 20 xyz CA
3 30 ijk LA

[code]...

There will be a stored procedure that will take order_no and cust_id as input paremeters and return out ref cursor.

create procedure P1( in_ord_no in number,
in_cust_id in varchar2,
out_cur out sys_refcursor);

Here is the expected output.

Case 1 - in_ord_no =4 , in_cust_id = 10
Expected output - Empty cursor. Because bothe tables does not have matching record.
Case 2- in_ord_no = 3 in_cust_id = 30
Expected output =

[code]...

View 7 Replies View Related

SQL & PL/SQL :: How To Get Latest Record In Embedded Select Statement

Mar 12, 2013

I am trying to run an Oracle report with a query that has an embeded sql. this sql is returning more than 1 row, and the report is failing.

I need to pick the latest record entered that this sql return.

I tried rownnum and it works but only i can get the rown num I specify, not the latest record. I try to order, but I am getting an error back.

select w.emp_no, (select t.timestamp
from tob.work_unit t
where t.work_date = to_date('20130312', 'YYYYMMDD')
and rownum = 1
order by t.timestamp desc)
,w. spare_type
from work.work_unit w
where w.work_date = to_date('20130312', 'YYYYMMDD')

I am getting missing right parenthesis at the order by keyword My report is much complex than this, but I am tring to see if I can get the row that I want.

View 10 Replies View Related

Reports & Discoverer :: Pick Latest Record Rank And Count?

Sep 1, 2010

Am working on a workbook to count the number of enrolments and withdrawals in the program. My data looks like this

name semester status year
A 1 enrol 2010
A 2 withdraw 2010
A 3 enrol 2010
B 1 enrol 2010
B 2 withdraw 2010

I want to count their latest status only. It should come up with
Total Enrol - 2
Total Withdrawn - 1

For total Withdrawn, I tried 'rank' and filter to equals 1 but it does not allow me. Is there any way to have this work?
Here's my calculation:(decode((FIRST_VALUE(status) OVER(PARTITION BY year, name ORDER BY semester DESC)),'withdraw', name)) It tells me that 'Aggregation of Analytic function not allowed'

View 3 Replies View Related

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 :: To Retrieve Only Latest Repair Information Based On Latest Date

Apr 3, 2012

I would like to retrieve only the latest repair information based on the latest date regardless of the other information, so I would like to query only items 3 and 5 in the following example.

drop table a;
create table a(
seq number,
custom_id number,
repair_id number,
repair_date date);
[code]........

View 10 Replies View Related

Forms :: Updating A Record In A Cursor?

Mar 3, 2012

when I updated a record in my form check my screenshot: and clicked save button the result was:

as you can see in the message at the bottom, it has 18 records. And since my original data(subjects) are just 9. And also the grades that I input didn't display all.

This is my code in when-new-block-instance trigger:
DECLARE
CURSOR studgrade_cur IS
SELECT e.student_id, s.subject_code --, g.grade

[code]...

View 39 Replies View Related

Forms :: Updating Record Must Be Exception To Query

Jan 31, 2013

SELECT COUNT(*)
INTO v_ctr
FROM leave_type_govt_service
WHERE (
:block_name.min BETWEEN minimum AND maximum
[code]......

This code in my forms really works for inserting a new record. But if I will update the record itself for example, in the table 'Type 1'

Minimum Maximum
1 5
6 10
11 15

and I will update the 6 - 10 to e.g. 7, It must update but my query includes 6 - 10 data so it raise the trigger failure.

Note: The AND condition in the last part is for unique types. Because even if e.g. 'Type 2' has a Min and Max data same as the 'Type 1' the trigger will not prompt.

View 1 Replies View Related

Avoid Updating Record If Columns Do Not Change?

Nov 29, 2012

is there any possibility or hint to avoid updating record if columns do not change? For example, I have UPDATE:

UPDATE MY_TABLE SET COLUMN_A = 'ABC' WHERE COLUMN_B = 12

if the value in COLUMN_A is 'ABC' I do not want to do this update. Of course I can add in WHERE 'AND COLUMN_A<>'ABC' but when I am updating a lot of columns it will be annoying

View 1 Replies View Related

Retrieving Max / Latest Date From A Table With A Join To One Another Table

Sep 19, 2011

I am having trouble retrieving the Max, latest date, from a table with a join to one another table and other fields from both.I was able to get the MAX service_date grouped by id. But once I tried to add more fields to the query and another table it won't work.

Here is what I have:

selectMAX(cs.service_date), cs.notes, cs.applicant_id,wr.program_code,wr.last_name,wr.first_name,wr.region_code,wr.status_cd
from cs join wr on cs.applicant_id=wr.applicant_id
where wr.status_cd='AC'
group by cs.applicant_id

View 3 Replies View Related

Forms :: Lock Record When Two Users Updating Existing One At Same Time

Aug 22, 2013

I am using Forms 6i and developed a Master Detail Oracle Form for Oracle EBS 11i application.

I was asked to write a pl/sql program so that.. When a user updating an existing record at the same time another user query the same record and try to update the same time, the record should be locked and a message should popup saying the record is being updated by another user.

View 2 Replies View Related

Application Express :: Updating Record As Apex_public_user instead Of Login User?

Sep 9, 2013

I have created an application as database authentication.In the application, I  have developed a screen based on a tabular form,when I try to update a  record ,the record is updated with apex_public_user insted of the database login. 

View 3 Replies View Related

How To Export Latest N Records From A Table

Jul 2, 2012

How to export latest n records from a table using the below query(latest n records)

select * from (select empid,ename,sal,joining_date from emp order by joining_date desc) where rownum<n;

View 3 Replies View Related

SQL & PL/SQL :: Retrieving Latest Create_date And Pay_total For Each Act_id From Table?

Apr 19, 2010

I am trying to retrieving the latest create_date and pay_total for each act_id from the table. Table is having more than 5000000 records. I prepared the below query but it didn't the data even after 6 hours.

select a.act_id,a.create_DATE,a.Pay_TOTAL
from payment_tab a
where 1 = (select count(distinct b.create_DATE)
from payment_tab b
where b.act_id=a.act_id
and
b.create_DATE >= a.create_DATE)

i cannot create the indexes on this table.

View 11 Replies View Related

Updating Table With Same Key?

Nov 19, 2008

I am using oracle 9i, and having trouble with updating a table.

I get ORA-00001(unique constraint) Error on executing the sql below; I know sql below is little strange( which use unique key in 'SET' statement) . but It worked on My Oracle Server. but it didn't on Client's.

why this error occurs or why this error did not occur on my PC,

[Update sql](key is CD and SDATE)
Update TBL1
set CD = 'A',

[Code]....

View 4 Replies View Related

Updating Two Table Via SQL Loader

Jun 27, 2011

I am trying to write a control file that will read information from two INFILES and update two tables with the different information via SQL Loader. I am using Oracle 11g on Linux. i am not sure how to take the result from the first insert query and use it as input to the second insert query. Currently I have the following control file:

LOAD DATA
INFILE 'table1.dat'
INFILE 'table2.dat'
APPEND
INTO TABLE table1
WHEN tid='1'
FIELDS TERMINATED BY ","
OPTIONALLY ENCLOSED BY '"'
(pid "pid.nextval", p_fname, p_lname, tid)
[code]....

The pid in the second insert query should be taken from the pid generated in the first insert query. However, I do not know how to do this. Does SQL Loader run the first insert query for all entries in the table1.dat file and then the second insert query or will it do one record at a time? Here are my INFILES:

table1.dat
,John,Doe,1
,Joe,Smith,1

table2.dat
10,,abc,1,
11,,xyz,1,

The second field in table2.dat should be taken from the result of creating a record in the table1.dat. Is this something that can be achieved using SQL Loader? The first part of the control file is successful, I can see the table being updated with the contents on table1.dat, but the second query fails.

View 1 Replies View Related

SQL & PL/SQL :: Trigger Updating Second Table With PK Value

Oct 20, 2011

Oracle 11.2 - The goal is to create a trigger on table and anytime an update, delete or insert is done on the table, write values to a second table. I have the trigger and it works except it is not loading my col1/PK values. I understand I need to do a new/old value. Col1 is my PK on Table that I want to load anytime there is an update/delete/insert on the table. How do I code the old/new variable?

My
CREATE OR REPLACE TRIGGER TRIGGER_NAME
AFTER INSERT OR UPDATE OR DELETE
ON TABLE_NAME
FOR EACH ROW
DECLARE
v_col1 TABLE_NAME.COLUMN%TYPE;
BEGIN
[code]...

View 5 Replies View Related

Updating A Table Column Which Is XML Datatype

Nov 1, 2011

I am updating a table column which is xml datatype and am getting above error.Below is the process what i did. since the xml is too large i split them into small chunks.

DECLARE
conditionXML CLOB;
ls_xml_2 Clob;
ls_xml_3 clob;
ls_xml_4 Clob;
ls_xml_5 Clob;
ls_xml_6 clob;
ls_xml_7 Clob;
[code]...

View 1 Replies View Related

SQL & PL/SQL :: Updating Fields Of History Table

Aug 25, 2011

pgit_policy is transaction table having producer code field.

pgith_policy is history table, on that table if any endorsement passed new records created with same polh_sys_id and increment on POLH_END_NO_IDX.

I am trying to update all records of the history table but its updating only higest POLH_END_NO_IDX only. i need to update all producer code.

update pgith_policy a
set a.polh_producer_code= (select b.pol_producer_code
from pgit_policy b
where b.pol_no=a.polh_no
--and b.POL_END_NO_IDX= a.POLH_END_NO_IDX and b.POL_END_SR_NO = a.POLH_END_SR_NO
and b.pol_producer_code is NOT NULL
and b.pol_class_code='10')
where a.polh_class_code='10'
and a.polh_producer_code is null
and a.polh_appr_dt between to_date('01-06-2011', 'dd-mm-yyyy') and to_date('30-06-2011', 'dd-mm-yyyy')

View 4 Replies View Related

SQL & PL/SQL :: Updating Table Statistics - View Not Appropriate

Oct 22, 2010

how many rows certain tables have.

updating the statistics for a table (with GATER_TABLE_STATS) and using NUM_ROWS then. This works fine for me as long as I am the owner of the table, but when someone else is, I always get this error: ORA-20000: Table does not exist or insufficient privileges.what privileges do I need to use GATHER_ TABLE_ STATS on all Tables, which were created by Users?

when I tried to use ANALYZE TABLE TEST_TABLE COMPUTE STATISTICS on a certain table I got the following error: a view is not appropriate here. The strange thing is, TEST_TABLE is not a view (at least it is not listed in ALL_VIEWS and is listed in ALL_TABLES, so it cant be a view right?).

Besides, is there another way to gather Table Statistics (not using Analyze Table or Gather_Table_Stats)?

View 3 Replies View Related

SQL & PL/SQL :: Trigger For Updating All Columns Of A Table

Sep 12, 2013

I have created the following trigger whcich will track all the column changes and insert the row in log table. here i have some doubt while substituting the cursor value.

create or replace trigger historylog_trigger
before update on log_dev_test
for each row
declare
PRAGMA AUTONOMOUS_TRANSACTION;
in_loamid number(10);
in_col_name varchar2(10);
in_old_val varchar2(100);

[Code]..

are the below assignement of values will work ?

in_old_val:= ':old.'||r.column_name;
in_new_val:= ':new.'||r.column_name;

i want to take the coulmname from the cursor and assign tat to psuedo columns like :new.r.column_name .

View 8 Replies View Related

SQL & PL/SQL :: Updating Another Table For Equal Strings

Jun 8, 2010

There are two tables:

create table songs(song_name text, song_artist text,song_url text, song_cat text, last_edit text);
create table categories(cat_name text, cat_total int);

im trying to create a trigger that, when i insert a new song in the songs table, it will check the category of the song (song_cat) and increase the respective cat_total (from table categories) by 1.

here is what i've done so far:

drop trigger countcat;
CREATE TRIGGER countcat AFTER INSERT ON songs FOR EACH ROW
update categories SET cat_total= cat_total +1
WHERE cat_name = (select song_cat FROM inserted);

What to write in the cat_name = (select ...). I have tried lots of stuff but still nothing. when i use this, i get the error that mydatabase.inserted doesnt exist

View 4 Replies View Related

SQL & PL/SQL :: Updating A Table With A Select Statement?

Nov 8, 2011

this is the correct syntax for updating a table with a select statement included. Table created easily and the alter table ran fine, but the update is running quite a log time.

My ultimate goal is to populate the "children" field with a count of children for each household id.

create table NON_GBC_Members nologging as
select distinct hcp.household_master_ID
from mrtcustomer.household_child_profile hcp
where hcp.child_birth_dt between '31-OCT-2000' and '30-OCT-2011'
group by hcp.household_master_id
minus

[code]....

View 5 Replies View Related

Updating A Column Of A Table With 70,000,000 Records

Aug 1, 2012

I need to update column of a table with +,- 70,000,000 records.

If I perform an update it lasts......too much and does not finish!

View 6 Replies View Related

Connecting To Oracle With VB7 And Updating Table?

Jul 7, 2013

I am trying to learn Oracle and trying to use Visual Basic 7 to connect to an Oracle database, upload a text file to an empty table and then update a second Oracle table based on the info in the first table. I know you can do this with SQL*Loader, but how about VB? I did some research and found this posting: Re: Using Bulk insert or SQL Loader in VB6 I borrowed the code from there and altered it for my application (see below). 

Dim con As New ADODB.ConnectionDim rst As New ADODB.RecordsetDim rst2 As New ADODB.RecordsetDim rst3 As New ADODB.Recordset con.ConnectionString = "Provider=OracleDB;User ID=john;Password=doe;Data Source=TestDB;"con.Open 'open the text filerst.Open "C:OracleTestCombinedCombined.txt" 'rst2 is an empty recordset because TempTable is empty at this time.rst2.Open "select * from TempTable", con, adOpenDynamic, adLockOptimistic 'adding rows into TempTable.Do Until rst.EOFrst2.AddNew Array("PACKET", "DATERET"), Array(rst.Fields("PACKET"), rst.Fields("DATERET"))rst.MoveNextLoop rst.Closerst2.Closecon.Close  

My second question is this -  say I had a second Oracle table in the same DB called "MasterTable", with the same two fields as "TempTable" (PACKET and DATERET). I want to update the DATERET field in "MasterTable" with the DATERET field in "TempTable" ONLY when the "PACKET" field matches in both tables.

View 5 Replies View Related

Updating Multiple Records In A Table

Oct 29, 2012

OS:Solaris
DB:10G

I have a situation where there are multiple records for a join criteria. I am trying to find a way to update a particular column for all the records returned by the join criteria. Example :

Table A

id number

1 1000
2 2000
3 3000
4 4000

Table B

id number
1 9999
1 9999
1 9999
1 9999
1 9999
1 9999
2 8888
2 8888
3 6666
3 6666

Result after update:

Table B

id number
1 1000
1 1000
1 1000
1 1000
1 1000
1 1000
2 2000
2 2000
3 3000
3 3000

update query ? When I use a update statement with where exists it errors out because the query returns more than one row for the join condition.

View 2 Replies View Related

Converting Rows Into Columns And Updating A Table?

Apr 26, 2012

I have a table A, whose table structure is in the below format.

Table A

ID DESC VALUE
123 A 454
123 B 1111
123 C 111
123 D 222
124 A 123
124 B 1
124 C 111
124 D 44

Now i need to insert the data from this table to another table B, the sturcture of which is as below

Table B

ID A B C D
1234541111111222
124123111144

How do i frame a query to fetch data from table A and insert that into table B? I don't want to use max and decode combination. as it would return only single row for an ID. I need all the id's to be displayed.

View 1 Replies View Related

Forms :: Formula Column Value Not Updating In Table?

Sep 5, 2011

I create the sample for master/detail form. In detail for prdcode,rate,qty,amount is there. When select prdcode it fetching prdcode,rate in a record and if you type the qty the amout will come based on formula(property) :qty*:rate.

It is available on screen. But when i store the data, in backend table the amount is be a null.

View 9 Replies View Related







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