PL/SQL vs MySQL Stored Programs
PL/SQL और MySQL Stored Programs एक Language नहीं हैं
PL/SQL Oracle Database का procedural SQL extension है। MySQL procedures, functions, triggers और scheduled events के लिए अलग stored-program language देता है। Variables, conditions, loops, cursors और error handling जैसे concepts मिलते हैं, लेकिन grammar, objects और runtime behavior अलग हैं।
यह तुलना Oracle PL/SQL और MySQL 8.4 के लिए है। PL/SQL हर database की procedural SQL का generic नाम नहीं है।
PL/SQL vs MySQL Difference Matrix
| Area | Oracle PL/SQL | MySQL |
|---|---|---|
| Anonymous block | DECLARE...BEGIN...EXCEPTION...END | General stored anonymous PL/SQL block नहीं; routine create या client SQL |
| Assignment | v_total := 10 | SET v_total = 10 |
| Parameter | p_id IN NUMBER | IN p_id INT |
| String | VARCHAR2 | VARCHAR |
| Error | EXCEPTION WHEN | HANDLER, SIGNAL, RESIGNAL |
| Module | Package spec/body | Direct package equivalent नहीं |
| Output | DBMS_OUTPUT | SELECT result या structured log |
| Rows | FETCH FIRST/ROWNUM | LIMIT |
| Numbering | Identity/sequence | AUTO_INCREMENT |
Types को similar name से नहीं; range, precision, character semantics और nullability से map करें।
Blocks, Declarations और Variables
Oracle block में optional declaration, required executable और optional exception part होता है। MySQL में declarations BEGIN...END के start पर आते हैं। Order important है: variables/conditions, फिर cursors, फिर handlers।
DELIMITER //
CREATE PROCEDURE show_customer_total(IN p_customer_id INT)
BEGIN
DECLARE v_total DECIMAL(12,2) DEFAULT 0;
SELECT COALESCE(SUM(total_amount), 0)
INTO v_total
FROM orders
WHERE customer_id = p_customer_id;
SELECT v_total AS paid_total;
END //
DELIMITER ;Procedures, Functions और Parameters
दोनों named procedures/functions देते हैं, details अलग हैं। MySQL procedure में mode name से पहले: IN p_id INT, OUT p_total DECIMAL(12,2)। Function inputs लेती, RETURNS declare करती और RETURN चलाती है।
CALL customer_summary(101, @paid_total);
SELECT @paid_total;
SELECT service_fee(1500.00);Oracle packages richer overloading और package state देते हैं। हर overload को same name में रखने का अनुमान न लगाएँ। Explicit names/signatures चुनें और session state को suitable table/application में redesign करें। MySQL में SQL SECURITY DEFINER/INVOKER; Oracle में AUTHID behavior है। Owners blindly copy न करें; least privilege rebuild करें।
Exceptions, Cursors और Diagnostics
Oracle error को EXCEPTION section में route करता है। MySQL block में handlers declare करता है:
DECLARE duplicate_key CONDITION FOR 1062;
DECLARE EXIT HANDLER FOR duplicate_key
BEGIN
ROLLBACK;
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'Order already exists';
END;CONTINUE execution जारी रखता; EXIT declaring block छोड़ता है। UNDO supported नहीं। Structured detail के लिए GET DIAGNOSTICS और current error preserve/augment करने के लिए RESIGNAL use करें।
MySQL cursors asensitive, read-only और nonscrollable हैं। Typical loop में CONTINUE HANDLER FOR NOT FOUND, OPEN, FETCH और CLOSE होते हैं। दोनों systems में set-based SQL first choice रखें।
Packages और Oracle-Specific Features का Redesign
Oracle package public declarations, private implementation, variables और overloads group करता है। MySQL 8.4 में direct spec/body object नहीं। Migration में:
billing_create_invoiceजैसे routine prefixes;- ownership/deployment fit होने पर suitable schema;
- orchestration और external services के लिए application modules;
- durable state के लिए keyed, locked, retained tables;
- narrow permission-controlled interfaces के लिए views/routines।
Sequences, collections, records, %TYPE, %ROWTYPE, bulk collect, FORALL, autonomous transactions, ref cursors, database links, synonyms और Oracle built-ins के one-line equivalents assume न करें।
Worked Migration: Customer Spend
DELIMITER //
CREATE PROCEDURE customer_spend(
IN p_customer_id INT,
OUT p_order_count INT,
OUT p_paid_total DECIMAL(12,2)
)
SQL SECURITY INVOKER
READS SQL DATA
BEGIN
IF p_customer_id IS NULL THEN
SIGNAL SQLSTATE '45000'
SET MESSAGE_TEXT = 'customer_id is required';
END IF;
SELECT COUNT(*), COALESCE(SUM(total_amount), 0)
INTO p_order_count, p_paid_total
FROM orders
WHERE customer_id = p_customer_id
AND status = 'PAID';
END //
DELIMITER ;
CALL customer_spend(101, @orders, @total);
SELECT @orders AS paid_orders, @total AS paid_total;Routine business contract preserve करती है, Oracle punctuation नहीं। Query set-based, NULL input explicit, output precision defined और security context intentional है।
Production Migration Checklist
- हर routine, package, trigger, job, dependency और caller inventory करें।
- Inputs, outputs, effects, errors, transaction owner लिखें।
- Range, precision, timezone, charset/collation से types map करें।
- Oracle-only SQL/built-ins के tested equivalents बनाएँ।
- Packages, state, autonomous work और bulk operations redesign करें।
- Exceptions को conditions, handlers और SIGNAL में convert करें।
- Set-based SQL prefer; cursors/per-row functions benchmark करें।
- Least-privileged definer/invoker privileges rebuild करें।
- Boundary, NULL, concurrency, rollback और retries test करें।
- Controlled Oracle baseline से results/row changes compare करें।
stored procedures, functions, cursors और transactions पढ़ें।
Official संदर्भ
- Oracle 19c: Main Features of PL/SQL
- MySQL 8.4: Compound Statement Syntax
- MySQL 8.4: Stored Program Restrictions
Language structure और migration cautions official Oracle PL/SQL और MySQL 8.4 manuals से verify किए गए हैं।