Skip to Main Content
  • Questions
  • SHowing Messges in Stored procedures onto form.

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Sankalp.

Asked: June 25, 2000 - 10:52 pm UTC

Last updated: July 23, 2004 - 8:31 am UTC

Version: 8.x

Viewed 1000+ times

You Asked

Dear Tom,
Thnaks for the reply.
a) With "Displaying messages from stored procedures onto form ", what I meant was, Eg we have a stored procedure LOAN CAPITALIZATION used for batch process. Can messages displayed (using dbms_output.put_line...) be displayed on the forms while calling the procedure through form?
Is there any way out to show to the user the status of the batch process,?

b) How to display PROGRES BAR in forms5.0. Thsi progress bar should end when the batch process ends.

Thanks in advance
SANKALP

and Tom said...

We need to use 2 sessions to do this. We can run the batch job in a minimized forms window and "watch" its progress from the other window.

I started with a procedure like:

create or replace procedure long_time( p_id in number,
p_iterations in number )
as
begin
for i in 1 .. p_iterations
loop
dbms_application_info.set_client_info( p_id ||
' Step ' || i ||
' of ' || p_iterations );
dbms_lock.sleep( 1 );
end loop;
end;
/

(you may need to grant execute on dbms_lock to the owner of this procedure to compile this). This procedure is your batch job. I pass into 2 items (in addition to what YOU'll pass it to run yours...). The first is a "unique" key, something we can use in our parent form to identify the row in v$session that represents our batch job. The other in this case is how many times this loop should execute (you in general won't need that one).


I then wrote a standalone form with a block on DUAL and 2 triggers. They are:

WHEN-NEW-FORM-INSTANCE:
DECLARE
timer_clock TIMER;
one_second NUMBER(7):=1000;
BEGIN
dbms_application_info.set_client_info
( '1234 Just Starting' );
set_window_property( FORMS_MDI_WINDOW, WINDOW_STATE,
MINIMIZE );
timer_clock := CREATE_TIMER('CLOCK_TIMER',
one_second,NO_REPEAT);
END;


That trigger simply minimizes our form and then creates a time to fire in 1 second. We need to use a timer to run our batch job since the parent form that will run this form will not get control back until AFTER the new form instance trigger completes.

The second trigger in this form is simply:

WHEN-TIMER-EXPIRED:
-- normally, 1234 will be a parameter the parent form will
-- pass to us
-- it'll be used by the parent to display some info (to help
-- find OUR row)
--
-- 15 is for 15 iterations
long_time( 1234, 15 );
exit_form;



So, if you run this form, it'll simply show itself -- minimize itself -- run the batch job -- and then exit. The batch job will constantly be filling in the CLIENT_INFO field in v$session with our "key" (1234 -- you will pass this in with a unique value so each client can id their rows) and the step it is on.


I then created another form. It had a block on DEPT (just as an example) and a control block (non-database) to show the progress. On this control block I put 3 items:

o a push button to run the job
o a text field I use to display the progress message (name=clock)
o a RED backgrounded text field I'll use to show the "progress
bar" (name=progress_bar)

On the button I put the following trigger:

WHEN-BUTTON-PRESSED:
DECLARE
timer_clock TIMER;
BEGIN
:b1.clock := null;
run_product( FORMS,
'C:\Documents and Settings\Thomas Kyte\Desktop\module2.fmx',
ASYNCHRONOUS, RUNTIME, FILESYSTEM, '', '' );
timer_clock := CREATE_TIMER('CLOCK_TIMER',1000,REPEAT);
set_item_property( 'b1.progress_bar', WIDTH, 0 );
END;

It just fired off another form and ran it asynchronously. I create a timer that fires every second (this will be how frequently we update our progress bar). I set the width of the "progress bar" to ZERO.

I then setup a WHEN-TIMER-EXPIRED trigger that looks like this:

WHEN-TIME-EXPIRED
declare
l_width varchar2(255);
begin
if ( GET_APPLICATION_PROPERTY(TIMER_NAME) = 'CLOCK_TIMER' )
then
begin
select to_char(sysdate,'hh24:mi:ss') || ' ' ||
client_info
into :clock
from v$session
where client_info like '1234 %';

