簡體   English   中英

MySQL-Concat-過程執行失敗

[英]Mysql - Concat - Procedure execution failed

我也有123個表格:M001-> M010-> M123。 每個都是一個客戶。 當它通過觸發器到達父表的記錄時,調用以下函數:

  Declare MasterX  int;
  Set MasterX = New.Master;
  Call Lecturas_Insertar(MasterX,New.Id);

這是我的功能:

BEGIN

#Set Master
  If MasterX < 10 Then 
  Set MasterX = Concat("lecturas.M00",MasterX);
  End If;
#Set Master
  If MasterX Between 10 and 99 Then 
  Set MasterX = Concat("lecturas.M0",MasterX);
  End If;

  set @a=concat("INSERT INTO ",MasterX, "(Id) Values(" ,Id, ")");
  PREPARE stmt1 FROM @a;
  EXECUTE stmt1; 
  DEALLOCATE PREPARE stmt1;

END

但這總是引發以下錯誤:

  Procedure execution failed
  1146 - Table 'lecturas.M' does not exist

感謝大家的幫助

試試這個腳本-

BEGIN
  SET @a = CONCAT('INSERT INTO lecturas.M', LPAD(MasterX, 3, 0), '(Id) Values(', Id, ')');
  PREPARE stmt1 FROM @a;
  EXECUTE stmt1; 
  DEALLOCATE PREPARE stmt1;
END

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM