简体   繁体   中英

Difference between fetchrow_array and fetchall_arrayref when working with stored procedures

I have recently used both to fetch result of a stored procedure. I have noticed that fetchrow_array returns the output of rows I select inside the stored procedure. Whereas fetchall_arrayref returns status of the stored procedure in the last row, along with selected rows in stored procedure.

Why we have this difference and is there a way to avoid getting the status of stored procedure inside fetchall_arrayref?

My stored Procedure

    CREATE PROCEDURE [dbo].[check_date_proc]
       @dateStart DATETIME
AS
BEGIN
SELECT
       check_date
FROM
       date_Table

WHERE
       data_date = @dateStart
END;

GO

and i call it like this

exec check_date_proc '20160920';

fetchrow_array returns

20160920

fetchall_arrayref returns

20160920
0

Thanks

Depending on which database type you are working with (and depending on the Perl DBD driver), it is likely that you are getting multiple result sets.

There is a way for processing multiple result sets (For ex., if you have executed two statements which have resulted in two result sets; and you want both of them).

Look here for sample code.

Since, in your case, you want to ignore the status of the stored procedure, you may feel it convenient just to fetch the results as hashes (all rows in one pull OR each one one by one), and then use the names of the columns to get the data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM