How to repeat a query [message #82378] |
Thu, 22 May 2003 16:41  |
Patrick F. O'Neill
Messages: 3 Registered: May 2003
|
Junior Member |
|
|
Can someone show the code to re-run a query using
SYSTEM.LAST_QUERY
I want the user to use enter query mode to send a query and look at some data on DataBlock_1. If the user confirms that the set of records is what she wants, then she clicks a button that runs the same query to load the same rows (with additional data elements) into DataBlock_2.
How can I approach this with SYSTEM.LAST_QUERY? Or is there a different way?
Pat
|
|
|
Re: How to repeat a query [message #82380 is a reply to message #82378] |
Fri, 23 May 2003 02:19  |
 |
Maaher
Messages: 7065 Registered: December 2001
|
Senior Member |
|
|
Here's a quick example:--
-- WHEN-BUTTON-PRESSED trigger of :BLOCK1.Btn_exeqry_block2 (push button)
--
Declare
-- variable to store the last query of block1
v_where_block1 Varchar2(2000);
-- variable to store the default where of block2
default_block2 Varchar2(2000);
Begin
-- Save the default_where
default_block2 := get_block_property('BLOCK2', Default_Where);
-- Check Whether we are in Normal mode (since the button is in block1, we can use :system.record_status
If :SYSTEM.RECORD_STATUS = 'QUERY' Then
-- Normal mode in block EMP? We can grep the 'WHERE' part of the last query executed in this block
-- Beware that this will only work for simple queries, and not with queries
-- that include a second 'WHERE' keyword
v_where_block1 := Substr( get_block_property('BLOCK1',Last_Query)
, instr(get_block_property('BLOCK1',Last_Query),'WHERE')+6
, length(get_block_property('BLOCK1',Last_Query)));
If default_block2 is null Then
set_block_property('BLOCK2', Default_Where, v_where_block1);
Else
set_block_property('BLOCK2', Default_Where, default_block2||' AND '||v_where_block1);
End if;
Go_block('Block2');
Execute_Query;
Else
Message('Can''t help you...');pause;
End If;
-- Reset the Where Clause of block2
set_block_property('BLOCK2', Default_Where, default_block2;
End; Verify the code, because I didn't test it. I'm sure the code can be improved, but it should get you on the way.
MHE
|
|
|