Outdated Version

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


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.


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;
  v = scalar(q);
  insert into output_log values(concat("max value is ", v));
delimiter ;

call p();

select * from output_log;


| msg            |
| max value is 2 |