Mysql
 sql >> база данни >  >> RDS >> Mysql

Съхранена процедура на MySQL с IF/THEN/ELSE

Опитайте тази конструкция

WHILE (@RowCnt <= @MaxRows)
BEGIN
    SELECT @currentReadSeq:=ReadSeq, @currentReadStrength:=ReadStrength, @currentReadDateTime:=ReadDateTime, @currentReaderID:=ReaderID FROM tblTempRead WHERE rownum = @RowCnt;

    IF (((@lastReadSeq + 10) > @currentReadSeq) AND (@lastReaderId = @currentReaderId))
        BEGIN
        SET @lastReadSeq = @currentReadSeq, @lastReadStrength = @currentReadStrength, @lastReadDateTime = @currentReadDateTime, @lastReaderID = @currentReaderID;
        END
    ELSE
        BEGIN
        INSERT INTO tblreaddataresults (SiteID, ReadDateTimeStart, ReadDateTimeEnd,ReadSeqStart, ReadSeqEnd, ReaderID, DirectSeconds) VALUES ('1002',@saveReadDateTime, @lastReadDateTime, @saveReadSeq, @lastReadSeq, @lastReaderID,timestampdiff(SECOND,@saveReadDateTime,@lastReadDateTime));
        SET @saveReadSeq = @currentReadSeq, @saveReadStrength = @currentReadStrength, @saveReadDateTime = @currentReadDateTime, @saveReaderID = @currentReaderID;
        SET @lastReadSeq = @saveReadSeq, @lastReadStrength = @saveReadStrength,@lastReadDateTime = @saveReadDateTime, @lastReaderID = @saveReaderID;
        END
    SET @RowCnt = @RowCnt+1;
END



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Как да предизвикам блокиране на MySQL

  2. Как да създадете динамична матрица в php?

  3. Конструирайте MySQL заявка (таблица meta_key/meta_value)

  4. Има ли алтернатива на IN с LIMIT?

  5. как да оптимизирам този php код за вмъкване на sql?