Home » Developer & Programmer » Forms » How to query SQL in a block?
How to query SQL in a block? [message #141796] Wed, 12 October 2005 03:34 Go to next message
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 #141945 is a reply to message #141796] Wed, 12 October 2005 19:35 Go to previous messageGo to next message
djmartin
Messages: 10181
Registered: March 2005
Location: Surges Bay TAS Australia
Senior Member
Account Moderator
What messages are you receiving? What version of forms are you running? Please add a 'message(p_where)' before the Set_Block_Property and verify your statement.

David
Re: How to query SQL in a block? [message #141956 is a reply to message #141796] Wed, 12 October 2005 21:21 Go to previous messageGo to next message
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 #141959 is a reply to message #141956] Wed, 12 October 2005 21:32 Go to previous messageGo to next message
djmartin
Messages: 10181
Registered: March 2005
Location: Surges Bay TAS Australia
Senior Member
Account Moderator
I didn't expect to see the 'select' word in the displayed 'default_where'. There are two 'errors' in your statement (1) 'WHERE AND' is wrong, and 'MA_CQTHUE IN()' is wrong.

Please confirm that the 'select' word came back in the displayed message.

I think you need to show us ALL the code that exists before the set_block_property statement.

David
Re: How to query SQL in a block? [message #141962 is a reply to message #141796] Wed, 12 October 2005 21:59 Go to previous messageGo to next message
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 Go to previous messageGo to next message
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 adding
message(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 #142018 is a reply to message #141796] Thu, 13 October 2005 03:18 Go to previous messageGo to next message
cuongtv
Messages: 34
Registered: August 2005
Location: Vi�t Nam
Member

Thank u, I've solved my problem
Re: How to query SQL in a block? [message #142214 is a reply to message #142018] Thu, 13 October 2005 18:10 Go to previous message
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
Previous Topic: Tables for FORMS practice
Next Topic: Referential intergiry in forms
Goto Forum:
  


Current Time: Fri Sep 20 02:00:04 CDT 2024