Skip to content

[mysql]: Stored procedure call with output parameters #1621

Answered by HaronK
HaronK asked this question in Q&A
Discussion options

You must be logged in to vote

Found solution.

Stored procedure:

CREATE PROCEDURE my_proc(
    IN name VARCHAR(255),
    OUT id INT,
    OUT data INT)
BEGIN
    ...
    SELECT my_tbl.is as id, my_tbl.data as data FROM my_tbl;
END;

sqlx:

    let query = sqlx::query!("CALL my_proc(?, @id, @data);", name);
    let res = query.fetch_one(&pool).unrwap();
    let id: i32 = res.try_get(0).unwrap();
    let data: i32 = res.try_get(1).unwrap();

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by HaronK
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant