mysql - Select a particular type of columns that begin with a certain letter and fetch data all together -
i trying fetch data @ same time select specific type of columns
i`m doing is:
select column_name information_schema.columns table_name = 'table' , table_schema = 'db' , column_name 'f%'
this query give me col names, there option fetch data of colum @ same time? or need take array of cols , make query? let want fetch data, doesnt matter.
thanks.
you can use stored procedure this, dynamic sql.
first, must create stored procedure:
create procedure fetchcolumns (in pschemaname char(50), in ptablename char(50), in pcolumnlikecondition char(50)) begin declare v_cols char(200); select group_concat(column_name separator ' , ') v_cols information_schema.columns table_name = ptablename , table_schema = pschemaname , column_name pcolumnlikecondition; set @s = concat('select ',v_cols,' ',ptablename ); prepare stmt @s; execute stmt; end
and finally, have calling it, this:
call fetchcolumns('db', 'table', 'f%')
Comments
Post a Comment