How to query SQL in a block? [message #141796] |
Wed, 12 October 2005 03:34 |
cuongtv
Messages: 34 Registered: August 2005 Location: Vi�t Nam
|
Member |
|
|
I always use these statement to execute query on a block:
Set_Block_Property('Block_Name', Defaul_Where, p_Where);
Go_Block('Block_Name');
Do_Key('Execute_Query');
Now my block doesn't have WHERE CLAUSE but I want to execute query on my block with WHERE Clause, how can I do?
|
|
|
|
Re: How to query SQL in a block? [message #141956 is a reply to message #141796] |
Wed, 12 October 2005 21:21 |
cuongtv
Messages: 34 Registered: August 2005 Location: Vi�t Nam
|
Member |
|
|
My error SQL statement:
SELECT hdr.TRAN_CODE,hdr.TRAN_NO,hdr.SO_CTU,hdr.NGAY_KB,hdr.MA_KB,hdr.MA_CQTHUE,hdr.TIN,hdr.T_SOTIEN,hdr.TEN_DTNT,hdr.DIA_CHI FROM EXC_V_CTU_KB_HDR hdr WHERE AND MA_CQTHUE IN() AND MUP.DATE01>=TO_DATE('13/10/2005','dd/MM/rrrr') AND MUP.DATE01<TO_DATE('13/10/2005','dd/MM/rrrr')+1
I use v_string = Get_Block_Property('Block_Name',Default_Where) and
Message(v_String) and I received WHERE Clause on block
(I set WHERE Clause on Block hdr.TRAN_CODE ='61') but I found:
ORA-00936: missing expression.
I'm using Oracle Form&Report 6i
[Updated on: Wed, 12 October 2005 21:24] Report message to a moderator
|
|
|
|
Re: How to query SQL in a block? [message #141962 is a reply to message #141796] |
Wed, 12 October 2005 21:59 |
cuongtv
Messages: 34 Registered: August 2005 Location: Vi�t Nam
|
Member |
|
|
I have 2 block : 'Taxoffice' and 'EXC_V_CTU_KB_HDR' alias = 'hdr'. I've set WHERE Clause on 'EXC_V_CTU_KB_HDR' block is hdr.TRAN_CODE.
On block 'EXC_V_CTU_KB_HDR' I have items:hdr.TRAN_CODE,hdr.TRAN_NO,hdr.SO_CTU,hdr.NGAY_KB,hdr.MA_KB,hdr.MA_CQTHUE,hdr.TIN,hdr.T_SOTIEN,hdr.TEN_DTNT,hdr.DIA_CHI. I set Query Data Source Name on block EXC_V_CTU_KB_HDR is From: EXC_V_CTU_KB_HDR Table.
Declare
v_Where Varchar2 (32000);
Begin
Validate (Item_Scope);
If Not Form_Success Then
Return;
End If;
Clear_Message;
-- v_where:= Get_Block_Property('EXC_V_CTU_KB_HDR', Default_Where);
-- message(v_Where);
Message ('Searching data...', NO_ACKNOWLEDGE);
Set_Application_Property (Cursor_Style, 'Busy');
/* Condition 1*/
v_Where := Fnc_DK1 ('Taxoffice', 'tax_id', 'MA_CQTHUE');
-- my function because I select MA_CQTHUE from Taxoffice so
-- you find MA_CQTHUE IN() in my error statement.
/* Condition 2: date*/
If :CG$CTRL.FromDate > :CG$CTRL.ToDate Then
Prc_Soft_Msg ('USR',
'00045',
'ToDate',
'FromDate');
Else
If :CG$CTRL.FromDate IS Not Null Then
v_Where := v_Where
|| ' And MUP.Date01>=to_date('''
|| to_char (:CG$CTRL.FromDate, 'dd/MM/rrrr')
|| ''',''dd/MM/rrrr'')';
End If;
If :CG$CTRL.ToDate IS Not Null Then
v_Where := v_Where
|| ' And MUP.Date01<to_date('''
|| to_char (:CG$CTRL.ToDate, 'dd/MM/rrrr')
|| ''',''dd/MM/rrrr'')+1';
End If;
End If;
Set_Block_Property ('EXC_V_CTU_KB_HDR', Default_Where, v_Where);
Go_Block ('EXC_V_CTU_KB_HDR');
Do_Key ('Execute_Query');
First_Record;
Set_Application_Property (Cursor_Style, 'Default');
Message ('Finish', NO_ACKNOWLEDGE);
End;
Upd-mod: Added code tags and a bit of formatting.
[Updated on: Wed, 12 October 2005 22:14] by Moderator Report message to a moderator
|
|
|
Re: How to query SQL in a block? [message #141965 is a reply to message #141962] |
Wed, 12 October 2005 22:20 |
|
djmartin
Messages: 10181 Registered: March 2005 Location: Surges Bay TAS Australia
|
Senior Member Account Moderator |
|
|
Fnc_DK1 appears to be returning "AND MA_CQTHUE IN()".
Please verify this by addingmessage(Fnc_DK1 ('Taxoffice', 'tax_id', 'MA_CQTHUE')); before your condition 2 comment.
Initialise v_Where as '1=1 ' and then you don't have to worry about the leading 'AND' statements.
Extra: Change first "v_Where :=" to "v_Where := v_Where ||".
David
[Updated on: Wed, 12 October 2005 22:22] Report message to a moderator
|
|
|
|
Re: How to query SQL in a block? [message #142214 is a reply to message #142018] |
Thu, 13 October 2005 18:10 |
|
djmartin
Messages: 10181 Registered: March 2005 Location: Surges Bay TAS Australia
|
Senior Member Account Moderator |
|
|
I expected that you would.
Add 'messages-pause pairs or 'alerts' where-ever you think they are necessary, and then add them where you DON'T think that they are necessary. It's facscinating how often it is the latter group that give you the feedback you require.
Please read this next paragraph gently: In future test your function calls via a script at the SQL*Plus prompt (or TOAD or SQL*Plus Worksheet) until you KNOW that they work. KEEP the test script so that when you modify your functions you have a test bed through which to retest them. Debugging in Forms is a major pain. Make your life easier and do development in smaller pieces and then, only when each part is working, put them all together in your form. <End of senior's advice>
David
|
|
|