在MYSQL语法

时间:2015-04-22 13:43:11

标签: mysql syntax procedure

我大部分时间都在使用Oracle DB,但现在我必须在mysql db上创建一个过程。但是,我不知道它的语法。我必须将下面的过程翻译成mysql语法。

我应该更改哪些参数?

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;
/

我的版本:

 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;

1 个答案:

答案 0 :(得分:0)

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