If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > automatic computation of totals (procedure)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-10-11, 08:49
ArminM ArminM is offline
Registered User
 
Join Date: Aug 2010
Posts: 22
automatic computation of totals (procedure)

Hello all,
I need some help with creating a procedure in Oracle Application Express which basically adds up the totals, during data entry (into a form) and outputs it.
This would probably need to have a stored procedure attached to the relevant fields in the form but creating it using SQL is quite tricky for me as I've never used procedures before.

thanks in advance.
Armin
Reply With Quote
  #2 (permalink)  
Old 12-10-11, 08:56
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
What is your Apex version? Perhaps you could do that using Dynamic Actions. Also, a procedure might not be needed - a simple SUM might do the job.
Reply With Quote
  #3 (permalink)  
Old 12-10-11, 10:46
ArminM ArminM is offline
Registered User
 
Join Date: Aug 2010
Posts: 22
hi 'littleFoot' I am using Apex version 4.0.2.00.07.
What is a 'dynamic action'? and how would i go about doing a SUM in SQL

thanks again.
Reply With Quote
  #4 (permalink)  
Old 12-10-11, 11:07
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
Dynamic actions.

What I had on mind would be this: when an item value changes, set value of the summary item using a SQL statement as
Code:
select sum(some_column) 
from some_table
where some_other_column = :PX_apex_item
  and ...
It means that every new insert should also submit the page.

Here are some dynamic actions examples.
Reply With Quote
  #5 (permalink)  
Old 12-10-11, 11:44
ArminM ArminM is offline
Registered User
 
Join Date: Aug 2010
Posts: 22
Out of sheer curiosity, how would've this been done using a procedure? I've been trying to learn more about SQL and I havent fully grasped the concept of procedures.

I've got my APEX application up and running, with tables populated with records already and shown in the report/form style.
Reply With Quote
  #6 (permalink)  
Old 12-10-11, 13:10
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
If you insist on (stored) procedures, why not a function instead? It returns a single value, can be used in a SQL statement. Procedures can be used only in PL/SQL and, if you want it to return a value, it has to have an OUT parameter.

I don't think that this forum's purpose is to teach you all about procedures - take a look at PL/SQL User's Guide and Reference and Application Developer's Guide - Fundamentals books (actually, don't just take a look - read them thoroughly).
Reply With Quote
  #7 (permalink)  
Old 12-16-11, 09:51
ArminM ArminM is offline
Registered User
 
Join Date: Aug 2010
Posts: 22
...so iv started creating the procedure but I'm stumbling on a few things:
here's what I have so far.

Code:
 CREATE PROCEDURE data_entry_totals
AS
CURSOR (*cursor_name*)
SELECT * FROM (*table_name*)
WHERE (*column_name* = *column_names.attribute*);
BEGIN
FOR
I need to display the number of records in my 'purchase' table which looks like this:

Code:
create table Purchase
(
Purchase_ID NUMBER(10),
Appetizer_ID NUMBER(10),
Main_Course_ID NUMBER(10),
Dessert_ID NUMBER(10),
Drink_ID NUMBER(10),
constraint pk_Purchase_ID PRIMARY KEY(Purchase_ID));
Code:
INSERT INTO Purchase values(900, 201, 301, 401, 501); 
INSERT INTO Purchase values(900, 202, 302, 402, 502);
I read somewhere that the cursor name needs to be declared before a procedure is created?

Thanks again guys!
Reply With Quote
  #8 (permalink)  
Old 12-16-11, 09:56
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,416
search this board for "CREATE OR REPLACE PROCEDURE"
__________________
You can lead some folks to knowledge, but you can not make them think.
The average person thinks he's above average!
For most folks, they don't know, what they don't know.
Reply With Quote
  #9 (permalink)  
Old 12-16-11, 10:17
ArminM ArminM is offline
Registered User
 
Join Date: Aug 2010
Posts: 22
iv searched this forum using the words "create or replace procedure" and "create procedure apex" but found nothing.

If anyone knows how to create this simple procedure and can explain it to me succinctly, I would be eternally grateful.

thanks in advance
Reply With Quote
  #10 (permalink)  
Old 12-16-11, 11:10
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
There's no use in spoonfeeding or doing your homework.

Click here, navigate to the Most Popular section and read:
- PL/SQL User's Guide and Reference
- Application Developer's Guide - Fundamentals

Will take some time, but you'll learn A LOT!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On