Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • checking connectivity between two servers Linux/Unix
  • Vivek’s egrep commands to trace problem. (on linux x86-64) Linux/Unix
  • Virtual Indexes in Oracle Oracle
  • Distributed Transaction Troubleshooting. Oracle
  • Pending Transaction Neighbors Script Oracle
  • To see how much time or progress of long transaction Oracle
  • .profile Linux/Unix
  • Jai Shree Ram Oracle
  • Rownum with Order by Oracle
  • proper cpu stats Linux/Unix
  • Explain Plan Output 2 Oracle
  • Search and replace pattern Linux/Unix
  • Removing first line Linux/Unix
  • Composite Index creation tip from Vivek Oracle
  • CTAS with LONG Column for 7.x and 8 and 8i Oracle

T-SQL Vs PL/SQL Syntax

Posted on 25-Jul-202525-Jul-2025 By Admin No Comments on T-SQL Vs PL/SQL Syntax

Below is a side-by-side comparison of Oracle PL/SQL and SQL Server T-SQL for someone coming from a PL/SQL background. This will help you quickly understand the syntax and behavior differences.


🔄 PL/SQL vs T-SQL Syntax Comparison

Concept / OperationOracle PL/SQL SyntaxSQL Server T-SQL Syntax
Anonymous BlockBEGIN ... END;BEGIN ... END (no semicolon required)
Variable DeclarationDECLARE v_name VARCHAR2(50);DECLARE @v_name VARCHAR(50);
Assignmentv_name := 'Hello';SET @v_name = 'Hello'; or SELECT @v_name = 'Hello';
Output MessageDBMS_OUTPUT.PUT_LINE('Hello');PRINT 'Hello';
IF StatementIF condition THEN ... ELSIF ... ELSE ... END IF;IF condition BEGIN ... END ELSE BEGIN ... END
LOOP (Simple Loop)LOOP ... EXIT WHEN condition; END LOOP;WHILE 1 = 1 BEGIN ... IF condition BREAK; END
FOR Loop (Numeric)FOR i IN 1..5 LOOP ... END LOOP;DECLARE @i INT = 1; WHILE @i <= 5 BEGIN ... SET @i += 1; END
WHILE LoopWHILE condition LOOP ... END LOOP;WHILE condition BEGIN ... END
Procedure DeclarationCREATE OR REPLACE PROCEDURE proc_name IS BEGIN ... END;CREATE PROCEDURE proc_name AS BEGIN ... END
Function DeclarationCREATE OR REPLACE FUNCTION func_name RETURN TYPE IS BEGIN ... END;CREATE FUNCTION func_name() RETURNS TYPE AS BEGIN ... RETURN ... END
Calling ProcedureEXEC proc_name; or BEGIN proc_name; END;EXEC proc_name; or EXECUTE proc_name;
Exception HandlingBEGIN ... EXCEPTION WHEN ... THEN ... END;BEGIN TRY ... END TRY BEGIN CATCH ... END CATCH;
Transactions (Manual)COMMIT; / ROLLBACK;BEGIN TRAN; / COMMIT; / ROLLBACK;
CURSOR DeclarationCURSOR cur IS SELECT ...;DECLARE cur CURSOR FOR SELECT ...
CURSOR LoopingOPEN cur; FETCH ...; EXIT WHEN ...; CLOSE cur;OPEN cur; FETCH NEXT FROM cur INTO ...; WHILE @@FETCH_STATUS = 0 ...
Temporary TableCREATE GLOBAL TEMPORARY TABLE ...CREATE TABLE #temp_table (...)
Autonumber / SequenceCREATE SEQUENCE seq_name ...IDENTITY column or SEQUENCE (since SQL Server 2012)
String Concatenation`’Hello’
Getting Current DateSYSDATEGETDATE() or SYSDATETIME()
Dual Table for SELECTSELECT 1 FROM DUAL;SELECT 1;

🧠 Key Behavioral Differences

FeaturePL/SQL (Oracle)T-SQL (SQL Server)
CompilationPL/SQL is compiled into bytecodeT-SQL is interpreted or compiled to native code
Exception HandlingStructured, robust EXCEPTION blockTRY...CATCH block
Package SupportYes (with procedures, functions, variables)No native package support
Autonomous TransactionsSupported with PRAGMA AUTONOMOUS_TRANSACTIONNot directly supported
RETURNING ClauseSupported in DML (e.g., RETURNING INTO)Only in OUTPUT clause with INSERT/UPDATE/DELETE
Procedural ConstructsRich in-built procedural featuresBasic procedural constructs

SQL Server

Post navigation

Previous Post: Check SQL Server edition
Next Post: SQL Server: How to see current transactions or requests

Related Posts

  • SQL Server: How to see historical transactions SQL Server
  • SQL Server: How to see current transactions or requests SQL Server
  • Check SQL Server edition SQL Server
  • SQL Server Vs Oracle Architecture difference SQL Server
  • Checking SQL Server Version SQL Server

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Categories

  • Ansible (0)
  • AWS (2)
  • Azure (1)
  • Linux/Unix (149)
  • MYSQL (5)
  • Oracle (393)
  • PHP/MYSQL/Wordpress (10)
  • POSTGRESQL (0)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (17)
  • rman-dataguard (26)
  • shell (149)
  • SQL scripts (342)
  • SQL Server (6)
  • Uncategorized (0)
  • Videos (0)

Recent Posts

  • Trace a SQL session from another session using ORADEBUG30-Sep-2025
  • SQL Server Vs Oracle Architecture difference25-Jul-2025
  • SQL Server: How to see historical transactions25-Jul-2025
  • SQL Server: How to see current transactions or requests25-Jul-2025
  • T-SQL Vs PL/SQL Syntax25-Jul-2025
  • Check SQL Server edition25-Jul-2025
  • Checking SQL Server Version25-Jul-2025
  • Oracle vs MYSQL Architecture differences (For DBAs)24-Jul-2025
  • V$INSTANCE of Oracle in MYSQL24-Jul-2025
  • Day to day MYSQL DBA operations (Compared with Oracle DBA)24-Jul-2025

Archives

  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • switchover for primary database Oracle
  • 272332.1 CRS 10g Diagnostic Collection Guide Oracle
  • Monitor and Trace Unix processes using truss Linux/Unix
  • Consolidated Reference List Of Notes For Migration / Upgrade Service Requests -ID 762540.1 Oracle
  • crontab syntax Linux/Unix
  • Goldengate Tutorial Oracle
  • Temporary tablespace explaination Oracle
  • Windows based Command line mailing program like mailx (Sednmail for windows) PHP/MYSQL/Wordpress

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme