Thread: waiting in a procedure (urgent)


Permlink Replies: 104 - Pages: 7 [ Previous | 1 2 3 4 5 6 | Next ] - Last Post: Aug 8, 2006 12:47 PM Last Post By: Kamal Kishore
N. Gasparotto

Posts: 18,604
Registered: 08/22/02
Re: waiting in a procedure (urgent)
Posted: Jul 9, 2006 9:48 AM   in response to: eightten1985@ya... in response to: eightten1985@ya...
Click to report abuse...   Click to reply to this thread Reply
can i let a procedure wait for a sepcific time( 10 seconds ) before inserting values into a table
A good question would be : why did you want wait 10 sec. before inserting ?

Nicolas.
eightten1985@ya...

Posts: 402
Registered: 04/04/05
Re: waiting in a procedure (urgent)
Posted: Jul 10, 2006 11:48 AM   in response to: N. Gasparotto in response to: N. Gasparotto
Click to report abuse...   Click to reply to this thread Reply
after all these posts , i have asked this question becuase i want to test how the timers will be executed incase a procedure that a timer call takes more time than the timer duration...
that all...................
after more than one day do u know why??????????????
William Robertson

Posts: 6,456
Registered: 06/17/98
Re: waiting in a procedure (urgent)
Posted: Jul 10, 2006 4:14 PM   in response to: eightten1985@ya... in response to: eightten1985@ya...
Click to report abuse...   Click to reply to this thread Reply
I don't understand what you mean by something taking more time than a timer duration?

Originally you asked
> can i let a procedure wait for a sepcific time( 10 seconds ) before inserting values into a table

Are you now asking how to set a limit on how long to wait for a procedure to execute?
eightten1985@ya...

Posts: 402
Registered: 04/04/05
Re: waiting in a procedure (urgent)
Posted: Jul 11, 2006 12:06 AM   in response to: William Robertson in response to: William Robertson
Click to report abuse...   Click to reply to this thread Reply
i do not know why we want to know the reason for my question any way, this is th ereason
i have made a timer using form developer and that timer fires each 10 seconds , so i want to see the timer behaviour incase the procedure which the timer call takes more than 10 seconds...
This is the reason
Faust - old acc...

Posts: 524
Registered: 01/14/01
Re: waiting in a procedure (urgent)
Posted: Jul 13, 2006 1:12 AM   in response to: Faust - old acc... in response to: Faust - old acc...
Click to report abuse...   Click to reply to this thread Reply
The execute privilege on DBMS_LOCK is not for an
end
user. There will be an application schema that
owns
the tables and packages and requires certain core
privileges, and end users will have controlled
access
to this via role grants. The end users will never
use
DBMS_LOCK directly.

If for some reason only the SLEEP procedure within
DBMS_LOCK is deemed safe for the applicaion to
access, then a more privileged account could own a
one-line wrapper procedure and grant execute on

that
to the application schema that needs to use it.

Nice thoughts William...


Yeah, as I said nice thoughts, but just that!

Reason?

Well, this time I will use Billy explanation just to avoid absence of belief in Faust statements:

"Grants and privs assigned via a role is not applicable inside named
PL/SQL (e.g. PL/SQL procs, packages and functions).

Reason: any changes to the privs for a role will invalidate all PL/SQL code
relying on that role - this can cause a major fubar in the database.

Solution: privs required for named PL/SQL code must be assigned explicitly and not via a role.

Roles privs work via anonymoys PL/SQL blocks as these are processed at runtime"


Cheers!
William Robertson

Posts: 6,456
Registered: 06/17/98
Re: waiting in a procedure (urgent)
Posted: Jul 13, 2006 2:32 AM   in response to: Faust - old acc... in response to: Faust - old acc...
Click to report abuse...   Click to reply to this thread Reply
I'm not sure what your point is.
Faust - old acc...

Posts: 524
Registered: 01/14/01
Re: waiting in a procedure (urgent)
Posted: Jul 13, 2006 3:42 AM   in response to: William Robertson in response to: William Robertson
Click to report abuse...   Click to reply to this thread Reply
I'm not sure what your point is.

Differentiation between ideal solution and real life solution (also sometimes called practical solution).
William Robertson

Posts: 6,456
Registered: 06/17/98
Re: waiting in a procedure (urgent)
Posted: Jul 13, 2006 4:13 AM   in response to: Faust - old acc... in response to: Faust - old acc...
Click to report abuse...   Click to reply to this thread Reply
What about it?
Andrew Max

Posts: 239
Registered: 02/17/06
Re: waiting in a procedure (urgent)
Posted: Jul 13, 2006 4:22 AM   in response to: Faust - old acc... in response to: Faust - old acc...
Click to report abuse...   Click to reply to this thread Reply
    ...
loop
ndiff := (sysdate - dstart)*86400;
exit when ndiff >= 10;
end loop;
...

Geez, I've already seen such code elsewhere but it still sends chills down my spine.
Please - begging you - don't be tempted to use it in your production systems.
Because such code will overheat your CPU.

NEVER DO THAT.

Well, if you don't believe me, let's test it and measure:

SQL> alter session set tracefile_identifier = SLEEP;

Session altered.

SQL> alter session set sql_trace = TRUE;

Session altered.

SQL> -- Awful code
SQL> declare
2 dstart date := sysdate;
3 ndiff number;
4 begin
5 loop
6 ndiff := (sysdate - dstart)*86400;
7 exit when ndiff >= 10;
8 end loop;
9 end;
10 /

PL/SQL procedure successfully completed.

SQL> -- DBMS_LOCK code
SQL> exec dbms_lock.sleep(10)

PL/SQL procedure successfully completed.

SQL> alter session set sql_trace = FALSE;

