Skip to Main Content

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Montasser.

Asked: July 09, 2001 - 5:23 pm UTC

Last updated: June 23, 2004 - 8:57 am UTC

Version: All

Viewed 1000+ times

You Asked

Hi TOM
Can you explain me why it is recommended to use block based on stored procedures in developer.
is it recommended for web applications or for all kind of applications . Please precise the difference and the advantages.

Thanks for the help you give us.

and Tom said...

I did not realize is was "recommended". It is there as a feature but it is harder to do (gotta write code) then to just use a default block.

Some of the nice aspects:

o end users do not have to have select/insert/update/delete on the tables -- only the package that forms uses. This means they must use your application to access the data, they cannot ad-hoc it in sqlplus for example.

o you can add fancy auditing to the package to see what people are doing

o you control the logic in the database -- find a bug in a query, fix the package and your application is fixed.


Downside:

o it is not as automatic as a default block, you have to write code.

Rating

  (5 ratings)

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

Comments

A reader, July 10, 2001 - 5:47 pm UTC


Learn more

Nilton Maganha, October 24, 2001 - 6:10 am UTC

I really would like to know what exactly I should write in each forms based in procedure, to improve forms execution. Particulary what should I do in LOCK procedure?

Oracle Forms' Stored Procedure Data Blocks

Geeta R, April 10, 2002 - 2:48 pm UTC

i tried this,
but the query procedure which i wrote on emp table,
does not work if i pass the argument for deptno,
with out that if only one out parameter of ref cursor is
used for returning the result set it works,
what is it that i am missing while passing the argument
of deptno from data source argument, that it just does not work
I also tried where clause in form property but it does not work,
what do i have to do this to work for a in argument.
Pls help, though i know i should not aks a question in review column but then it has not been useful comletely,
and i am unable to understand where what i am missing to pass.

Regards,
Geeta

Tom Kyte
April 10, 2002 - 4:18 pm UTC

well besides "does not work" being about as vague as we can get.... without a reproducible example and an explanation of

a) what you feel should happen
b) what actually does happen

there is no way anyone could help you.

Some more opinions

Paul Sharples, April 11, 2002 - 5:17 am UTC

In addition to Tom's nice aspects, I would add:

o You can write unit tests for business rules implemented in the database.

o You can denormalise the relational data and make the Forms block work with richer entities. This is sort of like using object views with the trigger code moved into the stored procedures. I originally tried to base my app on object views but our version of SQL*Plus (3.3.4) couldn't deal with objects reliably (and SQL*Plus 8.1.5 fails to connect with a TNS:protocol adapter error, but I digress...)

o You get to edit your business code in any number of superior alternatives to the Forms PL/SQL Editor (Toad, SQL Navigator or - from SQL Plus - Emacs, vi or even... Notepad!)

It's just better to architect your application with the business logic close to the data. I see too many Forms with business rules locked into Forms program units or shared libraries which is unavailable to the database. In fairness, many of these were written when Forms 4 was young, but people are slow to embrace progress. I would go so far as to suggest that anyone [developing with Forms 5 and 8i or better] who puts business logic anywhere in a Form should be marched into the parking lot and shot (actually, no, just flayed; everyone deserves a second chance).

I fully endorse Tom's comment that building Forms this way is more work. If you want to save hours of pain, remember the following:

* If you recompile your stored package spec, reconnect
from Forms before attempting to generate (Forms will
crash or generate Internal Errors; restart Forms).

* Save early and often. Save before generating,
compiling, fetching a drink or blinking.

* The Data Block Wizard is your friend. In particular,
it saves you the pain of having to specify the columns
using the property editor and it doesn't trash the
properties of the items already in place. You find
yourself needing to use the Wizard when you change the
record type on which your block is based (which happens
a lot during initial development).

IMO, the benefits of testability and maintainability outweigh these comparitively minor inconveniences.

Cheers.


Missing information about how to handle queries

Jørn Hansen, June 23, 2004 - 3:03 am UTC

Everybody recommends basing blocks on stored procedures but nobody really demonstrates a full-blown example of how to do it: When basing a block on a stored procedure, you have to write your own query-logic. And it is difficult to provide the same functionality as Oracle Forms.
Specific problem: Lets say that field f is NUMBER field in a block based on a stored procedure... You can emulate query logic so that if user presses key-enter-query, puts a '9' in field f and presses key-execute-query the logic returns all rows matching '9' in field f. But if you enter '>8' in field f, normal Formsbehaviour is set aside and you receive an error 'illegal value in a number field'.

So - how do you fix that one? Customer has heard a lot about the advantages of blocks based on stored procedures but has never heard that he is no longer allowed to search for number values greater than 8 as he has always done.

Tom Kyte
June 23, 2004 - 8:57 am UTC

i didn't recommend it, in fact I believe i said "i didn't realize it was recommended" -- for the reasons you listed. there are pro's, there are con's -- to everything.





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