<< Chapter < Page Chapter >> Page >

Các phép toán trên chuỗi

Các phép toán thường được dùng nhất trên các chuỗi là phép đối chiếu mẫu sử dụng toán tử LIKE. Ta mô tả các mẫu dùng hai ký tự đặc biệt:

  • ký tự phần trăm (%): ký tự % tương xứng với chuỗi con bất kỳ
  • ký tự gạch nối (_): ký tự gạch nối tương xứng với ký tự bất kỳ.
  • ‘Perry%’ tương xứng với bất kỳ chuỗi nào bắt đầu bởi ‘Perry’
  • ‘%idge%’ tương xứng với bất kỳ chuỗi nào chứa ‘idge’ như chuỗi con
  • ‘___’ tương xứng với chuỗi bất kỳ có đúng ba ký tự
  • ‘___%’ tương xứng với chuỗi bất kỳ có ít nhất ba ký tự

"Tìm tên của tất cả các khách hàng tên phố của họ chứa chuỗi con ‘Main’

SELECT Customer_name

FROM Customer

WHERE Customer_street LIKE ‘%Main%’

Nếu trong chuỗi mẫu có chứa các ký tự % _ \ , để tránh nhầm lẫn ký tự với"dấu hiệu thay thế", SQL sử dụng cách viết: ký tự escape (\) đứng ngay trước ký tự"đặc biệt". Ví dụ nếu chuỗi mẫu là ab%cd được viết là ‘ab\%cd’, chuỗi mẫu là ab_cde được viết là ‘ab\_cde’, chuỗi mẫu là ab\cd được viết là ‘ab\\cd’

SQL cho phép đối chiếu không tương xứng bằng cách sử dụng NOT LIKE

SQL cũng cho phép các hàm trên chuỗi: nối hai chuỗi (|), trích ra một chuỗi con, tìm độ dài chuỗi, biến đổi một chuỗi chữ thường sang chuỗi chữ hoa và ngược lại ...

Thứ tự trình bày các bộ (dòng)

Mệnh đề ORDER BY tạo ra sự trình bày các dòng kết quả của một câu vấn tin theo một trình tự. Để liết kê theo thứ tự alphabet tất cả các khách hàng có vay ở chi nhánh Perryridge:

SELECT DISTINCT Customer_name

FROM Borrower, Loan

WHERE Borrower.Loan_number = Loan.Loan_number AND

Branch_name = ‘Perryridge’

ORDER BY Customer_name;

Mặc nhiên, mệnh đề ORDER BY liệt kê theo thứ tự tăng, tuy nhiên ta có thể làm liệt kê theo thứ tự giảm/tăng bằng cách chỉ rõ bởi từ khoá DESC/ ASC

SELECT *

FROMLoan

ORDER BY Amount DESC, Loan_number ASC;

Các phép toán tập hợp

SQL92 có các phép toán UNION, INTERSECT, EXCEPT chúng hoạt động giống như các phép toán hợp, giao, hiệu trong đại số quan hệ. Các quan hệ tham gia vào các phép toán này phải tương thích (có cùng tập các thuộc tính).

  • Phép toán UNION

“tìm kiếm tất cả các khách hàng có vay, có tài khoản hoặc cả hai ở ngân hàng”

(SELECT Customer_name

FROM Depositor)

UNION

(SELECT Customer_name

FROM Borrower);

Phép toán hợp UNION tự động loại bỏ các bộ trùng, nếu ta muốn giữ lại các bộ trùng ta phải sử dụng UNION ALL

(SELECT Customer_name

FROM Depositor)

UNION ALL

(SELECT Customer_name

FROM Borrower);

  • Phép toán INTERSECT

“tìm kiếm tất cả các khách hàng có vay và cả một tài khoản tại ngân hàng”

(SELECT DISTINCT Customer_name

FROM Depositor)

INTERSECT

(SELECT DISTINCT Customer_name

FROM Borrower);

Phép toán INTERESCT tự động loại bỏ các bộ trùng, Để giữ lại các bộ trùng ta sử dụng INTERSECT ALL

