0

Is there any way to define database identifiers returned by a query as constants in order to reuse them in another query? Like table name or column name etc.

7
  • Well, you can store the returned value in variables. If your query returns multiple database / table names, then you probably need a cursos to loop through the resultset and process database / table names one by one. However, if you would like to use the returned names in another query, then you have to concatenate the query statement as text and used prepared statement to execute it. See the following answer for an example: stackoverflow.com/a/37314063/5389997 Commented Jul 6, 2020 at 22:44
  • Are you using a scripting language, python, php, java, etc? Commented Jul 6, 2020 at 23:59
  • @Shadow Thank you, but I am new to SQL, can you explain, what does this line means, SET @queryText = CONCAT('UPDATE ', TableName, ' SET ', UpdateColumn, '=', QUOTE(UpdateValue), ' WHERE ', WhereColumn, '=', QUOTE(WhereValue)); Is it not going to give error code:1248 Commented Jul 7, 2020 at 7:02
  • @Azeame Currently i am not using any scripting language, just running queries and practising. I am using MySQL workbench. Commented Jul 7, 2020 at 7:04
  • That line creates the dynamic sql statement as a string. It cannot result in error 1248, since there is no derived table used in the statement. Commented Jul 7, 2020 at 8:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.