首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Create Procedure on MYSQL语法

Create Procedure on MYSQL语法
EN

Stack Overflow用户
提问于 2015-04-22 21:43:11
回答 1查看 45关注 0票数 0

我大部分时间都在Oracle db上工作,但现在我必须在mysql数据库上创建一个过程。但是,我不知道它的语法。我必须将下面的过程转换为mysql语法。

我应该更改哪些参数?

代码语言:javascript
复制
CREATE OR REPLACE procedure schema.procedure IS
    l_sender              varchar2(200);
    l_recipient           varchar2(1000);
    l_subject             varchar2(100);
    l_msg                   varchar2(32760);  
    l_content_desc    varchar2(32760);
    l_count number := 0;
    l_time number;
    content_desc    varchar2(32760);
    l_body clob;
    counter number:=0;
 begin

l_subject := '';  
l_msg := '';    
l_sender := 'mail1';
l_recipient :=’mail2’;
l_subject   :=  to_char(sysdate-1, 'dd/mm/yyyy')|| '     '||xyzkcqlncqnl ';
l_msg := '';

  FOR r in (
    MY QUERY )

  LOOP
  if(mod(counter,2)=0) then
    l_body:=l_body||'<TR>';
    l_body:=l_body||'<TD BGCOLOR="#DCEFFE">'||r.ABC||'</TD>';
    l_body:=l_body||'<TD BGCOLOR="#DCEFFE">'||r.DEF||'</TD>';
    l_body:=l_body||'<TD BGCOLOR="#DCEFFE">'||r.GHI||'</TD>';
    l_body:=l_body||'<TD BGCOLOR="#DCEFFE">'||r.JKL||'</TD>';
    l_body:=l_body||'<TD BGCOLOR="#DCEFFE">'||r.MNO||'</TD>';
    l_body:=l_body||'</TR>';
    counter:=counter+1;
   else
    l_body:=l_body||'<TR>';
    l_body:=l_body||'<TD>'||r. ABC||'</TD>';
    l_body:=l_body||'<TD>'||r. DEF ||'</TD>';
    l_body:=l_body||'<TD>'||r. GHI ||'</TD>';
    l_body:=l_body||'<TD>'||r. JKL ||'</TD>';
    l_body:=l_body||'<TD>'||r. MNO ||'</TD>';
    l_body:=l_body||'</TR>';
    counter:=counter+1;
 end if;
   END LOOP;
content_desc:=content_desc||'<TABLE BORDER=1 BGCOLOR="#FFFFFF" style="font-       size:9pt;text-align:left;">';
content_desc:=content_desc||'<TR>';
content_desc:=content_desc||'<TH style="text-align:left;"  BGCOLOR="#ADCBFD">SCHEMA'||'</TD>';
content_desc:=content_desc||'<TH style="text-align:left;"  BGCOLOR="#DCEFFE">TEXT'||'</TD>';
content_desc:=content_desc||'</TR>';
content_desc:=content_desc||'<TR>';
content_desc:=content_desc||'<TH style="text-align:left;"  BGCOLOR="#ADCBFD">PROCEDURE NAME'||'</TD>';
content_desc:=content_desc||'<TH style="text-align:left;"  BGCOLOR="#DCEFFE" ‘NAME||'</TD>';
content_desc:=content_desc||'</TR>';
content_desc:=content_desc||'<TR>';
content_desc:=content_desc||'<TH style="text-align:left;"  BGCOLOR="#ADCBFD">JOB NAME'||'</TD>';
content_desc:=content_desc||'<TH style="text-align:left;"  BGCOLOR="#DCEFFE">REPORT'||'</TD>';
content_desc:=content_desc||'</TR>';
content_desc:=content_desc||'<TR>';
content_desc:=content_desc||'<TH style="text-align:left;"  BGCOLOR="#ADCBFD">INTERVAL'||'</TD>';
content_desc:=content_desc||'<TH style="text-align:left;"  BGCOLOR="#DCEFFE">DAILY / 00:00'||'</TD>';
content_desc:=content_desc||'</TR>';
content_desc:=content_desc||'<TR>';
content_desc:=content_desc||'<TH style="text-align:left;"  BGCOLOR="#ADCBFD">PLSQL LINK'||'</TD>';
content_desc:=content_desc||'<TH style="text-align:left;"  BGCOLOR="#DCEFFE"><a href=" ">VIEW PLSQL</a>'||'</TD>';
content_desc:=content_desc||'</TR>';
content_desc:=content_desc||'</TABLE><BR/><BR/>'; 
content_desc:=content_desc||'<TABLE BORDER=1 BGCOLOR="#FFFFFF">';
content_desc:=content_desc||'<TR>';
content_desc:=content_desc||'<TH BGCOLOR="#ADCBFD">ABC||'</TD>';
content_desc:=content_desc||'<TH BGCOLOR="#ADCBFD">DEF’||'</TD>';
content_desc:=content_desc||'<TH BGCOLOR="#ADCBFD">GHI||'</TD>';
content_desc:=content_desc||'<TH BGCOLOR="#ADCBFD">JKL'||'</TD>';
content_desc:=content_desc||'<TH BGCOLOR="#ADCBFD">MNO'||'</TD>';  
content_desc:=content_desc||'</TR>';
content_desc:=content_desc||l_body;
content_desc:=content_desc||'</TABLE>';                

