Outdated Version

You are viewing an older version of this section. View current production version.

SCALAR

The SCALAR function takes a query type variable containing a query that returns one column and one row as an argument, and returns a scalar value containing the single value in that row.

Example

create table t(a int);
insert into t values(1), (2);
create table output_log(msg varchar(70));

delimiter //
create or replace procedure p() as
declare q query(a int) = select max(a) from t;
declare v int;
begin
  v = scalar(q);
  insert into output_log values(concat("max value is ", v));
end
//
delimiter ;

call p();

select * from output_log;

Result

+----------------+
| msg            |
+----------------+
| max value is 2 |
+----------------+