Attn: Oracle Forms Developers [message #376612] |
Thu, 18 December 2008 00:50 |
Maverick27
Messages: 84 Registered: October 2008
|
Member |
|
|
Can somebody pls. give me the syntax for writing Oracle Query Forms. I've done it before but forgotten the syntax.
The idea is to FORM a statement by APPENDING the search items on the Form & substituting in the WHERE clause.
This way, we don't have to write many IF statments.
For example, if user wants to query by NAME & COUNTRY, then the statement >> Block:Name ||&|| Block:Country
Where clause: Block:Name ||&|| Block:Country
Thanks - Mave
|
|
|
|
|
|
Re: Attn: Oracle Forms Developers [message #376682 is a reply to message #376678] |
Thu, 18 December 2008 04:42 |
Maverick27
Messages: 84 Registered: October 2008
|
Member |
|
|
The items are CONTROL BLOCK items (non-base table.)
Queried records are based on TABLE - hence Query Forms.
So if the CONTRL BLOCK has 5 items, program unit should APPEND the items that need to be queried.
If user wants to query using 3 items >> APPEND statement using those 3 items & substitute in WHERE Clause
If user wants to query using 2 items >> APPEND statement using those 2 items & substitute in WHERE Clause
Catch the drift ?
I have written such forms but forgotten the SYNTAX
Mave
|
|
|
Re: Attn: Oracle Forms Developers [message #376716 is a reply to message #376682] |
Thu, 18 December 2008 06:24 |
|
Maaher
Messages: 7065 Registered: December 2001
|
Senior Member |
|
|
Ok, I clearly missed the point. I'll reply here instead of at the Oracle forums since they are experiencing some troubles
This is what I understand:
- you have a control block with search criteria and a push button "search"
- when you push the button all the values from these control block items are passed to a program unit
- this program unit should interpret these values and add them to the where clause of a cursor (or is it a block - still not clear, I'm afraid ?).
But you are confused about how to add these where clauses in a simple way and with as little code as possible. I think a NVL could do the trick:
SELECT <columns>
FROM <table>
WHERE db_column1 = NVL(:controlblock.field1, db_column1)
AND db_column2 = NVL(:controlblock.field2, db_column2);
By using a NVL, empty criteria will be ignored. Here's a small code sample to illustrate:
DECLARE
CURSOR mysearch (criterium1 IN VARCHAR2, criterium2 IN VARCHAR2)
IS
WITH mytable AS
(SELECT 'Jim' fname, 'Boston' locat
FROM DUAL
UNION ALL
SELECT 'Jenny' fname, 'Tucson' locat
FROM DUAL
UNION ALL
SELECT 'Frank' fname, 'Bristol' locat
FROM DUAL
UNION ALL
SELECT 'Patrick' fname, 'Boston' locat
FROM DUAL
UNION ALL
SELECT 'Susan' fname, 'Houston' locat
FROM DUAL)
SELECT *
FROM mytable
WHERE fname = NVL (criterium1, fname)
AND locat = NVL (criterium2, locat)
ORDER BY fname;
BEGIN
DBMS_OUTPUT.put_line ('show all: ');
FOR rec1 IN mysearch (NULL, NULL)
LOOP
DBMS_OUTPUT.put_line (rec1.fname || ' is located in ' || rec1.locat);
END LOOP;
DBMS_OUTPUT.put_line ('show Boston only: ');
FOR rec2 IN mysearch (NULL, 'Boston')
LOOP
DBMS_OUTPUT.put_line (rec2.fname || ' is located in ' || rec2.locat);
END LOOP;
DBMS_OUTPUT.put_line ('show Susan:');
FOR rec3 IN mysearch ('Susan', NULL)
LOOP
DBMS_OUTPUT.put_line (rec3.fname || ' is located in ' || rec3.locat);
END LOOP;
END;
PS: Sorry if my assumptions are incorrect (again).
MHE
[EDITED by LF: fixed invalid [list] tags]
[Updated on: Thu, 18 December 2008 06:52] by Moderator Report message to a moderator
|
|
|
Re: Attn: Oracle Forms Developers [message #376722 is a reply to message #376716] |
Thu, 18 December 2008 06:38 |
Maverick27
Messages: 84 Registered: October 2008
|
Member |
|
|
Thanks for the code, but it does'nt need to get as complicated as this !
The code to achieve this is very, very simple. I know it is b'coz i've done it but can't remember.
Your code DOES NOT incorporate the use of WHERE CLAUSE of the BLOCK.
Assuming there are 5 items on the Control Block.
User wants to search using ONLY 2 items on the block say Name & Country.
In the program unit:
Create a statement by APPENDING Name & Country. If i can remember>
variable := :Control_Block.Name ||&|| :Control_Block.Country
Now we use the WHERE CLAUSE utility of BASE Table block & assign variable to it
Assign: Where Clause := variable
Now the block knows how to restrict search query b'coz we have assigned 2 items i.e Name & Country
SIMPLE AS THIS, but can't remember the exact syntax..
This approach does really work...
There's absolutely no need for any Cursors or Loops
Mave
|
|
|
|
|
|
|
Re: Attn: Oracle Forms Developers [message #376745 is a reply to message #376742] |
Thu, 18 December 2008 07:47 |
Maverick27
Messages: 84 Registered: October 2008
|
Member |
|
|
Maaher wrote on Thu, 18 December 2008 07:35 | D'oh! Are you serious? That's just classic: I missed the obvious. Do you have enough information?
MHE
|
Good- now we're on the same wavelenght !!
1. Assign to a variable the items (from control block)
for query using concatenation symbols
2. Put variable in SET BLOCK PROPERTY
3. Assign program unit to Search button
If u can get it to work, pls. advise.
Thanks Folks.
|
|
|