SELECT product_name
FROM oe.product_information
WHERE regexp_like (product_name, 'SS[PS]/[VS]');
REGEXP_INSTR å½æ°è¿åå符串ä¸ç»å®æ¨¡å¼çä½ç½®ãæ£æ¥è¯æ³ï¼
REGEXP_INSTR(srcstr, pattern [, position [, occurrence
[, return_option [, match_option]]]])
å¨è¯¥å½æ°ä¸ï¼
positionï¼æ¯æç´¢çèµ·å§ä½ç½®
occurrenceï¼æ¯è¦æç´¢çå¹é
项
return_optionï¼æ示å¹é
项çå¼å¤´æç»å°¾ä½ç½®
match_optionï¼æä¾äºæ´æ¹é»è®¤å¹é
çé项ãå®å¯ä»¥å
å«ä»¥ä¸ä¸ä¸ªæå¤ä¸ªå¼ï¼
âcâï¼ä½¿ç¨åºå大å°åçå¹é
ï¼é»è®¤å¼ï¼
âiâï¼ä½¿ç¨ä¸åºå大å°åçå¹é
ânâï¼å
许å¹é
ä»»ä½å符çè¿ç®ç¬¦æ¥å¹é
æ¢è¡ç¬¦
âmâï¼å°æºå符串ä½ä¸ºå¤è¡å¤ç
è¦æç´¢è¿äºäº§åå称以æ¾å°ç¬¬ä¸ä¸ªéåæ¯å符ï¼æ 论å®æ¯å¤§åè¿æ¯å°åï¼çä½ç½®ï¼æ§è¡ä»¥ä¸èæ¬ï¼
@reinstr.sql
COLUMN product_name FORMAT a45
COLUMN non_alpha FORMAT 9999999999
SELECT product_name, REGEXP_INSTR(product_name, '[^[:alpha:]]') non_alpha
FROM oe.product_information ;
请注æï¼[^[:<class>:]]表示ä¸ä¸ªå符类ï¼å¹¶å¹é
该类ä¸çä»»ä½å符ï¼[:alpha:]å¹é
ä»»ä½åæ¯å符ãå¨æ¬ç¤ºä¾ä¸ï¼æ¨å°éè¿ä½¿ç¨ ^ 对该表达å¼åéã
REGEXP_SUBSTR å½æ°æ ¹æ®å¹é
项ç模å¼è¿åç»å®å符串ãæ£æ¥è¯æ³ï¼
REGEXP_SUBSTR(srcstr, pattern [, position
[, occurrence [, match_option]]])
å¨è¯¥å½æ°ä¸ï¼
positionï¼æ¯æç´¢çèµ·å§ä½ç½®
occurrenceï¼æ¯è¦æç´¢çå¹é
项
match_optionï¼æä¾äºæ´æ¹é»è®¤å¹é
çé项ãå®å¯ä»¥å
å«ä»¥ä¸ä¸ä¸ªæå¤ä¸ªå¼ï¼
âcâï¼ä½¿ç¨åºå大å°åçå¹é
ï¼é»è®¤å¼ï¼
âiâï¼ä½¿ç¨ä¸åºå大å°åçå¹é
ânâï¼å
许å¹é
ä»»ä½å符çè¿ç®ç¬¦æ¥å¹é
è¡ç¬¦
âmâï¼å°æºå符串ä½ä¸ºå¤è¡å¤ç
æ¨å¸æä» CUSTOMERS 表ä¸æåçµåé®ä»¶åï¼ä½æ¯åªæåä½äºç士ç客æ·ççµåé®ä»¶åã为æ¤ï¼æ¨éè¦è¿å CUST_EMAIL åï¼è¯¥åä½äº NLS_TERRITORY 为 Switzerland ç客æ·ç @ 符å·åé¢ï¼ä¸çå
容ãæ§è¡ä»¥ä¸èæ¬ï¼
@resubstr.sql
SELECT REGEXP_SUBSTR(cust_email, '[^@]+')
FROM oe.customers
WHERE nls_territory = 'SWITZERLAND' ;
请注æï¼å¨æ¬ç¤ºä¾ä¸ï¼ç»æè¿å第ä¸ä¸ªæ²¡æ @ 符å·çåå符串ã
REGEXP_REPLACE å½æ°ä½¿ç¨æ¿æ¢å符串ææ¿æ¢ç模å¼çæ¯ä¸ä¸ªå¹é
项æ¥è¿åç»å®å符串ãæ£æ¥è¯æ³ï¼
REGEXP_REPLACE(srcstr, pattern [,replacestr [, position
[, occurrence [, match_option]]]])
å¨è¯¥å½æ°ä¸ï¼
positionï¼æ¯æç´¢çèµ·å§ä½ç½®
occurrenceï¼æ¯è¦æç´¢çå¹é
项
replacestrï¼æ¯æ¿æ¢æ¨¡å¼çå符串
match_optionï¼æä¾äºæ´æ¹é»è®¤å¹é
çé项ãå®å¯ä»¥å
å«ä»¥ä¸ä¸ä¸ªæå¤ä¸ªå¼ï¼
âcâï¼ä½¿ç¨åºå大å°åçå¹é
ï¼é»è®¤å¼ï¼
âiâï¼ä½¿ç¨ä¸åºå大å°åçå¹é
ânâï¼å
许å¹é
ä»»ä½å符çè¿ç®ç¬¦
âmâï¼å°æºå符串ä½ä¸ºå¤è¡å¤ç
è¦è¿å PRODUCT_INFORMATION 表ç CATALOG_URL åä¸çä¿¡æ¯ï¼å¯ä»¥å¯¹è¯¥åæ§è¡å®å
¨æ«æãä½æ¯ï¼è¿å°å¯¼è´è¿åä¸ç¾ä¸ªè¡ï¼è¿æ¯å 为å®ååºäºå¤ä¸ªç®å½åä¸çç¹å® HTML 页é¢ä½ç½®ã
å¨è¯¥ç¤ºä¾ä¸ï¼æ¨åªæ³è¦æ¥æ¾å个ååæ¬èº«ï¼èä¸æ¯å®ä»¬æå
å«çä½çº§é¡µé¢ãè¦æ¥æ¾ä¸å
å«ææä¸å¿
è¦ä¿¡æ¯çååï¼ä½¿ç¨ REGEXP_REPLACE å½æ°ãæ§è¡ä»¥ä¸èæ¬ï¼
@rereplace.sql
SELECT UNIQUE REGEXP_REPLACE (catalog_url, 'http://([^/]+).*', '\1')
FROM oe.product_information ;
以ä¸æ¯æå
³å¦ä½å¤çå符串çä»ç»ï¼
http://
该表达å¼é¦å
æ¥æ¾è¯¥å符串æåï¼æ¤å¤æ²¡æç¹æ®çå
å符ã
([^/]+)
ç¶åï¼è¯¥è¡¨è¾¾å¼æç´¢ä¸ç³»åå符ï¼åªè¦å®ä»¬ä¸æ¯æ线 (/)ï¼ã
该表达å¼å¨ç¨è¯¥é¨åéå该å符串çå©é¨åæ¶ç»æã
å¹é
表达å¼æ¿æ¢ä¸ºååå¼ç¨ 1ï¼å®æ¯å¨ç¬¬ä¸ç»æ¬å·ä¸å¹é
çä»»ä½å
容ã
æ£å表达å¼å½æ°æ¯æå¤è¯è¨åè½ï¼å¹¶å¯ä»¥ç¨äºå¯¹åºå设置ææçåºç¨ç¨åºãè¦å°æ£å表达å¼ä¸ Oracle ç NLS è¯è¨åè½ç»å使ç¨ï¼æ§è¡ä»¥ä¸æ¥éª¤ï¼
æ§è¡ä»¥ä¸èæ¬æ¥æ¾è¡èçè¯ç产åæè¿°ï¼
@multiport.sql
SELECT regexp_substr(translated_name, '^[a-z]+')
FROM oe.product_descriptions
WHERE language_id = 'PT'
AND translated_name like 'G%' ;
请注æï¼æªæ¾ç¤ºè¯¥æ°æ®ã
^ ä½äºæ¹æ¬å·å¤é¨ï¼è¿æå³çæ¨å°æ索以任ä½å符ï¼ä» a å° zï¼å¼å¤´çä»»ä½å符串æåå符串ã
æ§è¡åä¸æ¥è¯¢ï¼ä½è¿æ¬¡ä½¿ç¨ä¸åºå大å°åçâiâãæ§è¡ä»¥ä¸èæ¬ï¼
@multiport2.sql
SELECT regexp_substr(translated_name, '^[a-z]+', 1, 1, 'i')
FROM oe.product_descriptions
WHERE language_id = 'PT'
AND translated_name like 'G%' ;
ç±äºå¨éå°éè±æå符æ¶ï¼è¿åçå符串被æªæï¼å æ¤ç»æä»ä¸å®æ´ãè¿æ¯å 为èå´ [a-z] 对 NLS_LANGUAGE æ¯è¾ææãèå´è¡¨è¾¾å¼å¯¹ NLS_SORT å¾ææï¼å¨æ¬ä¾ä¸ï¼å®æ´¾çèª NLS_LANGUAGEãæ¨éè¦ç¸åºå°è®¾ç½® NLS_LANGUAGE åæ°ï¼ä»¥è¿åå®æ´ç»æãæ§è¡ä»¥ä¸æ¥è¯¢ï¼
@multiport3.sql
ALTER SESSION SET NLS_LANGUAGE=PORTUGUESE;
SELECT regexp_substr(translated_name, '^[a-z]+', 1, 1, 'i')
FROM oe.product_descriptions
WHERE language_id = 'PT'
AND translated_name like 'G%' ;
æåä¸æ¥æ¯æ¥çç¨è±è¯åè¡èçè¯è¡¨ç¤ºçç»æ以确已ç»å®æäºç¿»è¯ãæ§è¡ä»¥ä¸èæ¬ï¼
@multiport4.sql
SELECT REGEXP_SUBSTR(i.product_name, '^[a-z]+', 1, 1, 'i') || ' = '
|| regexp_substr(d.translated_name, '^[a-z]+', 1, 1, 'i')
FROM oe.product_descriptions d, oe.product_information i
WHERE d.language_id = 'PT'
AND d.translated_name like 'G%'
AND i.product_id = d.product_id ;
ALTER SESSION SET NLS_LANGUAGE=AMERICAN;
å¨ CUSTOMERS 表ç CUST_EMAIL åä¸æ·»å ä¸ä¸ªæ ¡éªçº¦æå¯ä»¥ç¡®ä¿åªæ¥åå
å« @ 符å·çå符串ãæ§è¡ä»¥ä¸èæ¬ï¼
@chkemail.sql
INSERT INTO customers VALUES
(9999,'Christian','Patel',
cust_address_typ ('1003 Canyon Road','87501',
'Santa Fe','NM','US'),
phone_list_typ ('+1 505 243 4144'),'us','AMERICA','100',
'ChrisP+creme.com', 149, null, null, null, null, null) ;
ç±äºæªæ§è¡éªè¯ï¼å æ¤æ¥åäºæªå
å« @ 符å·ççµåé®ä»¶å°åã
è¿è¡èæ¬ä¹åï¼å¨å¼å§ä¸ä¸æ¥ä¹åï¼å¨ SQL> æ示符å¤è¿è¡ ROLLBACK è¯å¥ã
ROLLBACK;