Stored procedure is as follows:
The CREATE DEFINER=` root ` @ ` localhost ` PROCEDURE ` CXGX ` (P1 VARCHAR (255), P2 VARCHAR (255), P3 VARCHAR (255))
NO SQL
The BEGIN
The SET @ table_name=P1; # table name
The SET @ position_index=P2; # query which column
The SET @ limit_num=P3-1; Article # for which the data
The SET @ col_name=(SELECT COLUMN_NAME FROM information_schema. COLUMNS
WHERE table_name=@ table_name
AND ordinal_position=@ position_index
); # for the column name
The SET @ exe_sql=CONCAT (" SELECT ", @ col_name, "FROM", @ table_name, "LIMIT", @ limit_num, "1"); # for executing SQL statements
PREPARE stmt3 FROM @ exe_sql;
The EXECUTE stmt3; # query results
END
This CXGX stored procedure is to obtain some value in the cell in a table,
Such as running CALL CXGX (" agx002 ", 3, 1), the third column in agx002 table the first line coordinates numerical,
Question: can use MySQL statement, will CALL () function again operation result, reach the effect such as the following: CALL CXGX (" agx002 ", 3, 1) + CALL CXGX (" agx002 ", 4, 1) - CALL CXGX (" agx001 ", 5, 1), the actual operation will prompt wrong, 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 '+ CXGX (" agx002 ", 4, 1)' at line 1