🔥 V7.0 Released! DB2/MySQL migration, 13 new paths, and performance diagnosis.
Free Trial

Table of Contents

1. Key SQL Logic in Source Oracle Database


CREATE OR REPLACE PROCEDURE process_transaction AS
v_balance    NUMBER(10,2);  
v_transfer   NUMBER(10,2) := 10000.00;  
BEGIN

SELECT account_balance 
INTO v_balance 
FROM user_accounts  
WHERE account_id = 12345; 

v_balance := v_balance + TO_NUMBER('2000.00');  

UPDATE user_accounts 
SET account_balance = v_balance - v_transfer
WHERE account_id = 12345;
COMMIT;
END process_transaction;

2. SQL Refactoring Plan for Target MySQL

CREATE PROCEDURE process_transaction()
BEGIN
    DECLARE v_balance DECIMAL(10,2);  
    DECLARE v_transfer DECIMAL(10,2) DEFAULT 10000.00;  
    
    -- Retrieve account balance (row-level lock applied)
    SELECT account_balance 
    INTO v_balance 
    FROM user_accounts 
    WHERE account_id = 12345
    FOR UPDATE;  

    SET v_balance = v_balance + 2000.00;  
    
    UPDATE user_accounts 
    SET account_balance = v_balance - v_transfer
    WHERE account_id = 12345;

    COMMIT;
END;

3. Refactoring Summary

  1. Stored procedure structure refactoring:
    • Replace CREATE OR REPLACE PROCEDURE ... AS with CREATE PROCEDURE().
    • Move variable declarations from the AS block to explicit DECLARE statements.
    • Add FOR UPDATE locking to improve transactional consistency (MySQL default isolation is REPEATABLE READ).
  2. Accurate numeric type mapping:
    • Map NUMBER(10,2) to DECIMAL(10,2) to preserve precision and range.
    • Map BINARY_FLOAT to FLOAT for floating-point operations.
    • Replace TO_NUMBER() with direct numeric operations to avoid implicit-conversion risks.
  3. Variable initialization optimization: replace Oracle := assignments with declarative DEFAULT initialization where applicable.

Image credit: Designed by Freepik

Start Your Free SQLShift Trial Now

Break cross-database barriers and intelligently migrate non-table objects like stored procedures with less effort and lower migration cost.

Start Free Trial