All Questions
Tagged with local-variables mysql
17 questions
-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()
...
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 ...
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
...
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 ...
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.
...
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 ...
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 ...
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 ...
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;
...
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 ...
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 ...
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";
}...
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 ...
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 ...
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 ...