.NET MySQL Connector Stored Procedure Parameters Order - mysql

I'm iterating through a Dictionary(Of String, String) to pass parameters to a MySqlCommand, key being the name of the variable IN in the stored procedure and value being the value I'd like to use in the stored procedure.
It seems that the stored procedure parameters supplied are order dependent in that if they're not supplied in the order that the IN arguments are listed in the stored procedure it won't execute and give errors.
This is counterintuitive since I provide the exact name of the argument as the parameter key and if one parameter is out of order then the whole stored procedure is rendered useless.
Is there any way to pass parameters order independent?

Related

How to access dataset parameter in query parameter while executing oracle stored procedure

I created data-set and trying to execute oracle stored procedure which has one input date/time parameter and three output parameters(One ref_cursor,two varchar).
Stored procedure accepts input parameter as Date/Time datatype and default is today's date.But when I am trying to execute the stored procedure,in the query parameters not bale to see the dataset parameter value created.
Please let me know how to pass dataset parameter to query parameter and execute the stored procedure.
Based on your screenshots, it looks like your using the TEXT query type and not the Stored Procedure.
In the Dataset Properties, you should select the Query Type of Stored Procedure. The parameters should work.
MSDN Forums - call-an-oracle-stored-procdure-from-ssrs

mysql stored function calling dynamic stored procedure

I have a stored procedure that concatenates sql to make insert/update etc.
The stored procedure works.
However, I dont like the way its called (its OT but Im using node.js and calling a stored procedure is quite hard to accomplish and there doesnt seem to be much support/documentation for this).
So I decide to create a "simple" mysql stored function that will basically call the stored procedure (the function is called with a few IN parameters, the procedure (from the function) is called with the same IN parameters PLUS the OUT parameter ).
However, i get an error:
Dynamic SQL is not allowed in stored function or trigger
yes, I have read about functions and dynamic sql isnt allowed. BUT: Im doing dynamic sql from the procedure, not from the function. But still mysql doesnt like it. Is there a solution to this? I dont think something is wrong with my code...
CREATE FUNCTION my_func(a varchar(50), b varchar(50), c varchar(50), d integer, e integer)
RETURNS INT(10)
DETERMINISTIC
BEGIN
set #theid = 0;
call my_proc(a, b, c, d, e, #theid);
RETURN (#theid);
Q: But still MySQL doesnt like it. Is there a solution to this?
No.
The "Dynamic SQL is not allowed in a function" restriction also extends to any stored procedures called by the function.
There is no solution. There is no workaround.
This simply can't be done: you can't use Dynamic SQL in the context of a function or trigger.
I can't confirm this right now in the code, but I would assume that there are some data structures associated with prepared queries that can exist only one at a time in a given MySQL thread. Since a stored function or trigger is invoked from a query (which may be dynamic SQL itself), the function or trigger can't initiate a new dynamic SQL query.
So it doesn't matter that the dynamic SQL is in a procedure. You can't make a stored function that prepares and executes dynamic SQL, whether directory or indirectly.
You might be trying to find a workaround for a solved problem. See Is there a driver for mysql on nodejs that supports stored procedures?

Sending results of a SELECT to stored procedure in MySQL

I have a stored procedure which takes one parameter. Ordinarily, it will be called as needed on a single id. Sometimes, though, it would be helpful to run it on every result from a SELECT. How can I take the results of a SELECT statement and run the stored procedure on each result?
This isn't directly possible, but...
As long as the stored procedure doesn't return a result-set, you can write a stored function that accepts the desired input and calls the procedure with the same value as an argument. If a stored function is used in a select query, it will generally be called for each row returned, unless it's referenced in the where clause, in which case, the optimizer may call it for more rows than you might expect, depending on the query plan.
Or you can move the logic into a stored function directly instead of using a procedure at all.

System variable - Procedure name within procedure

When writing a stored procedure in MySQL is there a system variable that has the stored procedure's name?
I want to do some logging in stored procedures and I want to use the procedure name as a process id without hard coding the name in every proc. Something like me.name equals myStoredProc

What's the differences between stored procedures, functions and routines?

In MySQL database context, what is the difference among these 3 terms:
stored procedure
stored function
stored routine
Also the build-in functions like those date time functions (e.g. WEEKDAY() etc) are considered as what?
Google is your friend. The first match for "mysql routine function procedure" is this: http://dev.mysql.com/doc/refman/5.0/en/stored-routines-syntax.html
A quick summary:
A stored routine is either a procedure or a function.
A procedure is invoked using a CALL statement and can only pass back values using output variables.
A function can be called from inside a statement just like any other function and can return a scalar value.
Here I have tried to summarize the differences between functions and procedures:
A FUNCTION always returns a value using the return statement. PROCEDURE may return one or more values through parameters or may not return any at all.
Functions are normally used for computations where as procedures are normally used for executing business logic.
A Function returns 1 value only. Procedure can return multiple values (max 1024).
Stored procedure always returns an integer value of zero by default. Whereas function return types could be scalar or table or table values.
Stored procedures have a precompiled execution plan, where as functions are not.
A function can be called directly by SQL statement like SELECT func_name FROM DUAL while procedures cannot.
Stored procedure has the security and reduces the network traffic and also we can call stored procedure in any number of applications at a time.
A Function can be used in the SQL queries while a procedure cannot be used in SQL queries. That causes a major difference between function and procedures.
Difference between MySQL function and mysql procedure
MYSQL Function
It must return value. IN, OUT and INOUT cannot be used in function.But
return datatype must be declare when create a function. function can
be called from a SQL statement. Function return one values.
MYSQL Procedure
Return Values is not mandatory but may be uses the OUT parameter to
procedure returns. Can use the IN | OUT | INOUT parameters. Procedure
cannot be called from the SQL Statement. procedure return multiple
values by using OUT or INOUT parameters.
PROCEDURES VS FUNCTIONS
1. PROCEDURES may or may not return a value but FUNCTION must return a value
2. PROCEDURES can have input/output parameter but FUNCTION only has input parameter.
3. We can call FUNCTION from PROCEDURES but cannot call PROCEDURES from a function.
4. We cannot use PROCEDURES in SQL statement like SELECT, INSERT, UPDATE, DELETE, MERGE etc. but we can use them with FUNCTION.
5. We can use try-catch exception handling in PROCEDURES but we cannot do that in FUNCTION.
6. We can use transaction in PROCEDURES but it is not possible in FUNCTION.
Function must return a value but in Stored Procedure it is optional( Procedure can return zero or n values).
Functions can have only input parameters for it whereas Procedures can have input/output parameters .
Functions can be called from Procedure whereas Procedures cannot be called from Function.