Skip to content
pvmehta.com

pvmehta.com

  • Home
  • About Me
  • Toggle search form
  • Good Oracle Architecture In Short and point to point Oracle
  • Useful Solaris Commands on 28-SEP-2005 Linux/Unix
  • db_status.sql Oracle
  • import-export with multiple files Oracle
  • Establishing trusted relationship between dbmonitor( central monitoring) and monitoring targets. Linux/Unix
  • CPU speed on Linux Linux/Unix
  • Oracle 11g RAC on OEL 5 and Vmware 2 Oracle
  • proc.sql Oracle
  • lck.sql Oracle
  • Shuffle an array PHP/MYSQL/Wordpress
  • TRUNCATE Privs Oracle
  • plan10g.sql good Oracle
  • Kernel Parameter setting explaination for Processes Parameter Linux/Unix
  • Rename Oracle Instance Name Oracle
  • get_vmstat_solaris 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 current transactions or requests SQL Server
  • SQL Server: How to see historical transactions SQL Server
  • Checking SQL Server Version SQL Server
  • SQL Server Vs Oracle Architecture difference SQL Server
  • Check SQL Server edition 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 (392)
  • PHP/MYSQL/Wordpress (10)
  • POSTGRESQL (0)
  • Power-BI (0)
  • Python/PySpark (7)
  • RAC (17)
  • rman-dataguard (26)
  • shell (149)
  • SQL scripts (341)
  • SQL Server (6)
  • Uncategorized (0)
  • Videos (0)

Recent Posts

  • 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
  • MYSQL and Oracle Comparison for Oracle DBA24-Jul-2025

Archives

  • 2025
  • 2024
  • 2023
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • Good links for x$ tables in oracle. Oracle
  • Jai Shree Ram Oracle
  • Display the top 5 salaries for each department using single SQL Oracle
  • Monitor Long Running Job Oracle
  • pvm_pre_change.sql Oracle
  • Goldengate Tutorial Oracle
  • create database syntax Oracle
  • Good notes on Oracle Events Oracle

Copyright © 2025 pvmehta.com.

Powered by PressBook News WordPress theme