2

Some DBMSs have a pi() function to give the value of π. I can’t find the equivalent for Db2.

I can use radians(180), I suppose, but is there something more direct?

0

1 Answer 1

3

Some DBMSs have a pi() function to give the value of π. I can’t find the equivalent for Db2.

There is none in DB2.


I can use radians(180), I suppose, but is there something more direct?

You can use RADIANS(180) or ACOS(-1) , both will return 3.141592653589793

SELECT ACOS(-1) AS PI_a, RADIANS(180) AS PI_b FROM SYSIBM.SYSDUMMY1; 

You could also create a function with a static value , something like

CREATE FUNCTION PI() RETURNS DOUBLE DETERMINISTIC NO EXTERNAL ACTION RETURN 3.141592653589793; 

See example

2
  • And, to prove the point, acos(-1) - radians(180) returns 0, showing there’s no subtle difference in the nth decimal place. Commented Mar 13 at 5:16
  • Probably sufficient for most cases, but if better precision is needed the function could return DECIMAL(x,y) Commented Mar 22 at 12:07

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.