Session altered.

And now, here is what TKPROF says:

BEGIN dbms_lock.sleep(10); END;

call count cpu elapsed disk query current rows


------
----------
----------

Parse 1 0.03 0.02 0 12 0 0
Execute 1 0.00 9.98 0 0 0 1
Fetch 0 0.00 0.00 0 0 0 0

------
----------
----------

total 2 0.03 10.01 0 12 0 1

Misses in library cache during parse: 1
Optimizer mode: CHOOSE
Parsing user id: 72
********************************************************************************

declare
dstart date := sysdate;
ndiff number;
begin
loop
ndiff := (sysdate - dstart)*86400;
exit when ndiff >= 10;
end loop;
end;

call count cpu elapsed disk query current rows

------
----------
----------

Parse 1 0.00 0.00 0 0 0 0
Execute 1 9.71 9.70 0 0 0 1
Fetch 0 0.00 0.00 0 0 0 0

------
----------
----------

total 2 9.71 9.71 0 0 0 1

Misses in library cache during parse: 1
Optimizer mode: CHOOSE
Parsing user id: 72
********************************************************************************

ELAPSED time is near 10 sec in both cases, but look at CPU time.
DBMS_LOCK.SLEEP consumes no CPU time (at least, it can't be measured) whereas LOOP ... END LOOP can really overheat your CPU.

If DBMS_LOCK (or some wrapper routine for DBMS_LOCK.SLEEP) can not be granted due to DBA whims - well, show this testcase to him and try to explain things. And if he still doesn't get things right - I'm afraid it's better to get rid of such DBA.

Cheers.
Faust - old acc...

Posts: 524
Registered: 01/14/01
Re: waiting in a procedure (urgent)
Posted: Jul 13, 2006 4:31 AM   in response to: Andrew Max in response to: Andrew Max
Click to report abuse...   Click to reply to this thread Reply
Hi Andrew Max!

Thank you for your post, but I'm aware of facts you demonstrate so good.

Regards!
Faust - old acc...

Posts: 524
Registered: 01/14/01
Re: waiting in a procedure (urgent)
Posted: Jul 13, 2006 4:31 AM   in response to: William Robertson in response to: William Robertson
Click to report abuse...   Click to reply to this thread Reply
What about it?

What "What about it?"?
APC

Posts: 10,439
Registered: 08/27/03
Re: waiting in a procedure (urgent)
Posted: Jul 13, 2006 5:47 AM   in response to: Faust - old acc... in response to: Faust - old acc...
Click to report abuse...   Click to reply to this thread Reply
What about it?

What "What about it?"?


Presumably, what about "Differentiation between ideal solution and real life solution (also sometimes called practical solution)."?
William Robertson

Posts: 6,456
Registered: 06/17/98
Re: waiting in a procedure (urgent)
Posted: Jul 13, 2006 5:55 AM   in response to: APC in response to: APC
Click to report abuse...   Click to reply to this thread Reply
Precisely. What about that?

I have every confidence that there is a valid point being made here, and that it will turn out to be a good one and well worth the struggle.
Faust - old acc...

Posts: 524
Registered: 01/14/01
Re: waiting in a procedure (urgent)
Posted: Jul 13, 2006 7:48 AM   in response to: William Robertson in response to: William Robertson
Click to report abuse...   Click to reply to this thread Reply
Hi APC I'm glad to see you here :)

But hey guys,

are you really unable to see real flow of this thread with many aspects that were
opened here and what striving of person with handle "Faust" was / is?
Not just "What" in thread, but also and "How" in thread?

Do you even now believe that Faust want to say his first example is the best one
or right one? No, really no!!!
Development is continuous process not one time occasion! Because of that is
Refactoring so much useful und important ...
But if you have impresion that William suggestion about granting privs through
roles didn't impress me - well, then you are right.
This solution is ideal, but often very unpractical!

But back to main theme:

I have impression that you see just naked facts and wisdom about Oracle without
respect to human being, respect to human situations and different levels of
human existence (especial in case: working with Oracle)

Absolute truth don't exists, from situation to situation is truth different.

O.K. now I stop with this philosophical things ...
... and yet I want to say many thanks to all of you because I learned something new
from you in this thread!

Regards to all of you from Central Europe!

PS: Sorry for my bad English but that not my first (also not my second!) language

APC

Posts: 10,439
Registered: 08/27/03
Re: waiting in a procedure (urgent)
Posted: Jul 13, 2006 8:15 AM   in response to: Faust - old acc... in response to: Faust - old acc...
Click to report abuse...   Click to reply to this thread Reply
Absolute truth don't exists, from situation to situation is truth different.

Hmmm. Are you saying that in Central Europe if I walk in the rain without an umbrella I won't get wet? Surely not.

With databases there is absolute truth. Predicate logic assures us of that. Relative truth is a bug.

Which isn't to say that there are not workplaces where all sorts of inefficient and counterproductive practices are rife. Of course, people are stupid and lazy all over the world. So your problem (as I understand it) is political (how do I get the DBA to grant me privileges on DBMS_LOCK?) rather than technical (How can I make a procedure wait for a fixed duration of time?)

A technical fix for a political problem; write a PL/SQL wrapper to DBMS_LOCK.SLEEP, owned by SYS and granted to those who need it.

Cheers, APC
Legend
Guru Guru : 2500 - 1000000 pts
Expert Expert : 1000 - 2499 pts
Pro Pro : 500 - 999 pts
Journeyman Journeyman : 200 - 499 pts
Newbie Newbie : 0 - 199 pts
Oracle ACE Director
Oracle ACE Member
Oracle Employee ACE
Helpful Answer (5 pts)
Correct Answer (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums