Home » RDBMS Server » Server Administration » How do I compare two columns in a two different table that are of type LONG?
How do I compare two columns in a two different table that are of type LONG? [message #374106] Thu, 24 May 2001 20:30 Go to next message
Khanh Hua
Messages: 7
Registered: May 2001
Junior Member
I would like to do a join between two tables on a column that is of type LONG.

I tried doing something like this:

Example:

select a.emp_id, b.dept_id from emp a, dept b
where a.dept_id = b.dept_id AND
a.desc like '%b.desc%'

but the results did not join based on the desc column between the two tables. I suspect it is because the dataType is LONG for the desc column.

Any help would be much appreciated.

Thanks
Re: How do I compare two columns in a two different table that are of type LONG? [message #374107 is a reply to message #374106] Thu, 24 May 2001 20:51 Go to previous messageGo to next message
Rakesh Goel
Messages: 8
Registered: May 2001
Junior Member
Absolutely stupid question!
Try to learn the basics of variables and strings.
Re: How do I compare two columns in a two different table that are of type LONG? [message #374116 is a reply to message #374107] Fri, 25 May 2001 10:08 Go to previous messageGo to next message
Andrew again...
Messages: 270
Registered: July 2000
Senior Member
It's not a stupid question at all! It's often required. As Long can hold up to 2 GB, it can be difficult to compare the contents, but in PL/SQL you can get up to 32k of the value into a varchar2 variable and then compare the varchar2 variable contents. I don't have an example off hand.
Re: How do I compare two columns in a two different table that are of type LONG? [message #374117 is a reply to message #374107] Fri, 25 May 2001 10:13 Go to previous messageGo to next message
Andrew again...
Messages: 270
Registered: July 2000
Senior Member
It's not a stupid question at all! It's often required. As Long can hold up to 2 GB, it can be difficult to compare the contents, but in PL/SQL you can get up to 32k of the value into a varchar2 variable and then compare the varchar2 variable contents. I don't have an example off hand.
Re: How do I compare two columns in a two different table that are of type LONG? [message #374119 is a reply to message #374106] Fri, 25 May 2001 11:01 Go to previous messageGo to next message
Sundar Venkatasubramaniam
Messages: 26
Registered: May 2001
Junior Member
first of all you are enclosing b.desc in where clause with quotes it should be
like '%'||b.desc||'%'(any how it ill work for long columns).
for your req you can try this .

Here a.desc and b.desc are long columns

set serveroutput on
declare
cursor c1 is select a.desc adesc ,b.desc bdesc,a.emp_id, b.dept_id from emp a,
dept b where a.dept_id=b.dept_id;
n number;
begin
for c2 in c1
loop
n := instr(c2.adesc,c2.bdesc,1,1);
if n > 0 then
....

end if;
end loop;
end;
/
Re: How do I compare two columns in a two different table that are of type LONG? [message #374120 is a reply to message #374106] Fri, 25 May 2001 11:02 Go to previous messageGo to next message
Sundar Venkatasubramaniam
Messages: 26
Registered: May 2001
Junior Member
first of all you are enclosing b.desc in where clause with quotes it should be
like '%'||b.desc||'%'(any how it will not work for long columns.in previous reply as usual i made typo error sorry for that.).
for your req you can try this .

Here a.desc and b.desc are long columns

set serveroutput on
declare
cursor c1 is select a.desc adesc ,b.desc bdesc,a.emp_id, b.dept_id from emp a,
dept b where a.dept_id=b.dept_id;
n number;
begin
for c2 in c1
loop
n := instr(c2.adesc,c2.bdesc,1,1);
if n > 0 then
....

end if;
end loop;
end;
/
Re: How do I compare two columns in a two different table that are of type LONG? [message #374126 is a reply to message #374106] Fri, 25 May 2001 16:28 Go to previous messageGo to next message
Khanh Hua
Messages: 7
Registered: May 2001
Junior Member
Thanks!! I got it to work. One more question. When I am comparing two string with the INSTR function, it checks to see if the string b is in string a. I am running into the problem in that I want sting b to exactly match string a.

Example:

1) INSTR ('ABC Company - Memo text', 'ABC Company', 1,1)

2) INSTR ('ABC Company - Memo text', 'ABC Company - Memo text', 1,1)

I would like only option 2 to return a value greate than zero (i.e. true) Is this possible?
Re: How do I compare two columns in a two different table that are of type LONG? [message #374182 is a reply to message #374126] Tue, 29 May 2001 14:05 Go to previous messageGo to next message
Sundar Venkatasubramaniam
Messages: 26
Registered: May 2001
Junior Member
Try this.Sorry for late replay as I came to office now only.

set serveroutput on
declare
cursor c1 is select a.desc adesc ,b.desc bdesc,a.emp_id, b.dept_id from emp a,
dept b where a.dept_id=b.dept_id;
n number;
begin
for c2 in c1
loop
--n := instr(c2.adesc,c2.bdesc,1,1);
--if n > 0 then
if c2.adesc = c2.bdesc then
....

end if;
end loop;
end;
Re: How do I compare two columns in a two different table that are of type LONG? [message #374213 is a reply to message #374126] Wed, 30 May 2001 12:54 Go to previous message
Khanh Hua
Messages: 7
Registered: May 2001
Junior Member
Thank you!!!
Much appreciated
Previous Topic: How to change Time format
Next Topic: two doubt in internet address
Goto Forum:
  


Current Time: Mon Jul 01 03:53:55 CDT 2024