MySQL, SqlServer, postgresql custom functions and stored procedures

1. MySQL
1. MySQL custom functions and calls
-- 报错his function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its declaration and binary logg,解决办法
set global log_bin_trust_function_creators=TRUE;
-- custom function
CREATE FUNCTION mytest (a INT, b INT) RETURNS INT
BEGIN
RETURN a + b;
END
-- call custom function
SELECT mytest(4,2);
 
2. MySQL custom stored procedure and call
-- create custom stored procedure
CREATE PROCEDURE myPro(a INT,b INT)
BEGIN
INSERT INTO `mg`.`mg_favorites` (
`regnumber`
`type`,
`object_id`,
`ctime`
)
VALUES
(
a,
b,
'12784',
'1471871232'
);
END
-- call custom stored procedure
CALL myPro(1,2);
 
2. SqlServer
1. SqlServer custom functions and calls
-- custom function
CREATE FUNCTION dbo.mytest (@a INT ,@b INT) RETURNS INT AS
BEGIN
RETURN @a +@b
END
 
-- call custom function
SELECT dbo.mytest(1,2);
 
2. SqlServer custom stored procedure and call
-- custom stored procedure
CREATE PROCEDURE dbo.insertActiveData (@dataCount INT) AS
BEGIN
DECLARE
@i INT ;
SET @i = 0 ;
WHILE @i < @dataCount
BEGIN
INSERT INTO log_DeviceInfo (
[Idfa],
[Idfa_MD5],
[IsDel],
[CreateDate],
[EditDate],
[ClientIP],
[OsType],
[PhoneType],
[SystemVersion],
[StartDate],
[Idfa_UP_MD5],
[Imei],
[Channel]
)
VALUES
(
'868029027522895',
'9FD47F63EADB66590A531884215F6212',
'0',
'2018-02-05 19:10:57.920',
'2018-02-05 19:10:57.920',
'112.227.78.1',
'android',
'Redmi+Note+3',
'5.0.2',
'2018-02-05 19:07:54.000',
'9FD47F63EADB66590A531884215F6212',
'868029027511111',
'WHAN_XM'
) ;
SET @i = @i + 1 ;
END
END
 
-- call stored procedure
EXECUTE dbo.insertActiveData 10000 ;
 
Three, postgresql
1. Postgresql custom function and call
-- create custom function
CREATE
OR REPLACE FUNCTION test_function (INTEGER) RETURNS INTEGER AS
$$
DECLARE
b_count ALIAS FOR $1 ;
BEGIN
while b_count > 0 loop INSERT INTO "public"."call_log" (
"app_id",
"platform_id",
"call_id",
"type",
"extension_number",
"use_long",
"use_time",
"recording_file",
"calling_number",
"called_number",
"province",
"city",
"editor",
"edit_time",
"creator",
"create_time",
"app_account_id"
)
VALUES
(
'19',
'1',
'1505722054.5600903',
'1',
'2009',
NULL,
'2017-09-18 16:11:25.466',
NULL,
'28306099',
'15088052151',
'Guangdong',
'Guangzhou',
'19',
'2017-09-18 16:44:14.801',
'19',
'2017-09-18 16:07:48.097615',
NULL
) ;
b_count := b_count-1 ;
END loop ;
RETURN b_count ;
END;
$$
LANGUAGE plpgsql;
-- call custom function
SELECT test_function (100000);
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326022823&siteId=291194637