MYSQL - 使用PREPARE和EXECUTE给我错误#1064

时间:2018-01-02 03:17:03

标签: mysql prepared-statement

我正在尝试创建一个仅在特定布尔值标记为true时才返回表的过程。

这是我的表:

CREATE TABLE company (
    id              INT         NOT NULL    AUTO_INCREMENT,
    name            VARCHAR(50) NOT NULL,
    is_grocery_store            BIT(1)  NOT NULL DEFAULT b'0',
    is_restaurant               BIT(1)  NOT NULL DEFAULT b'0',
    is_entertainment            BIT(1)  NOT NULL DEFAULT b'0',
    is_retail_store             BIT(1)  NOT NULL DEFAULT b'0',
    is_financial_institution    BIT(1)  NOT NULL DEFAULT b'0',
    is_mortgage_company         BIT(1)  NOT NULL DEFAULT b'0',
    is_medical_establishment    BIT(1)  NOT NULL DEFAULT b'0',
    is_insurance_agency         BIT(1)  NOT NULL DEFAULT b'0',
    PRIMARY KEY (id)
)

以下是程序:

CREATE PROCEDURE get_company (IN CORPORATION ENUM(
        'grocery_store',
        'restaurant',
        'entertainment',
        'retail_store',
        'financial_institution',
        'mortgage_company',
        'medical_establishment',
        'insurance_agency'
    ))

    SET @sql = "SELECT * FROM company WHERE is_? = b'1'");
    PREPARE stmt FROM @sql;
    EXECUTE stmt USING FAMILY_ID, CORPORATION;
    DEALLOCATE PREPARE stmt;

我插入了一堆行,这里是我调用过程的地方:

CALL get_company('financial_institution');

当我尝试运行它时,我收到以下错误:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'NULL' at line 1
  

请注意,我使用phpMyAdmin上的SQL选项卡来运行此代码,但他们不使用delimiter //BEGINEND。这不是问题。

0 个答案:

没有答案