Home » SQL & PL/SQL » SQL & PL/SQL » What we should use for better function or procedure
What we should use for better function or procedure [message #621760] Mon, 18 August 2014 01:40 Go to next message
aaditya321
Messages: 181
Registered: January 2014
Location: Delhi
Senior Member
Hi Guys,

I want to print prime number 1 to 100 in pl/sql block then what we should use here means function or procedure and why.
Re: What we should use for better function or procedure [message #621762 is a reply to message #621760] Mon, 18 August 2014 01:52 Go to previous messageGo to next message
Michel Cadot
Messages: 59408
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

How to Check if a Number Is Prime

Note that MOD function directly gives you the remainder of a division.

Re: What we should use for better function or procedure [message #621764 is a reply to message #621760] Mon, 18 August 2014 02:15 Go to previous messageGo to next message
John Watson
Messages: 4676
Registered: January 2010
Location: Global Village
Senior Member
College homework question? Is the problem with the algorithm or with the PL/SQL?
Re: What we should use for better function or procedure [message #621766 is a reply to message #621760] Mon, 18 August 2014 02:31 Go to previous messageGo to next message
Lalit Kumar B
Messages: 2444
Registered: May 2013
Location: World Wide on the Web
Senior Member
http://www.orafaq.com/forum/m/612145/?srch=prime+number#msg_612145
Re: What we should use for better function or procedure [message #621767 is a reply to message #621762] Mon, 18 August 2014 02:33 Go to previous messageGo to next message
aaditya321
Messages: 181
Registered: January 2014
Location: Delhi
Senior Member
Michel Cadot wrote on Mon, 18 August 2014 01:52

How to Check if a Number Is Prime

Note that MOD function directly gives you the remainder of a division.



Thank you Michel for sharing supporting link
But I want to know what is better to use here
as
Create or replace function is_prime(prime number)

or

Create or replace procedure is_prime(prime number)
Re: What we should use for better function or procedure [message #621768 is a reply to message #621767] Mon, 18 August 2014 02:34 Go to previous messageGo to next message
Littlefoot
Messages: 19686
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
A function.

[EDIT] Why? Because you can use that function in SQL; for a procedure (with an OUT parameter), you have to use PL/SQL.

[Updated on: Mon, 18 August 2014 02:35]

Report message to a moderator

Re: What we should use for better function or procedure [message #621769 is a reply to message #621767] Mon, 18 August 2014 02:35 Go to previous messageGo to next message
John Watson
Messages: 4676
Registered: January 2010
Location: Global Village
Senior Member
A procedure.

[EDIT] Why? Because it has printed output, which is a side effect and a Bad Thing.

[Updated on: Mon, 18 August 2014 02:37]

Report message to a moderator

Re: What we should use for better function or procedure [message #621770 is a reply to message #621767] Mon, 18 August 2014 02:51 Go to previous messageGo to next message
Lalit Kumar B
Messages: 2444
Registered: May 2013
Location: World Wide on the Web
Senior Member
A SQL? Unless there is a real need of pl/sql.

Re: What we should use for better function or procedure [message #621771 is a reply to message #621769] Mon, 18 August 2014 02:51 Go to previous message
aaditya321
Messages: 181
Registered: January 2014
Location: Delhi
Senior Member
Thanks to all every guys.
Previous Topic: table should allow to insert only one row
Next Topic: who can create this output?
Goto Forum:
  


Current Time: Tue Oct 21 12:07:03 CDT 2014

Total time taken to generate the page: 0.16187 seconds