I need a stored procedure where I do two things. First I want to get all schema names that is prefixed with 'myschema_', so I've done this:
SELECT schema_name
FROM information_schema.schemata
WHERE schema_name LIKE 'myschema_%'
Next, I want a while loop that loops through each schema and gets 'name' from the 'person' table. This means that I somehow have to feed the result from the first select schema statement in as a parameter in the next call. And all of this should be one stored procedure.
This is what I want the stored procedure to return:
| schema | name |
-------------------
| schema_1 | Mike |
| schema_1 | Jane |
| schema_2 | Rich |
| schema_3 | Fred |
| schema_4 | Chris|
How do I do this?