Home » SQL & PL/SQL » SQL & PL/SQL » PL/SQL loops
PL/SQL loops [message #381749] Mon, 19 January 2009 11:17 Go to next message
surf
Messages: 1
Registered: January 2009
Location: london
Junior Member
Hi i have 2 arrays , a and b
how can i compare the values for each in a loop??

Re: PL/SQL loops [message #381750 is a reply to message #381749] Mon, 19 January 2009 11:19 Go to previous messageGo to next message
BlackSwan
Messages: 25033
Registered: January 2009
Location: SoCal
Senior Member
You need to help us by following the Posting Guidelines as stated below.
http://www.orafaq.com/forum/t/88153/0/
So we can help you.
Re: PL/SQL loops [message #381755 is a reply to message #381749] Mon, 19 January 2009 11:57 Go to previous messageGo to next message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
PL/SQL User's Guide and Reference
Application Developer's Guide - Fundamentals

Regards
Michel
Re: PL/SQL loops [message #381857 is a reply to message #381749] Tue, 20 January 2009 02:33 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
Why compare them in a loop?
Why not just see if they're equal:
declare
  type tab is table of varchar2(10);
  
  t1   tab := tab();
  t2   tab := tab();

begin
  for i in 1..10 loop
    t1.extend;
    t2.extend;
    t1(i) := 'Row '||i;
    t2(i) := 'Row '||(11-i);
  end loop;
  
  if t1 = t2 then
    raise_application_error(-20001,'Match');
  else
    raise_application_error(-20001,'No Match');
  end if;
  
end;
/
Re: PL/SQL loops [message #381863 is a reply to message #381857] Tue, 20 January 2009 02:42 Go to previous message
Michel Cadot
Messages: 64103
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Well, it depends on:
- array type
- what equality means

SQL> declare
  2    type tab is table of varchar2(10);
  3    
  4    t1   tab := tab();
  5    t2   tab := tab();
  6  
  7  begin
  8    for i in 1..10 loop
  9      t1.extend;
 10      t2.extend;
 11      t1(i) := 'Row '||i;
 12      t2(i) := 'Row '||(11-i);
 13    end loop;
 14    
 15    if t1 = t2 then
 16      raise_application_error(-20001,'Match');
 17    else
 18      raise_application_error(-20001,'No Match');
 19    end if;
 20    
 21  end;
 22  /
declare
*
ERROR at line 1:
ORA-20001: Match
ORA-06512: at line 16

TABLEs match but not for the same indices (actualy TABLE has no order).

SQL> declare
  2    type tab is VARRAY(10) of varchar2(10);
  3    
  4    t1   tab := tab();
  5    t2   tab := tab();
  6  
  7  begin
  8    for i in 1..10 loop
  9      t1.extend;
 10      t2.extend;
 11      t1(i) := 'Row '||i;
 12      t2(i) := 'Row '||(11-i);
 13    end loop;
 14    
 15    if t1 = t2 then
 16      raise_application_error(-20001,'Match');
 17    else
 18      raise_application_error(-20001,'No Match');
 19    end if;
 20    
 21  end;
 22  /
  if t1 = t2 then
        *
ERROR at line 15:
ORA-06550: line 15, column 9:
PLS-00306: wrong number or types of arguments in call to '='
ORA-06550: line 15, column 3:
PL/SQL: Statement ignored

You can't do it this way for VARRAY.

Regards
Michel

Previous Topic: getting compilation errors
Next Topic: uninitialized composite
Goto Forum:
  


Current Time: Sat Dec 03 13:39:38 CST 2016

Total time taken to generate the page: 0.19754 seconds