Skip to main content

All Questions

Tagged with
-4 votes
1 answer
103 views

A local variable is not rollbacked in a MySQL procedure [closed]

I'm trying to rollback the local variable v1 from 5 to 2 with ROLLBACK statement in my_proc() procedure but v1 is not rollbacked keeping 5 as shown below: DELIMITER $$ CREATE PROCEDURE my_proc() ...
Super Kai - Kazuya Ito's user avatar
0 votes
2 answers
2k views

MySQL set a variable inside CTE: "select" is fine but "set" doesn't work

People say CTE is a view and you can't set a variable in CTE. But I successfully set a variable @ttl in CTE running the query below: with CTE as (select @ttl:=(select sum(num) from test)) And when I ...
tides's user avatar
  • 25
0 votes
1 answer
357 views

stored procedure broke in release mySQL 8.0.22

With the release of mySQL 8.0.22, this stored procedure CREATE DEFINER=`workbench`@`%` PROCEDURE `loopPIDCreate`( IN startPID VARCHAR(4) , IN i INTEGER) SET @cpid = startPID ...
wistlo's user avatar
  • 329
0 votes
1 answer
82 views

Problem using a local variable in a SQL statement

I have this SQL statement: SELECT DNI, puntaje, @row := @row+1 as Puesto FROM postulante, (SELECT @row := 0) r WHERE idCa = 2 AND idPer = 1 AND @row <= (SELECT vacantes FROM ...
Vicious's user avatar
  • 51
0 votes
0 answers
39 views

SQL stored procedure local variable error #1064

I am working for a little film database with php and mysql. And i got a problem when I want to create a stored procedure, that the local variable don't work in the case i want to use it. ...
chnoeli's user avatar
0 votes
2 answers
3k views

How do i declare and increment local variables in db2?

I want to show row number for each of result set row, I have this query in mySQL SELECT @rownum := @rownum + 1 row, e.* FROM Employee e, (SELECT @rownum := 0) r Here @rownum is local variable and ...
Rahul Kulkarni's user avatar
0 votes
4 answers
2k views

mysql - initialize local variable (in stored procedure) from a query result

I am trying to create a stored procedure that would perform the select shown as the line before the end. It would take the earliest StartDate and the latest EndDate from my usertable and select all ...
Jens-Konrad Preem's user avatar
0 votes
1 answer
60 views

PHP unexpected null variable fails to echo Mysql result

I have a form comprising of a table of users. An Admin can select multiple members via check boxes and mark them down. I am trying to echo the username of each successful mark on a success message to ...
Rumesh's user avatar
  • 339
0 votes
1 answer
333 views

Select the value of user-defined variables with rand() in mysql

I have a select query like this: SELECT @imageID := imageID AS imageID, likeCount, path, `name`, description from VIEW_Select_Client_PopularImages ORDER BY RAND() LIMIT 1; SELECT @imageID; ...
Fatemeh Gharri's user avatar
0 votes
1 answer
711 views

Nested if-statement in MySQL

I am making a procedure that inserts a place ("Sted") and I would like to check if the inputs are NULL. However, whenever I try to add an if-statement at the start to surround my code (marked CRASH ...
PWL's user avatar
  • 466
0 votes
0 answers
226 views

MySQL User Variable Being Overwritten

I have a stored procedure which calls a user function similar to the structure below: CREATE PROCEDURE `MyProc`() BEGIN SELECT MyFunc(Column1), @running := @running + Column2 FROM MyTable ...
fungus1487's user avatar
  • 1,809
0 votes
2 answers
904 views

how to call php variables outside php tags

i want to call $query somewhere inside the html and this returns undefined. Even after declaring the variable as GLOBAL i still get that error. <?php if($query){ echo "Nice"; } else { echo "Bad"; }...
Relm's user avatar
  • 8,295
2 votes
1 answer
917 views

Can't assign a local variable inside a stored procedure on MYSQL

CREATE DEFINER=`root`@`localhost` PROCEDURE `add_item`( IN parentId BIGINT UNSIGNED, IN jobId BIGINT UNSIGNED, OUT id BIGINT UNSIGNED) BEGIN DECLARE newLeft INT UNSIGNED ...
user1401768's user avatar
32 votes
5 answers
51k views

MySQL local variables

I am trying to define and initialize a MySQL variable for a query. I have the following: DECLARE @countTotal INT; SET @countTotal = SELECT COUNT(*) FROM nGrams; I am using MySQL in Netbeans and it ...
CodeKingPlusPlus's user avatar
3 votes
2 answers
14k views

MySQL SELECT, store in a variable

For a stored procedure, I want to do a SELECT, and store a column's value into a variable. How do I do this? I want to do something like this: DECLARE countTemp INT; SET countTemp=(SELECT ...
rlb.usa's user avatar
  • 15k

15 30 50 per page