Sample Header Ad - 728x90

Execute a database query by iterating through results of a previous query

1 vote
3 answers
4322 views
I'm new to Unix and bash scripts so please bare with me if this is a silly question. I've just started working for a company that uses DB2 hosted on a Unix platform and there are a lot of unwanted schemas in their databases (created by IBM Design studio). I want to clean up these schemas and I'm assuming a bash script is the best way. What I'd like to do is query the database to get the schema names and store them in some kind of collection; then iterate through the collection executing a drop command for each name. I'm OK on the DB2 commands (I think) but I'm not clear on how to get the results back in a script. This will retrieve the offending schema names: db2 "SELECT schemaname FROM syscat.schemata WHERE schemaname like 'IWSCHEMA%'" This will remove the schema where the name has been assigned to the variable $SCHEMA_TO_DROP: db2 "CALL SYSPROC.ADMIN_DROP_SCHEMA('$SCHEMA_TO_DROP', NULL, 'ST', 'ErrorTable')" All I need to do now is link the 2 together but not sure where to start?
Asked by TeamWild (111 rep)
Jun 10, 2015, 10:52 AM
Last activity: Jun 11, 2015, 09:23 AM