Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • My Test Case On 21-OCT-2005 Oracle
  • Directory wise folder wise space usage Linux/Unix
  • plan10g.sql Oracle
  • Zip and unzip with tar Linux/Unix
  • When error comes for temporary tablespace with version <= 9i Oracle
  • oracle_env_10g_CADEV Linux/Unix
  • Creating a Container Database using dbaascli Uncategorized
  • Sample WW22 listener.ora Oracle
  • runon_allcdbs_find_pdbs.sql Oracle
  • Find total file sizes Linux/Unix
  • catting.sh Linux/Unix
  • Reading config file from other folder inside class Python/PySpark
  • create database link syntax Oracle
  • Pending Distributed Transations Oracle
  • Handling LOB data in Oracle 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 Vs Oracle Architecture difference SQL Server
  • 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
  • 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)
  • Django (0)
  • GIT (1)
  • Linux/Unix (149)
  • MYSQL (5)
  • Oracle (402)
  • PHP/MYSQL/Wordpress (10)
  • POSTGRESQL (1)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (18)
  • rman-dataguard (26)
  • shell (150)
  • SQL scripts (350)
  • SQL Server (6)
  • Uncategorized (5)
  • Videos (0)

Recent Posts

  • SAT Mathematics 10 questions and answer at the end.30-Apr-2026
  • top 10 AI news today30-Apr-2026
  • runon_allpdbs_show_conname.sh23-Apr-2026
  • runon_allcdbs_find_pdbs.sql23-Apr-2026
  • Running PDB on single node in RAC09-Apr-2026
  • find_arc.sql09-Apr-2026
  • pvm_pre_change.sql08-Apr-2026
  • find_encr_wallet.sql08-Apr-2026
  • find_pdbs.sql08-Apr-2026
  • Creating a Container Database using dbaascli08-Apr-2026

Archives

  • 2026
  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • sess_server.sql Oracle
  • Giving Grant on v$DATABASE Oracle
  • Running some SQL on multiple databases connecting using monitoring userid and password Linux/Unix
  • Find sort details from Db find_sort.sql Oracle
  • remove archfiles only when it is applied to DR rm_archfiles.sh Linux/Unix
  • cold backup scripts to copy locally Linux/Unix
  • Wait.sql Oracle
  • Exadata Basics Oracle

Copyright © 2026 pvmehta.com.

Powered by PressBook News WordPress theme