Questions tagged [mysql-function]

75 questions
0
votes
1 answer

MySQL: get a random unique integer ID

I tried to write a SQL-function that generates an unused unique ID in a range between 1000000 and 4294967295. I need numeric values, so UUID() alike is not a solution. It doesn't sound that difficult, but for some reason, the code below does not…
meistermuh
  • 393
  • 3
  • 11
0
votes
1 answer

Error #1241 Operand should contain 1 column(s) in Mysqlworkbench

I just try following query: CREATE DEFINER=`root`@`localhost` FUNCTION `cal1`(z DATE , y DATE) RETURNS float BEGIN SET @c= (SELECT a.StudentName, (b.marks/a.marks) as difference from (select Date, StudentName, marks from studenthistory2015 WHERE…
BTG123
  • 137
  • 1
  • 3
  • 13
0
votes
1 answer

How can I correctly select a MySql function value on a table having a specific alias?

I am not so into database and I have the following problem extracting geographical coordinates from a point object in a query. I am using MySql. So I have a table like this: Field Type Null Key Default Extra …
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596
0
votes
1 answer

MySQL function fails in main server but works in localhost

I have a MySQL function as below, but it is generating an error: BEGIN DECLARE image1 VARCHAR(250); select case when ( select COUNT(*) from profile_images where building_id = bid and contractor_id = cid ) > 0 …
samjad ps
  • 45
  • 5
0
votes
1 answer

Creating a MySQL function to make simple INSERTS

Having the following inputs which aren't taken from any other query... (891,892,903,993,1008) I wanto to make for each one, (891, 892, etc.) the following INSERT (being XXXX the actual value) INSERT INTO myTable (id, name) SELECT id, …
Avión
  • 7,963
  • 11
  • 64
  • 105
0
votes
1 answer

mysql functions over two tables, innodb

Hello I am developing a levelsystem for a web application. What i have: Database: table: levels -- fields: level_id, level_points This table defines the levels from 0 to 20 with different point values. table: profiles -- relevant fields:…
0
votes
1 answer

MYSQL count hours passed exluding weekends

I've come to a halt, I made a funtion inside mysql counting hours but it keeps giving me faulty numbers, I've been looking at it for hours and I just can't see what I am doing wrong FUNCTION `WorkingHours`(`stardate` TIMESTAMP, `enddate` TIMESTAMP)…
Breezer
  • 10,410
  • 6
  • 29
  • 50
0
votes
0 answers

MYSQL function creation syntax error

I am trying to create a query to return the number of working days in between 2 days but while trying to create a function it is giving below error. ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that…
vvr02
  • 611
  • 2
  • 12
  • 22
0
votes
1 answer

Extract SELECT expression using MySQL function or procedure

I'm interested in simplifying an SQL query/view by extracting the select expression (select_expr from the MySQL docs). Each of the select_expr is essentially duplicated with a small amount of variation that could be extracted into variables. For…
wsams
  • 2,499
  • 7
  • 40
  • 51
0
votes
1 answer

MySQL Functions: Error #1064

I'm getting the error: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IN GenreID INT(11), OUT AlbumName VARCHAR(30)) BEGIN SELECT AlbumName INTO Na' at…
DJPharaohCHS
  • 181
  • 1
  • 3
  • 13
0
votes
0 answers

Mysql insert column with function

I want to add column if the column exist on table. But i my code doesn't work i get error the error message is ; [Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right…
Zarzamora
  • 45
  • 1
  • 8
-1
votes
1 answer

MySQL query for migrating entities into a new table

In our database, we have a few tables in which the entities sometimes have a file appended and thus they have a file column storing the name of that file on disk. id entity_name file 123 document1 fdjie.txt (from table…
-1
votes
1 answer

Atomicity of the data in mysql

One of the client has asked us to write a store procedure in mysql, which states that one data should be accessed by only one resources (Even if their happens to be Multiple resources ready to read the data, whomsoever will come first will take the…
Mavericks
  • 283
  • 1
  • 7
  • 20
-1
votes
1 answer

mysql select case not working with function

how to store value in image1 variable BEGIN DECLARE image1 VARCHAR(250); select case when ( ( select COUNT(*) from profile_images where building_id = bid and…
samjad ps
  • 45
  • 5
-2
votes
2 answers

Create a MySQL function

In my mysql dababase i have 2 tables "brands" and "models" CREATE table brands ( id int(11), brand_name varchar(20)); CREATE TABLE models ( id int(11), idBrand int(11), model_name varchar(20)); I want to write a functions allowing me to display a…
1 2 3 4
5