Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Join using LIKE operator [SOLVED]

Peter GjelstrupJul 23 2008 — edited Jul 24 2008

Hi,

BANNER                                                          
-------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
PL/SQL Release 10.2.0.3.0 - Production                          
CORE	10.2.0.3.0	Production                                      
TNS for IBM/AIX RISC System/6000: Version 10.2.0.3.0 - Productio
NLSRTL Version 10.2.0.3.0 - Production 

I am given a log table tlog that has a few mio records, and need to group the messages based on their pattern. My problem is that the message are not defined anywhere, so I have created my own definition in table regx. Currently, this table has 65 records and I expect it to grow to perhaps 100-200.

These are the tables:

drop table tlog purge;
drop table regx purge;

create table tlog (id number(9) primary key, msg varchar2(55));
create table regx (id number(9) primary key, pattern varchar2(55) not null unique);

insert into tlog values(1, 'Error where item = 1234');
insert into tlog values(2, 'Error where item = 2345');

insert into tlog values(3, 'Discard due to code = 123 on customer');
insert into tlog values(4, 'Discard due to code = 234 on customer');
insert into tlog values(5, 'Discard due to code = 345 on customer');

insert into tlog values(6, 'Discard due to code = 123 on vendor = 456');
insert into tlog values(7, 'Discard due to code = 234 on vendor = 567');
insert into tlog values(8, 'Discard due to code = 345 on vendor = 678');
insert into tlog values(9, 'Discard due to code = 456 on vendor = 789');

insert into regx values (100, 'Error where item =%');
insert into regx values (200, 'Discard due to code =%on customer');
insert into regx values (300, 'Discard due to code =%on vendor =%');
commit
/

select * from tlog;

select * from regx;
/

Now, I can do something like this:

select regx.id, count(*)
  from regx, tlog
 where tlog.msg like regx.pattern
group by regx.id
order by regx.id;

        ID   COUNT(*)
---------- ----------
       100          2
       200          3
       300          4
3 rows selected.       

So far so good. My problem now is that I have messages that does not fall into
any of the categories. Consider

insert into tlog values(10, 'Other kind of message');
insert into tlog values(11, 'Another kind of message');
insert into tlog values(12, 'Yet, another');
insert into regx values (400, '%');
commit
/

select regx.id, count(*)
  from regx, tlog
 where tlog.msg like regx.pattern
group by regx.id
order by regx.id;

        ID   COUNT(*)
---------- ----------
       100          2
       200          3
       300          4
       400         12 wrong! 
4 rows selected.       

The correct answer for group *400* would be 3.

Any ideas on how to handle these other messages?

Any changes to the regx table, including contents and definition is possible. Changes to tlog table is not.

Regards
Peter

Message was edited by:
Peter Gjelstrup (Added banner)

Message was edited by:
Peter Gjelstrup [SOLVED]

Comments

fac586
I would also like for the region title of certain regions to be dynamic, or rather equaling the value of some item on the page. I did some digging on Google and found that this was apparently possible in Apex 3, but I'm currently working in Apex 4.
What makes you think that these methods don't work in APEX 4.0? Did you try them?

Use the static text exact substitution method to reference the value of the page item in the region title attribute:
&P1_TITLE.
Ensure the page item value is set before the titled region is rendered (e.g. using a Before Header Computation).
860960
I tried this in Application Express 4.0.2.00.07 and it works
Chandran
Could you please give a sample code
Jozef Demovic SVK
Hi,
Here is the example.

Type something like: "Order &P4_ORDER_NR." to the TITLE of the region.
- if item P4_ORDER_NR has value of 01/2012 then the Region Title will be "Order 01/2012".

Regards
J :D
917318
jozef_SVK wrote:
Hi,
Here is the example.

Type something like: "Order &P4_ORDER_NR." to the TITLE of the region.
- if item P4_ORDER_NR has value of 01/2012 then the Region Title will be "Order 01/2012".

Regards
J :D
Hi,

I've tried to handle item value. and I got a problem.

If I use Region Title: Role Description: &P4_POSITION_ID. - it shows : Role Description: 2
but when I inserted Region Title: Role Description: &P4_POSITION. it shows only Role Description:.

where P4_POSITION_ID - is Database column with source Position_ID
while P4_POSITION - is SQL query with source select e.POSITION_NAME from POSITION e where e.POSITION_ID = :P4_POSITION_ID

As I understand problem is when page is loaded P4_POSITION_ID item handle value, but P4_POSITION is empty.
but how to solve it?
Deep_in_Texas
When does the following code executes on your page?

while P4_POSITION - is SQL query with source select e.POSITION_NAME from POSITION e where e.POSITION_ID = :P4_POSITION_ID

Thanks
Pradeep

(I changed my handle but it's still displaying the number !!!!)

Edited by: 965010 on Oct 12, 2012 7:31 AM
917318
Deep_in_Texas wrote:
When does the following code executes on your page?

while P4_POSITION - is SQL query with source select e.POSITION_NAME from POSITION e where e.POSITION_ID = :P4_POSITION_ID

Thanks
Pradeep

(I changed my handle but it's still displaying the number !!!!)

Edited by: 965010 on Oct 12, 2012 7:31 AM
I don't know when it is executed. I've just created page item P4_POSITION and made it as SQL query.

Actually, value in the P4_POSITION_ID item is from POSITION_ID in EMPLOYEE table, which contains primary key EMPLOYEE_ID and has foreign key - POSITION_ID,
POSITION_ID is a primary key of POSITION table, which contains POSITION_NAME.

What I made is I created link from page 3 using EMPLOYEE_ID to redirect to page 4. There are all items in the page 4, which are in the EMPLOYEE table. But I need to show POSITION_NAME from POSITION table. So I created page item P4_POSITION as I mentioned before.

Do I need to create dinamic action or process before handling Region title?
1030438

The value for the item you wish to include in the title must be set at "Before Header" execution point (or earlier). If you're using an automated row fetch, I think you can simply move the row fetch process to the "Before Header" execution point.

1 - 8
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Aug 20 2008
Added on Jul 23 2008
8 comments
13,572 views