How to execute a SQL statement concatenated with a variable in a Procedure in MySQL

2

I'm creating a procedure to create a base and some tables within that base. I get the name of the base to be created by parameter.

I'm having trouble concatenating this parameter next to the table creation script.

Below is the code I did:

CREATE PROCEDURE criar_base_empresa(IN empresa VARCHAR(14))
  BEGIN
    CREATE DATABASE IF NOT EXISTS empresa;
    CREATE TABLE IF NOT EXISTS empresa.'notas' (
      'id'        INT(11)     NOT NULL AUTO_INCREMENT,
      'dtEmissao' DATE        NOT NULL,
      'modelo'    CHAR(2)     NOT NULL,
      'valor'     FLOAT(9, 2) NOT NULL,
      PRIMARY KEY ('id')
    );

  END //

CALL criar_base_empresa('99999999999')

If I run, the base that is created is 'company' and not '99999999999'.

Note that the bank name has only numbers, so you would have to put the name of the bank between "(apostrophes)."

    
asked by anonymous 29.12.2017 / 14:29

0 answers