Oracle SQL help

I have 2 tables with the below definition:
table 1:  
column 1 varchar 2
column 2 varchar2

table 2:  
column 1 varchar 2
column 2 varchar2

value in column1 is always a characters:
value in column2 can be a character or a number.

end result i expect:
the join condition is with column1 on both tables
if column 2 value is character,if the value does not match fetch the result
if column 2 values is a number, then table1,column2 <= table2.column2 ,fetch the result
eagle_eaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
I have created a function getnumber (below) to enable this easily ...

select *
  from table1 t1
  join table2 t2
     on t1.column1 = t2.column1
where  ( getnumber(t1.column2) is NULL 
          AND t1.column2 <> t2.column2
           )
    OR ( getnumber(t1.column2) is NOT NULL 
     and getnumber(t2.column2) is NOT NULL
     and getnumber(t1.column2)  <= getnumber(t2.column2)
        )   

Open in new window


here is the function code:
create or replace
FUNCTION GetNumber(txt_IN IN varchar2)
RETURN NUMBER
IS
	test NUMBER;
	res VARCHAR2(128);
BEGIN

BEGIN
  res := TRANSLATE ( txt_IN, '0123456789' , '          ');
  res := REPLACE( TRANSLATE ( txt_IN, res ,  ' ' ) , ' ', '');

  test := TO_NUMBER(res);

EXCEPTION
  WHEN VALUE_ERROR THEN test:=NULL;
END;

RETURN (test);

END GetNumber;

Open in new window

0
eagle_eaAuthor Commented:
can this be achieved without any function?
0
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you can:
select *
  from tmp_ee_1 t1
  join tmp_ee_2 t2
     on t1.column1 = t2.column1
where  ( TO_NUMBER(REPLACE( TRANSLATE ( t1.column2,  TRANSLATE(t1.column2, '0123456789' , '          ') , ' ' ) , ' ', '')) is NULL 
          AND t1.column2 <> t2.column2
           )
    OR ( TO_NUMBER(REPLACE( TRANSLATE ( t1.column2,  TRANSLATE(t1.column2, '0123456789' , '          ') , ' ' ) , ' ', '')) is NOT NULL 
     and TO_NUMBER(REPLACE( TRANSLATE ( t2.column2,  TRANSLATE(t2.column2, '0123456789' , '          ') , ' ' ) , ' ', '')) is NOT NULL
     and TO_NUMBER(REPLACE( TRANSLATE ( t1.column2,  TRANSLATE(t1.column2, '0123456789' , '          ') , ' ' ) , ' ', ''))  <= TO_NUMBER(REPLACE( TRANSLATE ( t2.column2,  TRANSLATE(t2.column2, '0123456789' , '          ') , ' ' ) , ' ', ''))
        )   
;        

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
eagle_eaAuthor Commented:
this is exactly what i was looking for, thanks a lot
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.