Questions tagged [mysql-function]
75 questions
1
vote
0 answers
Changing a MySQL stored procedure to get the Titles instead of the IDs
I have a MySQL database that includes a table of components that are hierarchical (each non-top level component has a parent component)
It includes an SQL function GetParents(ComponentID), which returns a comma separated list of parent ComponentIDs,…

Ben Holness
- 2,457
- 3
- 28
- 49
1
vote
1 answer
In mysql user defined function how to set dynamic return data type
In mysql user defined function how to set dynamic return data type based on function execution.
DELIMITER $$
CREATE FUNCTION financeNumberFormat(number double) RETURNS DECIMAL(10,5)
DETERMINISTIC
BEGIN
DECLARE decpoint int(10);
SELECT…

Ram
- 284
- 2
- 5
- 19
1
vote
2 answers
Create a user defined function that works with GROUP BY in mysql
I'm trying to create an aggregated function MEDIAN() in MySQL like MIN(), MAX(), AVG() which takes the input the column name or string that has concatenated values of the desired column.
I'm having trouble understanding the limitations of MySQL…

Nikhil V
- 35
- 5
1
vote
0 answers
SQL syntax error: MySQL server RETURNS timestamp deterministic BEGIN
I am getting the following error:
1064 - SQL syntax; MySQL server RETURNS timestamp deterministic BEGIN DECLARE
dt_act timestamp; sele' at line 1
This is my code:
DROP FUNCTION IF EXISTS NewProc;
DELIMITER //
CREATE FUNCTION NewProc(f_test…

Sayan Roychowdhury
- 11
- 3
1
vote
0 answers
Comparing a function result and subselect in MYSQL where clause
I can't figure out why this subselect doesn't return anything.
select value from mytable where
indx = @var
and f() in (select num from nums);
when this version does:
select value from mytable where
indx = @var
and f() in (2,5,11);
When I create…

ShawnInAA
- 11
- 1
0
votes
0 answers
Why creating a function for Mysql I got syntax error?
In Dbeaver 22.2.5 I try to create a function for Mysql 8.0.21, which returns temp table, like
DELIMITER $$
DROP FUNCTION IF EXISTS getUserPermissionTickets$$
CREATE FUNCTION getUserPermissionTickets(permission_id INT, user_id INT)
RETURNS…

Petro Gromovo
- 1,755
- 5
- 33
- 91
0
votes
1 answer
Stored Function and dynamic where clause and json_object error fix
I have defined a stored function in mysql 8.0:
But whenever I try to hit the function with the below mentioned call, its throwing an error saying, #1582 - Incorrect parameter count in the call to native function 'JSON_OBJECT'. How to resolve it?…

Midhun Kumar
- 549
- 5
- 23
0
votes
1 answer
Functions and procedures in mysql
[enter image description here](https://i.stack.imgur.com/ffuLC.png)
I have been trying to create this function for past 2 days now, could anyone help me figure this one out?
CREATE DEFINER=`root`@`localhost` PROCEDURE `aggressorPopulator`(
IN…
0
votes
1 answer
Use functions time in MySQL Stored Function
I'm trying to create an execution log of a function stored within MySQL.
Have it like this:
Log table:
CREATE TABLE log_execution (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
task VARCHAR(255) NOT NULL,
start_time TIMESTAMP(6) NOT NULL,
…

Dezem
- 1
0
votes
1 answer
Is there an equivalent function of unnest(postgresql) in mysql?
was working on a sql question which had a simple answer through unnest in postgresql but what i want to know is that can we basically solve it on same grounds in mysql too? question with the dataset is given below
Sort the words alphabetically in…
0
votes
1 answer
Lost connection to MySQL server during query error when I try to use function
I am trying to make a function which checks if any date between say Date-range A and B lies between the Date-range C and D.
Whenever I try running the function MySQL Workbench always throws an Error Code:2013 Lost connection to MySQL Server during…

Jaisal Singhani
- 3
- 2
0
votes
1 answer
Does a MySQL backup save custom functions, events, and queries?
I successfully did a backup of my database, dropped the DB in workbench and created a new one, and attempted to restore it. First, it didn’t restore until I ran the creation of a custom function first (which is something I use in multiple views),…
0
votes
1 answer
SQL calculate processing time for business hours (including special hours on friday)
I am looking for a SQL function, that returns the processing time of a ticket. The ticket comes along with two timestamps:
start_time = when the ticket was submited
end_time = when ticket was processed
If it wasn't processed yet, the end_time is…

Alex
- 81
- 6
0
votes
1 answer
How to insert all parents id in pivot table (MariaDB 10.3)
I have the following tables:
Announcements:
id | title | body
-----------------------
1 | test1 | test body1
2 | test2 | test body2
3 | test3 | test body3
Tags:
id | title | parent_id
-------------------------
1 | tag1 | (NULL)
2 | tag2 |…

George Stinis
- 1
- 1
0
votes
0 answers
Create a function in MySQL to calculate Median
I want to create a function that I can use to calculate median in MySQL. I found this article but I can't wrap my head around it. Is there any easy way to create a function to calculate the median in MySQL. Below is my code. I want to use median…

hkay
- 159
- 1
- 2
- 12