Các Function Trong Oracle - Chia Sẻ Mọi Kiến Thức Về SQL Server

Breaking News Loading... 15/02/2014 Home » function » Oracle » Oracle Developer » Oracle Function » Các function trong Oracle Các function trong Oracle Vinh Aqua 11:37 function Oracle Oracle Developer Oracle Function Hôm nay tôi dành một ít thời gian nghiên cứu các built-in functions, tức là các function có sẵn trong Oracle, mục tiêu là tương lai tôi có thể xử lý công việc lập trình trên cả SQL Server lẫn Oralce. Trong Oracle, tôi khám phá được các function sau, kèm theo là ví dụ: SUBSTR: lấy một đoạn ký tự con trong một chuỗi DECLARE r VARCHAR2(50):='mai quang vinh'; BEGIN dbms_output.put_line(SUBSTR(r, 1, 1)); END; Kết quả trả về sẽ là m CHR: ta có thể sử dụng hàm này để chèn một ký tự xuống dòng vào DECLARE text1 VARCHAR2(10) := 'Title'; text2 VARCHAR2(10) := 'Content'; BEGIN dbms_output.put_line(text1||CHR(10)||text2); END; CONCAT(string1, string2): nối chuỗi INITCAP: hàm này vô cùng hữu dụng, ví dụ ta có một chuỗi và ta muốn viết hoa ký tự đầu của mỗi từ, những ký tự còn lại viết thường DECLARE text VARCHAR2(12) := 'hello world!'; BEGIN dbms_output.put_line(INITCAP(text)); END; INSTR: tìm vị trí nơi một chuỗi con bắt đầu trong 1 chuỗi cha DECLARE text VARCHAR2(12) := 'Hello World!'; BEGIN dbms_output.put_line('Start ['||INSTR(text,'World',1)||']'); END; Kết quả trả về sẽ là Start [7] LENGTH: hàm này đơn giản, trả về chiều dài của chuỗi LTRIM: cắt bỏ khoảng trắng ở đầu một chuỗi. Hàm này giống bên SQL Server. LPAD(output_string, output_length, padding_character): cho phép ta thêm một ký tự một hay nhiều lần vào vị trí đầu của một chuỗi RPAD(output_string, output_length, padding_character): giống hàm LPAD ở trên, nhưng ở vị trí cuối REPLACE(base_string, search_string, replace_string): thay thế một chuỗi con bằng một chuỗi khác UPPER, LOWER: 2 hàm này viết thường, viết hoa một chuỗi, giống bên SQL Server. COALESCE: tìm phần tử đầu tiên không null trong một tập hợp, giống bên SQL Server. DECODE: cú pháp như sau: DECODE(evaluation_expression, comparison_expression1, true_expression1 , comparison_expression2, true_expression2 , comparison_expression(n+1), true_expression(n+1) , comparison false_expression); Hàm Decode này thực thi tương tự như cấu trúc if-then-else and if-then-else-if-then-else trong SQL DECLARE redsox NUMBER := 96; yankees NUMBER := 94; division NUMBER := 96; headline VARCHAR2(30); BEGIN SELECT DECODE(division,yankees,'Yankees clinch pennant.' ,redsox,'Red Sox clinch pennant.' ,'Tied Again!') INTO headline FROM dual; dbms_output.put_line(headline); END; CÁC HÀM VỀ XỬ LÝ SỐ CEIL: hàm này cho phép ta làm tròn số với giá trị tiếp theo lớn hơn giá trị hiện tại DECLARE n NUMBER := 4.1; BEGIN dbms_output.put_line('Ceiling ['||CEIL(n)||']'); END; Kết quả sẽ là Ceiling [5] MODE: lấy phần dư của một phép chia REMAINDER: lấy phần dư của một phép chia, giống hàm MODE, nhưng hàm này có 1 chút khác biệt, chạy ví dụ sau đây sẽ rõ. DECLARE n NUMBER := 16; m NUMBER := 3.24; BEGIN dbms_output.put_line('Remainder ['||REMAINDER(n,m)||']'); dbms_output.put_line('Remainder ['||MOD(n,m)||']'); END; POWER: hàm này là tính lũy thừa của 1 số DECLARE n NUMBER := 3; m NUMBER := 4; BEGIN dbms_output.put_line('Cube of ['||n||'] is ['||POWER(n,m)||']'); END; Kết quả sẻ là 81, vì là 3*3*3*3=81 FLOOR: cắt đi phần thập phân của một số, giữ lại phần nguyên DECLARE n NUMBER := 4.44; BEGIN dbms_output.put_line('Flooring ['||FLOOR(n)||']'); END; Share: Newer Post Older Post

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Danh mục

  • ...
  • 32 bit - 64 bit
  • Active Directory
  • administrator
  • Agent Job
  • aggregate
  • alert
  • alias
  • alter
  • alwayson
  • amazon
  • Analysis Services
  • analytic function
  • Attach
  • backup
  • bad practice
  • bcp
  • BI
  • Big Data
  • block
  • blocking
  • bottleneck
  • buffer pool
  • Bulk insert
  • Business Intelligence
  • C#
  • Capacity Planning
  • career path
  • case
  • cast
  • Certtificate
  • check list
  • CLR
  • Clustered index
  • collation
  • column
  • common language runtime
  • compare
  • compression
  • computed column
  • concurrency
  • configuration
  • Configuration Manager
  • constraint
  • Control Flow
  • convert
  • corrupt
  • count
  • covering index
  • CPU bottleneck
  • cross apply
  • CTE
  • cumulative update
  • cursor
  • cxpacket
  • data analyst
  • data cache
  • data mining
  • Data Mining Algorithm
  • Data Quality
  • data quality services
  • data type
  • Data Warehouse
  • database
  • database mail
  • database snapshot
  • date
  • DAX
  • DBCC
  • deadlock
  • demo
  • derived table
  • design
  • detach
  • diagnose
  • Dimension table
  • disaster recovery
  • distinct
  • DMV
  • DMX
  • duplicate
  • Dynamic Query
  • Error handling
  • Error log
  • event log
  • Excel
  • execute as
  • execution plan
  • exists
  • Experts
  • export
  • express
  • Extended Events
  • file
  • filegroup
  • foreach
  • format string
  • Fragmentation
  • function
  • generate script
  • gioi-thieu
  • Goto
  • hadoop
  • hardware
  • heap
  • high availability
  • hint
  • history
  • I/O
  • I/O Best Practices
  • I/O bottleneck
  • implicit conversion
  • import
  • IN
  • index
  • index fragmentation
  • index scan
  • index seek
  • indexed view
  • insert
  • inside
  • Instant file initialization
  • Integration Services
  • Internal SQL
  • interview
  • isolation level
  • join
  • latch
  • Line number
  • linked server
  • lock
  • log
  • log shipping
  • Logi Info
  • Logi Info Chart
  • login
  • loop
  • mail
  • maintenance
  • mapreduce
  • master data services
  • max
  • max server memory
  • maxdop
  • Measure
  • memory
  • Memory bottleneck
  • Memory pressure
  • missing index
  • misunderstanding
  • MongoDB
  • MongoDB syntax
  • monitor
  • msdb
  • Multidimensional Model
  • mysq
  • mysql
  • mysql administrator
  • mysql common_schema
  • mysql cursor
  • mysql developer
  • mysql format string
  • mysql function
  • mysql index
  • mysql monitor
  • mysql performance
  • mysql schema
  • mysql tool
  • mysql webyod
  • nonclustered index
  • nosql
  • NULL
  • Oracle
  • Oracle Administrator
  • Oracle Developer
  • Oracle Function
  • order
  • orphaned user
  • output
  • over
  • page split
  • paging
  • parallelism
  • parameter sniffing
  • partition
  • path
  • performance counter
  • performance tuning
  • performance tuning secret
  • permission
  • Pig
  • pivot
  • PL/SQL
  • plan cache
  • policy management
  • poor query
  • postgreSQL
  • Power View
  • PowerPivot
  • PowerShell
  • PowerView
  • primary key
  • procedure cache
  • processor
  • profiler
  • Python
  • question-answer
  • R
  • Raid
  • random
  • ranking
  • recompilation
  • red gate
  • Regex
  • replication
  • Reporting Services
  • restore
  • retailer
  • rewrite query
  • RowCount
  • running queries
  • scale out
  • schema
  • search
  • security
  • Self Service BI
  • server trace
  • service broker
  • sessionid
  • shard
  • shrink
  • sort
  • source code
  • sp_spaceused
  • sp_who
  • sp_who2
  • spid
  • SQL 2012
  • SQL 2014
  • SQL Agent
  • SQL Course
  • sql feature
  • SQL log
  • SQL Server Management Studio
  • sql version
  • sqlcmd
  • sqlserver
  • SSAS
  • SSIS
  • SSIS 2012
  • SSIS Best Practices
  • SSIS Excel
  • SSIS Performance
  • SSMS
  • SSRS
  • SSRS Image
  • SSRS variable
  • star schema
  • statistics
  • storage
  • stored procedure
  • stuff
  • sub query
  • suspect database
  • synchronize
  • system database
  • t-sql
  • T-SQL optimization
  • table
  • table value parameter
  • table variable
  • Tabular Model
  • tempdb
  • temporary table
  • tip
  • Tools
  • tools for dba
  • top query
  • transaction
  • transaction log
  • Trigger
  • trim
  • troubleshooting
  • truncate
  • try...catch
  • UDF
  • unpivot
  • update
  • user
  • wait_type
  • waitfor
  • WhoIsActive
  • Window Function
  • WMI
  • workload
  • XML

My Blog List

  • Paul S. Randal New course: SQL Server 2025 Vector Search Essentials 3 days ago
  • SQLskills.com Protected: IE Query Store Recordings 5 years ago
  • Microsoft SQL Server Integration Services Fixed IP addresses for ADF Integration Runtimes 5 years ago
  • Microsoft SQL Server Knowledge Bank SQL Server Performance Quick Fixer 6 years ago
  • Sam Vanga How Do You Ensure Data Integrity in Cubes? 10 years ago
  • SQL Việt blog Agile Và Tư Duy Chiều Ngang 10 years ago
  • Brad M McGehee At the End of One Chapter and the Beginning of a New Chapter 13 years ago
  • Robert Sheldon
  • mssqltips
  • What's going on

Lượt xem trang

Facebook

  Toggle Footer

Từ khóa » Hàm Làm Tròn Lên Trong Oracle