Solved

How do I create procedure that check current date and display all data with the date before current date?

Posted on 2008-10-17
4
351 Views
Last Modified: 2013-12-07
Create a procedure which displays the total cost of all appointments by month for all appointments with the date before current date.
Your select statement must have condition date < SYSDATE

How can I do this?
0
Comment
Question by:Zerysaish
  • 2
4 Comments
 
LVL 6

Assisted Solution

by:Jankovsky
Jankovsky earned 60 total points
ID: 22747506
Do you mean something like:
Select trunc(date_column,'MM') as month, sum(cost_column)  as mtd_cost where date_column<sysdate group by trunc(date_column,'MM')
?
0
 

Author Comment

by:Zerysaish
ID: 22747866
yes, something like that, but I've to create user defined procedure. When the procedure is called, it'll display the total cost of all appointments by month for all appointments with the date before current date.
0
 
LVL 6

Expert Comment

by:Jankovsky
ID: 22749148
Which way to display? there are several possibilities such as DBMS_OUTPUT etc. Would you like see all total costs for months before current date or just the one last Month to day total value?
 
0
 
LVL 15

Accepted Solution

by:
Shaju Kumbalath earned 65 total points
ID: 22749164
i will just try to conert the sql given by Jankosky
-- Create the procedure
 
Create or replace procedure p_display_cost_app_month as
cursor cur_cost is
Select trunc(date_column,'MM') as cost_month, sum(cost_column)  as mtd_cost where date_column<sysdate group by trunc(date_column,'MM');
begin
 for myrec in cur_cost
 loop
dbms_output.put_line('Month ' || Cost_month||' Cost '||mtd_cost);
end loop;
end;
/
-- connect  to sql plus
set serveroutput on
exec p_display_cost_app_month ;
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now