Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
321 views
in Technique[技术] by (71.8m points)

Unknown column ' ' in the field list mysql and passing dynamic table name while calling mysql function

I was trying to create a mysql stored procedure function using mysql workbench, which will show result of join data of two tables on based on some conditions. I want to pass table names as parameter also.

My code is here:

CREATE PROCEDURE `Get_Texts`(IN wrd longtext, IN dbname longtext,
 IN splitdbname longtext,
 IN lang longtext)


BEGIN
          
        
SET @sql_ = CONCAT('SELECT * FROM ',dbname,' as ifxcd

INNER JOIN 
',splitdbname,' as ifxsd
ON 
ifxsd.Crawl_id = ifxcd.Id where ifxsd.Language = ',lang,'

AND ifxsd.Word Like ',wrd,'%

order by ifxsd.Percentage desc 
limit 100');
          

PREPARE statement_ FROM @sql_;
          
EXECUTE statement_ ;

END

Call Function:

call Get_Texts('acc', emp_info, split_emp_txt , 'English(en)');

After calling the function I get an error

'Unknown column 'emp_info' in the field list

How can I overcome this and can see the desired output? Thanks in advance.

question from:https://stackoverflow.com/questions/65937813/unknown-column-in-the-field-list-mysql-and-passing-dynamic-table-name-while

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

SET a udv before the call and prefix emp_iinfo with an at symbol. same for split_emp_text for example

set @emp_info = 'aaa';
set @split_emp_text = 'bbb'
call Get_Texts('acc', @emp_info, @split_emp_txt , 'English(en)');

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...