Home » SQL & PL/SQL » SQL & PL/SQL » Collection Last Record (Oracle 11g)
Collection Last Record [message #653755] Mon, 18 July 2016 05:08 Go to next message
ORAGENASHOK
Messages: 240
Registered: June 2006
Location: Chennai
Senior Member
                              Open c_mrg_dtl(tc_file_dtl(i).source_id, tc_tbl_dtl(j).tbl_id, tc_tbl_dtl(j).tbl_name) ;
                              Loop
                                      Fetch c_mrg_dtl BULK COLLECT INTO tc_mrg_dtl;
                  
                                      EXIT WHEN tc_mrg_dtl.COUNT <= 0;
                  
                                      log_util.log_msg(
                                      p_msg                =>  'Inside cursor c_mrg_dtl ',
                                      p_msg_code       =>  k_msg_code||(g_msg_code_no) ,
                                      p_module           =>  v_proc_name,
                                      p_action             =>  v_subproc_name);
                  
                                      for o in tc_mrg_dtl.FIRST..tc_mrg_dtl.LAST
                                      Loop                              
                                      
                                          if ( tc_mrg_dtl(o).mrg_on_flg = 'Y') then                                                  
                                          
              [b]v_query := v_query||' '||'ss.'||tc_mrg_dtl(o).tbl_col_name||' = '||'stg.'||tc_mrg_dtl(o).stg_col_name||' '||'and' ;[/b]
                                              
                                          End if ;                                                                                                                                                                                                        
                                      
                                      End Loop ; -- End merge clause for loop end                                                                                                                  
                              End Loop ;--- End merge clause open cursor end

I have above code and am forming it dynamically. Now from the inner loop i want find last record like below

if ( last record) then
i will not appended with "and" at end of the statement.

i used LAST = COUNT it returns same value.

Any possibility to identify last record in this case?
Re: Collection Last Record [message #653756 is a reply to message #653755] Mon, 18 July 2016 05:16 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
There's a really obvious way to do this.
Think about:
What values does o have?
What value does tc_mrg_dtl.LAST have?
Re: Collection Last Record [message #653761 is a reply to message #653756] Mon, 18 July 2016 06:57 Go to previous messageGo to next message
ORAGENASHOK
Messages: 240
Registered: June 2006
Location: Chennai
Senior Member
I got it ... Thanks a lot
Re: Collection Last Record [message #653827 is a reply to message #653761] Tue, 19 July 2016 14:33 Go to previous messageGo to next message
Bill B
Messages: 1971
Registered: December 2004
Senior Member
Also a VERY easy way to do it is to add at the end of initial setup of the v_query the string 1=1 and then move the and from
the end to the beginning. Everything works perfect and the 1=1 is treated as a noop by the optimizer.

[Updated on: Tue, 19 July 2016 14:35]

Report message to a moderator

Re: Collection Last Record [message #653840 is a reply to message #653827] Wed, 20 July 2016 03:05 Go to previous message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
Or you could just use trim to remove the trailing AND.
Previous Topic: Merging BLOB
Next Topic: Logic for displaying below row as first row
Goto Forum:
  


Current Time: Fri Apr 19 12:06:12 CDT 2024