Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save mikelemus27/c4baa39b69b55380f26d1f43a2e1d870 to your computer and use it in GitHub Desktop.

Select an option

Save mikelemus27/c4baa39b69b55380f26d1f43a2e1d870 to your computer and use it in GitHub Desktop.
select version() as 'mysql version';
#delimiter \\:
drop procedure if exists p1;
create procedure p1()
begin
declare ctr int default 0;
declare i int default 10;
myloop: WHILE (ctr < i) DO
#SET cnt = (SELECT COUNT(*) FROM temp_results WHERE result = "true");
#select @ctr := ctr + 1;#only works for @variables( variales globales)
#set ctr=@ctr;#passing value from global to local
set ctr = ctr + 1;#using only local variables
SELECT ctr;
IF ctr > 5 THEN
SELECT concat("last value of ctr: ",ctr) as LVCTR;
LEAVE myloop;
END IF;
END WHILE myloop;
end \\
call p1();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment