# Find string of decimal digits in Pi

I am trying to find the first occurrence of "12345" in the decimal expansion of $\pi$ by using MySQL. Possibly by using the Instr function?

But I am stuck because it only displays the first 7 fractional digits.

• Where did you get the value of pi? What datatype is it stored in? Mar 14, 2015 at 19:06
• You might have done that yourself ... Mar 14, 2015 at 19:15
• @RickJames Actually I did that by SELECT PI() Mar 14, 2015 at 19:34
• It'd really help if any of you guys could get MyQL to print pi and then I'll use instr to find the first occurrence of 12345 Mar 14, 2015 at 19:35
• PI() is good to only about 16 decimal places because it is stored in a DOUBLE datatype. Mar 14, 2015 at 20:40

USE test
DROP TABLE IF EXISTS pi;
CREATE TABLE pi
(
num BLOB
) ENGINE=MyISAM;
INSERT INTO pi VALUES
('3.14159265358...');
SELECT LOCATE('12345',num) FROM pi;


Here is the output

+---------------------+
| locate('12345',num) |
+---------------------+
|               49704 |
+---------------------+
1 row in set (0.03 sec)


I had to go to http://www.piday.org/million/ and scroll/Ctrl-F dozens of times until my web browser found it. Then, I pasted about 60000 characters into that line. Then, I ran the code using MySQL 5.6.21 on my laptop in Windows 8.1.

Have Fun !!!

# UPDATE 2015-03-14 15:52 EST

BTW I just discovered this website : 100,000 Digits of Pi.

This displays pi to 100,000 digits instantly. 12345 is also there.

# UPDATE 2015-03-14 15:57 EST

I tried the INSTR() function

+--------------------+
| instr(num,'12345') |
+--------------------+
|              49704 |
+--------------------+
1 row in set (0.00 sec)


It works as well !!!

• Happy Pi day. 3/14/15 Mar 14, 2015 at 22:57