Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
hi how is possible to return datatable or table from mysql function, for example I give parameter and I want to return the whole datatable with that parameter, I just found out that views cant have parameters and I just found about functions, which accepts parameters but I dont know how to make the function to return table?
Posted
Comments
Sergey Alexandrovich Kryukov 23-Jun-15 15:32pm    
What do you mean by "returning a database"... or a "table"? This is not how SQL works.
SELECT * FROM tableName
would do something like a table, but better don't do it...
—SA

1 solution

Try a stored procedure rather than a function.
A sample stored procedure with parameter -
SQL
DELIMITER $$

DROP PROCEDURE IF EXISTS MyFirstSP$$
CREATE PROCEDURE MyFirstSP(IN Id INT)
BEGIN
 SELECT * FROM MyTable WHERE pk_id=Id;
END$$


You can follow this link to learn how to create a simple stored procedure.
MySQL: Creating a simple stored procedure [^]

Hope, it helps :)
 
Share this answer
 
Comments
SrgjanX 23-Jun-15 16:00pm    
whoa thanks man, i forgot about these stored procedures, sorry man today i found about functions and stored procedures a taught i need to use functions since i need return result, this is much simpler than i taught, thanks.. works..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900