Pages

🈷️ SQL NCHAR, NVARCHAR2 & INTERVAL

🈷️ SQL Data Types: NCHAR, NVARCHAR2, INTERVAL

In this tutorial, you’ll learn about NCHAR, NVARCHAR2, and INTERVAL — data types used for supporting Unicode characters and handling time durations.

🔤 1️⃣ NCHAR (National Character)

Syntax: NCHAR(n)

Purpose: Stores fixed-length Unicode (international) characters, such as Bangla, Arabic, Chinese.

NCHAR(10) -- Always reserves 10 characters, padding with spaces

Example: Bangla name:

name NCHAR(20)  
-- 'নাসরিন' will be stored as Unicode

📝 2️⃣ NVARCHAR2 (National Variable Character)

Syntax: NVARCHAR2(n)

Purpose: Stores variable-length Unicode text, supports multiple languages like Bangla, Arabic, Chinese without wasting space.

comment NVARCHAR2(200)

Example: Storing a Bangla message or review:

INSERT INTO feedbacks (comment)
VALUES (N'সেবা খুবই ভালো ছিল');

⏳ 3️⃣ INTERVAL

Purpose: Stores time durations or differences — useful for finding the gap between two timestamps or dates.

▶️ INTERVAL YEAR TO MONTH

INTERVAL '2-6' YEAR TO MONTH  
-- means: 2 years and 6 months

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন