stored-functions

Creating functions in mysql doesnt work - Error 1064

点点圈 提交于 2019-12-25 11:58:50
问题 I tried this example via phpMyAdmin http://www.databasejournal.com/features/mysql/article.php/3569846/MySQL-Stored-Functions.htm mysql> DELIMITER | mysql> CREATE FUNCTION WEIGHTED_AVERAGE (n1 INT, n2 INT, n3 INT, n4 INT) RETURNS INT DETERMINISTIC BEGIN DECLARE avg INT; SET avg = (n1+n2+n3*2+n4*4)/8; RETURN avg; END| This worked DELIMITER | The next statement gave: Error SQL query: CREATE FUNCTION WEIGHTED_AVERAGE( n1 INT, n2 INT, n3 INT, n4 INT ) RETURNS INT DETERMINISTIC BEGIN DECLARE avg

Creating functions in mysql doesnt work - Error 1064

时间秒杀一切 提交于 2019-12-25 11:58:13
问题 I tried this example via phpMyAdmin http://www.databasejournal.com/features/mysql/article.php/3569846/MySQL-Stored-Functions.htm mysql> DELIMITER | mysql> CREATE FUNCTION WEIGHTED_AVERAGE (n1 INT, n2 INT, n3 INT, n4 INT) RETURNS INT DETERMINISTIC BEGIN DECLARE avg INT; SET avg = (n1+n2+n3*2+n4*4)/8; RETURN avg; END| This worked DELIMITER | The next statement gave: Error SQL query: CREATE FUNCTION WEIGHTED_AVERAGE( n1 INT, n2 INT, n3 INT, n4 INT ) RETURNS INT DETERMINISTIC BEGIN DECLARE avg

Creating functions in mysql doesnt work - Error 1064

给你一囗甜甜゛ 提交于 2019-12-25 11:58:08
问题 I tried this example via phpMyAdmin http://www.databasejournal.com/features/mysql/article.php/3569846/MySQL-Stored-Functions.htm mysql> DELIMITER | mysql> CREATE FUNCTION WEIGHTED_AVERAGE (n1 INT, n2 INT, n3 INT, n4 INT) RETURNS INT DETERMINISTIC BEGIN DECLARE avg INT; SET avg = (n1+n2+n3*2+n4*4)/8; RETURN avg; END| This worked DELIMITER | The next statement gave: Error SQL query: CREATE FUNCTION WEIGHTED_AVERAGE( n1 INT, n2 INT, n3 INT, n4 INT ) RETURNS INT DETERMINISTIC BEGIN DECLARE avg

How to remove or escape the double quotes while returning table from PostgreSQL function

烂漫一生 提交于 2019-12-25 02:53:35
问题 Hello I have a PostgreSQL function which returns table -- Function: stloadstoryview(integer) -- DROP FUNCTION stloadstoryview(integer); CREATE OR REPLACE FUNCTION stloadstoryview(IN luserid integer) RETURNS TABLE(stid integer, stname text, stowner character varying, stbegin date, stend date) AS $BODY$ Begin Return query Select dbStory.stID, dbStory.stName, (Select usName from dbUser where usID = dbStory.stOwner):: Varchar(30), dbStory.stBegin, dbStory.stEnd from dbStory where dbStory.stID in

“MD5 decrypt” php function to MySQL stored function

对着背影说爱祢 提交于 2019-12-24 19:36:57
问题 I'm trying to fix things on a PHP site. There is a pair of PHP functions: function get_rnd_iv($iv_len) { $iv = ''; while ($iv_len-- > 0) { $iv .= chr(mt_rand() & 0xff); } return $iv; } function md5_encrypt($plain_text, $password, $iv_len = 16) { $plain_text .= "\x13"; $n = strlen($plain_text); if ($n % 16) $plain_text .= str_repeat("\0", 16 - ($n % 16)); $i = 0; $enc_text = get_rnd_iv($iv_len); $iv = substr($password ^ $enc_text, 0, 512); while ($i < $n) { $block = substr($plain_text, $i, 16)

Oracle stored function - pass table name as parameter

孤街浪徒 提交于 2019-12-24 15:42:29
问题 I'm trying to create a stored function in Oracle that will count the table rows..i want to make the table name dynamic, so i passed it as a parameter, the stored function code looks like this create type tes_jml_obj is object(jumlah integer); create type tes_jml_table is table of tes_jml_obj; create or replace function jumlahBaris(namatabel varchar) return tes_jml_table is tabel tes_jml_table := tes_jml_table(); begin for r in (execute immediate 'select count(*) as jumlah from' || namatabel)

Disallow NULL parameters to stored procedures in MySQL/MariaDB

杀马特。学长 韩版系。学妹 提交于 2019-12-24 13:04:24
问题 I can specify that table columns are NOT NULL, but how do I make a stored procedure or function only be compatible with non-null arguments? Adding NOT NULL after the argument name doesn't work. 回答1: You would need to validate passed parameter values yourself. If you're using MySQL 5.5 and up you can make use of SIGNAL. DELIMITER // CREATE PROCEDURE my_procedure (IN param1 INT) BEGIN IF param1 IS NULL THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'NULL is not allowed.'; END IF; -- do

Solve “cannot perform a DML operation inside a query ” [duplicate]

邮差的信 提交于 2019-12-24 12:35:12
问题 This question already has answers here : Solution to “cannot perform a DML operation inside a query”? (3 answers) Closed 6 months ago . The pl SQL script below transfers the amount c of money from account a to b. Why isn't allowed to update the table in the function / how can it be fixed? create or replace function ueberweisung (a varchar2, b varchar2,c number) RETURN varchar2 IS k1 number; -- Variablendeklaration k2 number; BEGIN SELECT saldo into k1 FROM konto WHERE konto_nr=a; SELECT saldo

need help adding column to one table using function that does arithmetic operations between columns from two separate tables

放肆的年华 提交于 2019-12-23 22:07:24
问题 I am trying to add a column "wOBA" to a table "starting_pitcher_stats" in MySQL using sequel-pro. Below is the code for a function that performs arithmetic operations on nine variables in the "starting_pitcher_stats" table. In particular, the function gathers the values for a number of variables, applies different weights (coefficients) to some of them (numerator below) and divides that sum by the addition and subtraction of a few more variables. All of these variables reside in the "starting

How do I eval a simple math formula inside a MySQL stored _function_?

試著忘記壹切 提交于 2019-12-23 17:43:52
问题 Inside my stored function I have : formula := "(10+10 * 1000)/12"; (a simple math formula, with numbers only, dynamically created as a string) How do I eval this, and return the result ? I can't use EXECUTE (not possible inside a stored function) and if I make it a stored procedure and call it from a stored function, I get "Dynamic SQL is not allowed in stored function or trigger" -as if I would have the eval directly inside the function. I need a stored function, and not a procedure, because