文档详情

实验3 Transat-SQL常用函数.doc

发布:2018-04-17约1.19千字共3页下载文档
文本预览下载声明
实验3 Transat-SQL常用函数 实验任务与要求 声明一个类型为日期时间型的变量,要求一:将今天的日期赋值给该变量,并显示其结果。 要求二:将今天的日期接照月、日、年的格式赋值给该变量,并显示其结果。 Declare @dt datetime; Declare @yn int, @mn int, @dn int; Set @dt=getdate(); Set @yn=year(@dt); Set @dn=day(@dt); Set @mn=Month(@dt); Print ltrim(str(@mn))+’月’; Print ltrim(str(@dn))+’日’; Print ltrim(str(@yn))+’年’; 写结果:select round(76.512565,3), round(23.3234357,3), round(34.213456,-2) 写结果:select str(123.45,6,1),str(123.45,2,2),str(floor(123.45),8,3) ,str(123.45,4,0) 写结果:select lower(‘abc’) +space(5) + rtrim(ltrim(‘你好!’)) 写函数表达式和结果:求出‘数据库’在‘大型数据库技术’中的位置 写函数表达式和结果:计算字符串’SQL Server数据库管理系统’的长度 写函数表达式和结果:查找字符串’wo’在‘MY wonderful‘中的开始位置 写结果:计算Hell Transat-SQL字符串的所有ASCII值,并打印每个字母和对应的ASCII值。 declare @str nvarchar(30) declare @x char declare @i int set @str=Hell Transat-SQL set @i=1 while @i=len(@str) begin set @x=substring(@str,@i,1) set @i=@i+1 select @x char, ASCII (@x) ASCII end 使用 SUBSTRING、UNICODE、CONVERT 和 NCHAR 函数打印字符串My城市学院的字符数、Unicode 字符以及每个字符的 UNICODE 值。 declare @str nvarchar(30) declare @x nvarchar(10) declare @i int set @str=My城市学院 set @i=1 while @i=len(@str) begin set @x=substring(@str,@i,1) set @i=@i+1 select @x char,unicode(@x) unicode end
显示全部
相似文档