How to get a loop value in MySQL stored procedure?
FOR I = 1 TO 10 tRESNUM = ALLTRIM(STR(I)) tRESCAS = 'tRESCAS'+tRESNUM &tRESCAS = 0.00 ENDFOR
I am converting this fox-pro code to MySQL Stored Procedure.
In Foxpro tRESCAS = 'tRESCAS'+tRESNUM gives tRESCAS1, tRESCAS2,.. and &tRESCAS gives the value which is tRESCAS1 or tRESCAS1 or ... something else.
if I =1 => FOR I = 1 TO 10 tRESNUM = ALLTRIM(STR(1)) tRESCAS = 'tRESCAS'+1 tRESCAS1 = 0.00 ENDFOR If I =2 => FOR I = 1 TO 10 tRESNUM = ALLTRIM(STR(2)) tRESCAS = 'tRESCAS'+2 tRESCAS2 = 0.00 ENDFOR
&tRESCAS Automatically take the tRESCAS value tRESCAS1 or tRESCAS2 like this.
In Stored Procedure How Can i get this type of Value?. (is any Special variable in stored procedure like & this?)
Is this details enough?.
Have a look at this procedure -
PROCEDURE procedure1() BEGIN DECLARE tRESCAS VARCHAR(255) DEFAULT ''; DECLARE i INT DEFAULT 0; DROP TEMPORARY TABLE IF EXISTS t; CREATE TEMPORARY TABLE t(num INT, column1 VARCHAR(255)); WHILE i < 10 DO INSERT INTO t VALUES(i, CONCAT('tRESCAS', i)); SET i = i + 1; END WHILE; -- Try to get fifth value SELECT column1 FROM t WHERE num = 5; END
All values are stored into temporary table.
Execute the procedure:
CALL procedure1; +----------+ | column1 | +----------+ | tRESCAS5 | +----------+
- A Linux, Apache, MySQL, PHP (LAMP) stack is a combination of open source software that is typically installed together to enable a server to host dynamic […]
- MySQL is an the most popular open-source database management system, in most of hosting company its has been bundle by LAMP(Linux, Apache, MySQL, PHP/Python/Perl) stack. Another alternative […]
- MySQL is the world’s most popular open-source database. Despite its powerful features, MySQL is simple to set up and easy to use. Below are some instructions […]