(SELECT Customer_name

FROM Depositor)

INTERSECT ALL

(SELECT Customer_name FROM Borrower);

  • Phép toán EXCEPT

“Tìm kiếm tất cả các khách hàng có tài khoản nhưng không có vay tại ngân hàng”

(SELECT Customer_name

FROM Depositor)

EXCEPT

(SELECT Customer_name

FROM Borrower);

EXCEPT tự động loại bỏ các bộ trùng, nếu muốn giữ lại các bộ trùng phải dùng EXCEPT ALL

(SELECT Customer_name

FROM Depositor)

Questions & Answers

how does Neisseria cause meningitis
Nyibol Reply
what is microbiologist
Muhammad Reply
what is errata
Muhammad
is the branch of biology that deals with the study of microorganisms.
Ntefuni Reply
What is microbiology
Mercy Reply
studies of microbes
Louisiaste
when we takee the specimen which lumbar,spin,
Ziyad Reply
How bacteria create energy to survive?
Muhamad Reply
Bacteria doesn't produce energy they are dependent upon their substrate in case of lack of nutrients they are able to make spores which helps them to sustain in harsh environments
_Adnan
But not all bacteria make spores, l mean Eukaryotic cells have Mitochondria which acts as powerhouse for them, since bacteria don't have it, what is the substitution for it?
Muhamad
they make spores
Louisiaste
what is sporadic nd endemic, epidemic
Aminu Reply
the significance of food webs for disease transmission
Abreham
food webs brings about an infection as an individual depends on number of diseased foods or carriers dully.
Mark
explain assimilatory nitrate reduction
Esinniobiwa Reply
Assimilatory nitrate reduction is a process that occurs in some microorganisms, such as bacteria and archaea, in which nitrate (NO3-) is reduced to nitrite (NO2-), and then further reduced to ammonia (NH3).
Elkana
This process is called assimilatory nitrate reduction because the nitrogen that is produced is incorporated in the cells of microorganisms where it can be used in the synthesis of amino acids and other nitrogen products
Elkana
Examples of thermophilic organisms
Shu Reply
Give Examples of thermophilic organisms
Shu
advantages of normal Flora to the host
Micheal Reply
Prevent foreign microbes to the host
Abubakar
they provide healthier benefits to their hosts
ayesha
They are friends to host only when Host immune system is strong and become enemies when the host immune system is weakened . very bad relationship!
Mark
what is cell
faisal Reply
cell is the smallest unit of life
Fauziya
cell is the smallest unit of life
Akanni
ok
Innocent
cell is the structural and functional unit of life
Hasan
is the fundamental units of Life
Musa
what are emergency diseases
Micheal Reply
There are nothing like emergency disease but there are some common medical emergency which can occur simultaneously like Bleeding,heart attack,Breathing difficulties,severe pain heart stock.Hope you will get my point .Have a nice day ❣️
_Adnan
define infection ,prevention and control
Innocent
I think infection prevention and control is the avoidance of all things we do that gives out break of infections and promotion of health practices that promote life
Lubega
Heyy Lubega hussein where are u from?
_Adnan
en français
Adama
which site have a normal flora
ESTHER Reply
Many sites of the body have it Skin Nasal cavity Oral cavity Gastro intestinal tract
Safaa
skin
Asiina
skin,Oral,Nasal,GIt
Sadik
How can Commensal can Bacteria change into pathogen?
Sadik
How can Commensal Bacteria change into pathogen?
Sadik
all
Tesfaye
by fussion
Asiina
what are the advantages of normal Flora to the host
Micheal
what are the ways of control and prevention of nosocomial infection in the hospital
Micheal
what is inflammation
Shelly Reply
part of a tissue or an organ being wounded or bruised.
Wilfred
what term is used to name and classify microorganisms?
Micheal Reply
Binomial nomenclature
adeolu
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Hệ quản trị cơ sở dữ liệu. OpenStax CNX. Jul 31, 2009 Download for free at http://cnx.org/content/col10838/1.1
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Hệ quản trị cơ sở dữ liệu' conversation and receive update notifications?

Ask