A simple example of a stored procedure with parameters and returned values in Oracle

Source: Internet
Author: User

 

Create or replace procedure caf_trackdiffbyId (

Sendid in number,

Userid in varchar,

Diffnum in number,

Lats in number,

Latn in number,

Lngw in number,

Lnge in number,

Minid out number,

Maxid out number

) Is

CurrDate date;

MinDate date;

MaxDate date;

SubMin number;

 

Cursor baseMinCursor is select * from caf_usertrack where datetime <currDate order by id desc;

Cursor baseMaxCursor is select * from caf_usertrack where datetime> currDate order by id asc;

 

Begin

Select datetime into currDate from caf_usertrack where id = sendid and userid = userid and

Lat> = lats and lat <= latn and lng> = lngw and lng <= lnge;

Begin

If currDate is not null then

Begin

MinDate: = currDate;

MaxDate: = currDate;

End;

End if;

For sysd in baseMinCursor loop -- get the minimum ID value www.2cto.com

Begin

SubMin: = round (to_number (minDate-sysd.datetime) * 24*60, 2 );

If subMin <= diffnum then

Begin

MinDate: = sysd. datetime;

End;

Else

Begin

Minid: = sysd. id;

Dbms_output.put_line ('Min' | minid );

Exit;

End;

End if;

End;

End loop;

For sysd in baseMaxCursor loop -- get the largest ID value

Begin

SubMin: = round (to_number (sysd. datetime-maxDate) * 24*60, 2 );

If subMin <= diffnum then

Begin

MaxDate: = sysd. datetime;

End;

Else

Begin

Maxid: = sysd. id;

Dbms_output.put_line ('maxid' | maxid );

Exit;

End;

End if;

End;

End loop;

End;

 

End caf_trackdiffbyId;

 

From yuefengyuan's column

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.