SQL Server中的通配符
通配符_
"_"号表示任意单个字符,该符号只能匹配一个字符."_"可以放在查询条件的任意位置,且只能代表一个字符.一个汉字只使用一个"_"表示.
例子:
if PATINDEX('%[吖-做]%','需要判断的字符')>0 -- 判断是否有字符
print '有汉字'
else
print '无汉字'
通配符%
"%"符号是字符匹配符,能匹配0个或更多字符的任意长度的字符串.在SQL语句中可以在查询条件的任意位置放置一个%来代表一个任意长度的字符串.在查询条件时也可以放置两个%进行查询,但在查询条件中最好不要连续出现两个%
通配符[]
在模式查询中可以利用"[]"来实现查询一定范围的数据.[]用于指定一定范围内的任何单个字符,包括两端数据
通配符[^]
[^]用来查询不属于指定范围 ([a-f]) 或集合 ([abcdef]) 的任何单个字符。
如:select * from alluser
where username like 'M[^abc]%'
表示从表alluser中查询用户名以M开头,且第二个字符不是a,b,c信息.
ESCAPE子句的模式匹配
可搜索包含一个或多个特殊通配符的字符串。例如,customers 数据库中的 discounts 表可能存储含百分号 (%) 的折扣值。若要搜索作为字符而不是通配符的百分号,必须提供 ESCAPE 关键字和转义符。例如,一个样本数据库包含名为 comment 的列,该列含文本 30%。若要搜索在 comment 列中的任何位置包含字符串 30% 的任何行,请指定由 Where comment LIKE '%30!%%' ESCAPE '!' 组成的 Where 子句。如果不指定 ESCAPE 和转义符,SQL Server 将返回所有含字符串 30 的行。
下例说明如何在 pubs 数据库 titles 表的 notes 列中搜索字符串"50% off when 100 or more copies are purchased":
Select notes from titles
Where notes LIKE '50%% off when 100 or more copies are purchased'
ESCAPE '%'
escape的主要用途
1.使用 ESCAPE 关键字定义转义符。 在模式中,当转义符置于通配符之前时,该通配符就解释为普通字符。例如,要搜索在任意位置包含字符串 5% 的字符串,请使用: Where ColumnA LIKE '%5/%%' ESCAPE '/'
2.ESCAPE 'escape_character' 允许在字符串中搜索通配符而不是将其作为通配符使用。 escape_character 是放在通配符前表示此特殊用途的字符。
Select * from finances Where description LIKE 'gs_' ESCAPE 'S'
意思就是: 比如,我们要搜索一个字符串 "g_" ,如果直接 like "g_",那么 "_"的作用就是通配符,而不是字符,结果,我们会查到比如 "ga","gb","gc",
相关文档:
--1加内存表
EXEC sp_tableoption '表名','pintable', 'true'
--2卸载内存表
EXEC sp_tableoption '表名','pintable', 'false'
--2查询是否有内存表驻留
SELECT * from INFORMATION_SCHEMA.Tables
WHERE TABLE_TYPE = 'BASE TABLE'
AND OBJECTPROP ......
Oracle SQL(partI)
Data manipulation language(DML): select, insert, update, delete, merge.
Data definition language(DDL): create, alter, drop, rename, truncate, comment
Data control language(DCL): grant, revoke
Transaction control: commit, rollback, savepoint
Arithmetic Expressions:
+, -, *, / ......
Confirming granted privileges
Data Dictionary View Description
ROLE_SYS_PRIVS System privileges granted to roles
ROLE_TAB_PRIVS & ......
Merge statement
function benefits: 1) provides the ability to conditionally update, insert or delete data into a database table. 2) performs an update if the row exists, and an insert if it is a new row. --> 1) avoids seperate updates, 2) increase performance and ease of use. 3) is useful in dat ......
Group functions
SELECT [column,] group_function(column) ... from table [WHERE condition] [GROUP BY group_by_expression] [ORDER BY column];
e.g.:
SELECT department_id, job_id, SUM(salary), COUNT(employee_id) from employees GROUP BY department_id, job_id ;
SELECT [column,] group_function(column).. ......