if ( :clock like '%Step % of %' )
then
l_width := substr( :clock, instr(:clock, 'Step ')+4 );
l_width := substr( l_width, 1, instr(l_width,'of')-1 );
l_width := ltrim(rtrim(l_width));
set_item_property( 'b1.progress_bar', WIDTH,
to_number(l_width)*10 );
end if;
exception
when no_data_found then
if ( :clock <> 'Batch completed...' )
then
delete_Timer( 'CLOCK_TIMER' );
end if;
:clock := 'Batch completed...';
end;
end if;
end;


That timer trigger updates the text field with the contents of the CLIENT_INFO field and a timestamp (see the Long_Time procedure above -- it fills in this field). It also gets out the "step X of Y" part I put in there and sets the width of our "red" progress bar to be that wide. Thats our progress bar.

I do not have forms 5.0 installed which is what you have (I currently have 6.0) so I cannot give you the forms directly but I believe the above will get you going in the right direction.

Rating

  (9 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Helena Markova, March 23, 2001 - 4:55 am UTC


Good idea!

Andrew Pouckatch, May 20, 2003 - 5:17 am UTC

Thanks

pl/sql output on forms

Anurag, April 30, 2004 - 7:57 am UTC

Hi!

How can I display dbms_output.put_line() output called thru DB procedure from FORMS. I need to display its output on forms and later on reports.

Pl. help

Tom Kyte
April 30, 2004 - 8:17 am UTC

make sure you call dbms_output.enable() in your form first and then, after calling a procedure that does dbms_output stuff, you can either dbms_output.get_line or dbms_output.get_lines (that is what sqlplus does) and do whatever you like with the output.

If you have expert one on one Oracle -- i discuss this in the appendix on dbms_output


can u elaborate

Anurag, April 30, 2004 - 9:48 am UTC

Could U please elaborate with an example. It would help.

Tom Kyte
April 30, 2004 - 10:36 am UTC

when I find "U", I'll ask him if he would like to elaborate.

or -- did you really mean "you"? it is hard to tell -- since this is not a phone and we are not doing SMS.......


anyway -- just call dbms_output.get_line! it is really quite "simple". Have you seen the docs?

</code> http://docs.oracle.com/docs/cd/B10501_01/appdev.920/a96612/d_outpu2.htm#1000449 <code>

just call get_line or get_lines and you'll "get the data"

Thanks

Anurag, May 01, 2004 - 1:27 am UTC

Thanks Tom, Sometimes simple things are also missed.
By "U" I meant "you" only, nothing else. Thanks once again.

SHowing Messges in Stored procedures onto form

Clovis, July 20, 2004 - 10:01 am UTC

How I show messages in Stored procedures onto form10g if I don't use RUN_PRODUCT?

Tom Kyte
July 20, 2004 - 8:11 pm UTC

er? none of that makes sense.


stored procedures cannot (never could) "show messages"

the forms builtin "message" would have been used to show a message on the clients screen

run_product would never have been used for that.


so, for plsql running in 10g forms to show a message to the client, it would call message()

SHowing Messges in Stored procedures onto form

A reader, July 21, 2004 - 2:14 pm UTC

Why "run_product would never have been used for that" if the example use run_product

My question is who a do this example on forms10g if i can't use RUN_PRODUCT?


Tom Kyte
July 21, 2004 - 6:43 pm UTC

sorry -- i just read your comment and not even the subject -- not the article. there was insufficient context to really read your question by itself.

anyway -- suggest you try otn.oracle.com under the discussion forums, I've never used the web based forms modules at all.

but an easy solution would be to use DBMS_JOB to run the procedure asyncronously from the form and just use a single session. so you would not need two forms at all -- just one that submits a job and then monitors it.

A reader, July 22, 2004 - 4:05 pm UTC

Thank U Tom


Ayo Rabba

Ayo Rabba, July 22, 2004 - 10:54 pm UTC

I thought you will direct dudes to discussion forums on otn for questions on Forms or Reports..

Why these double standards..

Tom Kyte
July 23, 2004 - 8:31 am UTC

did you not see the "hey, suggest you goto otn" in the recent followup? eh?

this was a really old question, from when I ran windows, and i had client server forms installed on there, from when I could fire up forms If I wanted to.

geez. double standards? I'll answer a question if I know the answer.

if the question is about forms and i don't know the answer then the solution will be "goto otn".

if the question is about forms, and I might have a solution, I'll suggest it and perhaps also say "but goto otn".




More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library