-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02 extra functions.sql
More file actions
39 lines (36 loc) · 905 Bytes
/
02 extra functions.sql
File metadata and controls
39 lines (36 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
DROP procedure IF EXISTS `show_image`;
DELIMITER $$
USE `mnist`$$
CREATE PROCEDURE `show_image`(IN image_id integer, IN image_group varchar(255) )
BEGIN
set @header_offset=16;
set @image_offset=28*28*image_id+@header_offset;
SELECT
numbers_table.num,
HEX(SUBSTR(data,
numbers_table.num * 28 + @image_offset,
29))
FROM
mnist_data_loader,
numbers_table
WHERE
numbers_table.num < 29 AND
name = image_group
ORDER BY numbers_table.num;
END$$
DELIMITER ;
DROP function IF EXISTS `asciiart`;
DELIMITER $$
USE `mnist`$$
CREATE DEFINER=`student`@`%` FUNCTION `asciiart`(s varchar(255)) RETURNS varchar(255) CHARSET latin1
BEGIN
set @i =0;
set @y='';
while @i < length(s) do
set @x=ascii( substr(s,@i,1) );
set @y = concat( @y, substr(" .:-=+*#%@",round(@x*10/255+1),1) );
set @i=@i+1;
end while;
RETURN @y;
END$$
DELIMITER ;