l_msg := content_desc||  chr(13) || chr(10) ||  chr(13) || chr(10)||  chr(13) || chr(10)||  chr(13) || chr(10)||  chr(13) || chr(10);


l_msg := l_msg ||to_char(sysdate-1, 'dd/mm/yyyy')||'      '||text' || chr(13) || chr(10);

SCHEMA.email_html ( l_recipient,l_sender,l_subject,'test',l_msg, ,);
SCHEMA.email_html ( l_recipient1,l_sender,l_subject,'test',l_msg, ,);     
end;
/

我的版本:

代码语言:javascript
复制
 DELIMITER //
 CREATE PROCEDURE SCHEMA.procedure (
 IN loc_ooooor VARCHAR(255),
 IN loc_ccccccn VARCHAR(255),
 IN loc_tttttt VARCHAR(255),
 IN loc_bbbbb VARCHAR(255),
 IN loc_bbbbbbb VARCHAR(255),
 IN loc_ccccccc INT(255)
 )
  BEGIN

  counter=0;

  FOR r in (
  MY QUERY)

  <table border="1">
  <tr>
   <th>Ooooooo</th>
   <th>AAAAAAAAAAA</th>
   <th>HHHHH</th>
   <th>UUUUUU</th>
   <th>BBBBBBB</th>
  </tr>
  </table>

   LOOP
   if(mod(counter,2)=0) then
   <table border="1">
   <tr>
    <th>||r.ddddddd||</th>
    <th>||r.cccccccc||</th>
    <th>||r.ttttttt||</th>
    <th>||r.sssssss||</th>
    <th>||r.rrrrrrrr||</th>
   </tr>
   </table>
   loc_counter=loc_counter+1;
   else if;
  END LOOP;
  END //
 DELIMITER;
EN

回答 1

Stack Overflow用户

发布于 2015-04-23 21:13:16

代码语言:javascript
复制
DROP PROCEDURE IF EXISTS udsp_Name;
DELIMITER //
CREATE PROCEDURE udsp_Name
(   var_Param1          VARCHAR(70)     ,
    var_Param2                  NVARCHAR(100)   
)
BEGIN
    -- --------------------------------------------------------------------------
    -- 01 Variable Declaration
    -- --------------------------------------------------------------------------
    DECLARE error_InvalidInputs         CONDITION FOR SQLSTATE 'HY000';
    DECLARE var_NewId                   VARCHAR(36);

    DECLARE EXIT HANDLER FOR SQLSTATE '22001'                               
    BEGIN                               
        ROLLBACK;                           
        SIGNAL SQLSTATE '22001';                                
    END;

    -- --------------------------------------------------------------------------
    -- 02 Input Variable Initialization
    -- --------------------------------------------------------------------------
    SET var_Param1      = IFNULL(var_Param1,''); 
    SET var_Param2              = IFNULL(var_Param2,'');

    -- --------------------------------------------------------------------------
    -- 03 Mandatory Check
    -- --------------------------------------------------------------------------
    IF var_Param1 ='' OR var_Param1='' THEN
        SIGNAL error_InvalidInputs
        SET MESSAGE_TEXT    = 'Mandatory fields are not provided', 
        MYSQL_ERRNO     = 2002;
    END IF;

    -- --------------------------------------------------------------------------
    -- 04 Creating Content Template
    -- --------------------------------------------------------------------------

    START TRANSACTION;  -- optional
    -- your query here 
    COMMIT; -- optional if added txn


END //

DELIMITER ;

这是正确的虚拟语法MySQL Reference

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29799481

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档