MSK Institute • Shikohabad
Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Connecting serverPlease wait...
💻 Practical Labs🚀 Free Demo📜 Verified Certificates
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Both Stored Procedures and Stored Functions allow developers to encapsulate database logic. However, they serve completely different architectural purposes in application system design.
Selecting the appropriate routine type impacts query composability, transaction boundaries, and system maintainability.
| Dimension | Stored Function | Stored Procedure |
|---|---|---|
| Return Value | Must return exactly one scalar value via RETURNS / RETURN | May return zero, one, or multiple result sets, or use OUT params |
| Invocation | Embedded inline in SQL (SELECT fn(x), WHERE fn(x) > 10) | Invoked independently using CALL proc() |
| Parameters | Only IN parameters permitted | Supports IN, OUT, and INOUT parameters |
| Transaction Management | Cannot manage transactions (No COMMIT or ROLLBACK) | Full transaction control (START TRANSACTION, COMMIT, ROLLBACK) |
| DML Statements | Generally restricted to read-only calculations (cannot alter tables in queries) | Can execute arbitrary INSERT, UPDATE, DELETE, and DDL |
| Composability | High: Can be combined with other expressions in joins and projections | Low: Cannot be nested inside a SELECT expression |
SELECT queries, views, or reports.COMMIT / ROLLBACK) and exception handlers.OUT parameters.Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Working with Cursors: Declare, Open, Fetch, Close | Trigger Fundamentals & Event Hooks |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.