Home  >  Q&A  >  body text

linux - mysql variable problem

About the reference of variables in the mysql5.5 database.

1. There is a database called test_num_base, which has a test table.

I want to get test data through variables.

select * from test_num_base.test;

Use variables:

set @A=test_num_base;
But when accessing again, use: select * from @A.test;
Error report: ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@A' at line 1

If you use the splicing method to set:

set @B=concat('test_num_base.' 'test');
Access: select * from @B;
Still reporting an error.
Please explain how to correct it, thank you very much!
About the use of database variables.

伊谢尔伦伊谢尔伦2697 days ago684

reply all(1)I'll reply

  • 为情所困

    为情所困2017-05-31 10:39:04

    Only parameters can reference variables. Table names, views and data dictionaries cannot use variables directly. They can only be used through dynamic sql splicing

    reply
    0
  • Cancelreply