Home » SQL & PL/SQL » SQL & PL/SQL » creation_date should be equal to update_date
creation_date should be equal to update_date [message #606841] Wed, 29 January 2014 23:35 Go to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Can you please provide, suppose i have 2 tables xxc_worktab_temp, xxc_header_tab, i have creation date column in the temp table & update date column in the Header table.

So my requirement is ,creation_date should equal to the update_date.Please provide query

Thank you very much if you are helpful to me.


[#1 SPLIT by LF from How to get back purged data into the tables]
[#2 SPLIT by LF from How to store the table data(Backup)
[#3 LF MERGED #1 & #2]

[Updated on: Thu, 30 January 2014 11:37] by Moderator

Report message to a moderator

Re: How to get back purged data into the tables [message #606842 is a reply to message #606841] Wed, 29 January 2014 23:42 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/
Re: How to get back purged data into the tables [message #606857 is a reply to message #606842] Thu, 30 January 2014 02:21 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
How is your last question related to the original problem?

Write an UPDATE statement, such as
update temp_table t set
  t.creation_date = (select h.update_date
                     from header_table h
                     where h.id_column = t.id_column
                    )
where exists (select null 
              from header_table h1
              where h1.id_column = t.id_column
             )

[Updated on: Thu, 30 January 2014 02:21]

Report message to a moderator

Re: How to get back purged data into the tables [message #606871 is a reply to message #606857] Thu, 30 January 2014 05:22 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Thank You Littlefoot it is working fine.. Smile
Re: How to get back purged data into the tables [message #606876 is a reply to message #606857] Thu, 30 January 2014 05:56 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Hi Littlefoot,

UPDATE regal.regal_om_edi850_worktab_temp a
SET a.creation_date = (SELECT b.creation_date 
FROM regal.regal_om_edi850_header_tab b
WHERE a.original_system_reference = b.original_system_reference)
WHERE EXISTS (SELECT b.creation_date 
FROM regal.regal_om_edi850_header_tab b
WHERE a.original_system_reference = b.original_system_reference)	


I got ORA-01427: single-row subquery returns more than one row
I ran the above it is working fine for me in vision & not worked at my client server.Please suggest me
Re: How to get back purged data into the tables [message #606878 is a reply to message #606876] Thu, 30 January 2014 06:06 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
WHERE clause needs to be adjusted. The way you wrote it, it doesn't make the SELECT statement return only 1 record. Alternatively, try to add SELECT DISTINCT into subqueries or switch from "=" to "IN", maybe it'll help.
Re: How to get back purged data into the tables [message #606884 is a reply to message #606878] Thu, 30 January 2014 07:46 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Hi Littlefoot,

I ran the below query i got 16,22,000 records.
SELECT a.creation_date             hdr_c_date, 
       b.creation_date             worktab_c_date, 
       a.original_system_reference hdr_ori_sys_ref, 
       --    b.original_system_reference worktab_ori_sys_ref, 
       a.tprt_number               hdr_tpt_num, 
       b.tprt_number               worktab_tpt_num 
FROM   regal.regal_om_edi850_header_tab a, 
       regal.regal_om_edi850_worktab_temp b 
WHERE  a.original_system_reference = b.original_system_reference 
AND a.tprt_number = b.tprt_number


I wrote same query using cursor for loop but i got only 1400, why not shows 16,22,000 records,

DECLARE 
    CURSOR c1 IS 
      SELECT a.creation_date             hdr_c_date, 
             b.creation_date             worktab_c_date, 
             a.original_system_reference hdr_ori_sys_ref, 
             --    b.original_system_reference worktab_ori_sys_ref, 
             a.tprt_number               hdr_tpt_num, 
             b.tprt_number               worktab_tpt_num 
      FROM   regal.regal_om_edi850_header_tab a, 
             regal.regal_om_edi850_worktab_temp b 
      WHERE  a.original_system_reference = b.original_system_reference 
             AND a.tprt_number = b.tprt_number; 
--AND a.original_system_reference LIKE 'JCP01-100009670-03440269-94656' 
BEGIN 
    FOR crec IN c1 LOOP 
        dbms_output.Put_line('TPRT Number: '                ||crec.hdr_tpt_num     ||' ' ||
                              'original system reference : '  ||crec.hdr_ori_sys_ref  ||' ' ||
                              'Header Creation date : '       ||crec.hdr_c_date ||' ' ||'  '||
                              'Worktab creation date : '      ||crec.worktab_c_date); 
    /*UPDATE regal.regal_om_edi850_worktab_temp 
    SET creation_date=CREC.hdr_c_date 
    WHERE original_system_reference = CREC.original_system_reference 
    and a.tprt_number = b.tprt_number; 
    */ 
    END LOOP; 
END; 


Please help me.
Re: How to get back purged data into the tables [message #606885 is a reply to message #606884] Thu, 30 January 2014 08:03 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
how are you determining how many rows the loop returns?
Re: How to get back purged data into the tables [message #606891 is a reply to message #606884] Thu, 30 January 2014 08:41 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
mist598 wrote on Thu, 30 January 2014 19:16
I ran the below query i got 16,22,000 records.

I wrote same query using cursor for loop but i got only 1400, why not shows 16,22,000 records,


The query is same in both SQL and PL/SQL code, however, the dbms_output which you have used to determine the number of rows makes the output different.

If you want to know the count of records looped, take a variable, increment it by 1 in the loop and display it through dbms_output.
creation_date should be equal to update_date [message #606897 is a reply to message #606841] Thu, 30 January 2014 09:08 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
Hi all,
First of all sorry it was my mistake.

I have another requirement .I want to update the creation date in oe_orders_lines_all table with creation_date of oe_order_headers_all .Can you send the update statement code or cursor to update.Please help me.

SELECT a.creation_date             header_c_date, 
       b.creation_date             lines_c_date
FROM   oe_order_headers_all_bkp a, 
       oe_order_lines_all_bkp b
where  a.header_id = b.header_id
and a.creation_date is not null
       
       
update oe_order_lines_all_bkp
set creation_date=sysdate
       
update oe_order_lines_all_bkp a
set a.creation_date=(select creation_date from oe_order_headers_all_bkp b where a.header_id = b.header_id)




Cursor for loop
declare
CURSOR C1 
IS
SELECT a.creation_date             header_c_date, 
       b.creation_date             lines_c_date
FROM   oe_order_headers_all_bkp a, 
       oe_order_lines_all_bkp b
       where  a.header_id = b.header_id ;
BEGIN
FOR CREC IN C1 LOOP
dbms_output.put_line('Headers Creation Date: '||crec.header_c_date||' '||'Lines C Data  : '||crec.lines_c_date);
update oe_order_lines_all_bkp a
set a.creation_date=(select creation_date from oe_order_headers_all_bkp b where a.header_id = b.header_id);
END LOOP;
end;


Please help me.
Thank You
Re: How to store the table data(Backup) [message #606898 is a reply to message #606897] Thu, 30 January 2014 09:12 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
You already have a separate thread for this, and you need to answer my question in it.
Re: How to store the table data(Backup) [message #606899 is a reply to message #606897] Thu, 30 January 2014 09:13 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
http://en.wikipedia.org/wiki/Plonk_(Usenet)
Re: How to store the table data(Backup) [message #606900 is a reply to message #606897] Thu, 30 January 2014 09:15 Go to previous messageGo to next message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
No offense here mist, but you seem woefully out of your depth. The posts that you have recently been posting show that you are being asked to perform work that you currently do not have the skillset to approach. The main issue around this is that you could very well be given code that seems to do what you need, but further down the line will turn out to be wholly inappropriate and potentially damaging (depending upon how you implement). Can I respectfully suggest that you raise, as an issue, with your line manager that you simply don't have the skillset at the moment to be able to handle the work that you are being given which is likely to result in a disaster for your company/ customer and that you really need to be either sent on a training course, or at least given some time to get up to speed with the basics of SQL and PL/SQL.
Re: How to get back purged data into the tables [message #606901 is a reply to message #606891] Thu, 30 January 2014 10:02 Go to previous messageGo to next message
mist598
Messages: 1195
Registered: February 2013
Location: Hyderabad
Senior Member
I want to update the creation date in oe_orders_lines_all table with creation_date of oe_order_headers_all .Can you send the update statement code or cursor to update.Please help me.
Re: How to get back purged data into the tables [message #606910 is a reply to message #606901] Thu, 30 January 2014 11:40 Go to previous messageGo to next message
Littlefoot
Messages: 21807
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
mist598, will you, PLEASE, stop creating mess on this forum? If you have a question, open a topic and it will be discussed. If you have another question - which is not related to the previous one - do NOT ask it in the first topic - open a new one instead.

I'm kind of getting tired of splitting & merging your messages all over the forum, so I'd really appreciate if you consider my request.
Re: How to get back purged data into the tables [message #606911 is a reply to message #606901] Thu, 30 January 2014 11:41 Go to previous message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
I will bet that nobody, except you, can perform the task. Please go through the entire thread, understand the context and then come up woth your try.
Previous Topic: exam seating plan & datesheet
Next Topic: Row number for null
Goto Forum:
  


Current Time: Fri Apr 19 01:28:39 CDT 2024