简体   繁体   中英

Convert simple postgreSQL function to Mysql

I was wondering if I could get some help. I have the following function in Postgresql which is designed to give me a "solrid" value without having to store it each time in the database, and basically works by putting an "A" at the start of the value.

-- Setup Solrid Function
CREATE OR REPLACE FUNCTION solrid(IN local_id INTEGER, OUT result TEXT) AS $$
DECLARE
    database_id TEXT := 'A';
BEGIN
    result := database_id || local_id::TEXT;
END;
 $$ LANGUAGE PLPGSQL;

I now have to move my database to MySql and I was wondering if anyone could tell me how I can convert this function to work with MySQL.

Here is the same function in MySQL:

DELIMITER //

DROP FUNCTION IF EXISTS solrid //

CREATE FUNCTION solrid(local_id INTEGER) RETURNS TEXT
BEGIN
  DECLARE database_id TEXT;
  SET database_id = 'A';
  RETURN CONCAT(database_id, CAST(local_id AS CHAR));
END //

DELIMITER ;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM