Breaking News
Loading...
22/12/2013

MySQL: cursor on common_schema framework

SET @script :='
foreach($some_id: select column1 from YourTable limit 10)
{
select $some_id+1, $some_id
}';
CALL common_schema.run(@script);

If we want to select more than one column:
 
SET @script :='
foreach($some_id, $some_id2: select column1, column2 from YourTable limit 10)
{
select $some_id, $some_id2
}';
CALL common_schema.run(@script);

Another example, here I get the list of tables in a database called isporttl, then I count to find the total rows for each table
 
SET @script := 'foreach($t: table in isporttl) {select count(*), $t from isporttl.:$t}';
CALL run(@script)

0 comments:

Post a Comment

 
Toggle Footer