0

Is there a way to convert this query into a new function:

SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS 
 WHERE COLUMN_NAME IN ('current_edition') AND TABLE_SCHEMA='db_local';

where current_edition and db_local are variables so it is possible to search for a column using:

search_column('column_name', 'database'); 
1

1 Answer 1

1

you want to return a table using function in MySQL as I know you can't, but you can use a procedure:

DELIMITER $$
CREATE DEFINER=`root`@`%` PROCEDURE search_column(cl_name VARCHAR(100),db_name VARCHAR(100))
BEGIN
  SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS 
  WHERE COLUMN_NAME like cl_name 
    AND TABLE_SCHEMA=db_name;
END;
Sign up to request clarification or add additional context in comments.

Comments

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.