首页 > 编程技术 > php

金额阿拉伯数字转换为中文的自定义函数

发布时间:2016-11-25 16:43

CREATE FUNCTION ChangeBigSmall
(@ChangeMoney money)
RETURNS VarChar(100) AS
BEGIN
Declare @String1 char(20)
Declare @String2 char(30)
Declare @String4 Varchar(100)
Declare @String3 Varchar(100) --从原A值中取出的值
Declare @i int --循环变量
Declare @J Int --A的值乘以100的字符串长度
Declare @Ch1 Varchar(100) --数字的汉语读法
Declare @Ch2 Varchar(100) --数字位的汉字读法
Declare @Zero Int --用来计算连续有几个零
Declare @ReturnValue VarChar(100)
Select @ReturnValue = ''
Select @String1 = '零壹贰叁肆伍陆柒捌玖'
Select @String2 = '万仟佰拾亿仟佰拾万仟佰拾元角分'
Select @String4 = Cast(@ChangeMoney*100 as int)
select @J=len(cast((@ChangeMoney*100) as int))
Select @String2=Right(@String2,@J)
Select @i = 1
while @i<= @j Begin
Select @String3 = Substring(@String4,@i,1)
if @String3<>'0' Begin
Select @Ch1 = Substring(@String1, Cast(@String3 as Int) 1, 1)
Select @Ch2 = Substring(@String2, @i, 1)
Select @Zero = 0 --表示本位不为零
end
else Begin
If (@Zero = 0) Or (@i = @J - 9) Or (@i = @J - 5) Or (@i = @J - 1)
Select @Ch1 = '零'
Else
Select @Ch1 = ''
Select @Zero = @Zero 1 --表示本位为0

--如果转换的数值需要扩大,那么需改动以下表达式 I 的值。
Select @Ch2 = ''
If @i = @J - 10 Begin
Select @Ch2 = '亿'
Select @Zero = 0
end

If @i = @J - 6 Begin
一。Mysql数据库的安装、建库和ODBC的安装设置
  Mysql和ODBC驱动可以在其主页(http://www.mysql.com/)下载,在右边的Latest Versions点击进去,下载相应的版本就行了。这里我们要下载Intel版本的Mysql(最新版本为3.23.40),ODBC驱动则是MyODBC 2.50.37 for NT/2000 (full setup),如果使用Win95/98,其驱动是不同的,请注意区分。
  然后就可以安装了,Mysql的安装是非常简单的,将它解压到一个目录(C:mysql),在Win2000中,Mysql可以作为Windows的一个服务运行,在命令行中运行"C:mysqlinmysqld-nt --install",然后在Win2000管理工具的服务中我们就可以发现有Mysql这个服务运行,不过我发现直接运行winmysqladmin.exe也是可以的,这时会要求输入一个密码,这是Mysql的连接密码,请记好,默认的连接是没有密码的(用户为root)。
  其后是建立数据库和表,由于要将Access和Excel中的数据都导过来,因此表格中要包括两者的全部字段,这里为简单起见,只选择了其中的一些字段来说明,运行cmd进入到命令行方式,切换到c:mysqlin目录,执行"mysqladmin create build",这个命令是创建数据库,build是数据库的名称,成功后,执行“mysql”,进入"Mysql>"的命令行方式下,执行以下的命令:
mysql>use build;
mysql>CREATE TABLE loupan (
id int(10) unsigned NOT NULL auto_increment,
loupantype varchar(6),
inputdate date,
at_whatsection varchar(6),
buildname varchar(50),
buildaddress varchar(50),
room tinyint(4),
hall tinyint(4),
areasize decimal(10,2),
exp_sellprice decimal(13,2),
ownername varchar(20),
contactway varchar(50),
memo varchar(255),
updatestatus char(1),
goodloupan char(1),
PRIMARY KEY (id)
);
  接着就会出现Query OK, 0 rows affected (0.04 sec)的成功提示,上文中use build表示切换当前的数据库为build,接着的语句是建表的命令,字段由上至下表示的是id号(自动加1,而且是该表的主键)、楼盘的类型、输入的日期、所在的区域、楼盘的名字、地址、房间的数目、厅的数目、面积、期望售价、业主的名字、联系方式、备注、更新状态、笋盘标志。
  接着就是安装Mysql的ODBC驱动了,MyODBC的安装也是傻瓜式的,运行setup,一步步确认。结束后,就可以在控制面板的ODBC数据源中进行设置了,点“系统DSN”,选择“添加”,在驱动程序的列表中选择“mysql”,就会弹出一个配置页面,在Windows DSN Name中输入数据源的名称,这里输入build(还可以输入其它的名称,不一定跟数据库的名字相同),在“MySQL host(name or IP)”中,输入“localhost”,表示Mysql运行在本机上,在Mysql Database Name中输入数据库的名字“build”,User中输入“root”,PassWord中输入刚才设置的密码,如果刚才没有设置的话,留空,按“OK”后,就会在系统数据源中多了一项“build”,这样Mysql的ODBC数据源就设置成功了。
如何缩小MSSQL的日志文件已经是一个经常性的问题了,不过这个问题在精华区已经有不少答案了,我这里也不再赘述。
现在我们讨论一下治本的问题,即如何使日志文件不再增大?
先介绍一个简单的方法。
就是把数据库的故障还原模型设置为“简单”(SQL2K)。这样它就会在Checkpoint的时候截断日志。
具体操作方法是:
1、在Enterprise Manager中右键点数据库,“属性|选项|故障还原”,选择“简单”就可以了,如果是SQL7,在“属性|选项”中有一个“trunc. log on chkpt. ”,选中就可以了。
2、如果不想用Enterprise Manager,在Query Analyser或者isql里面执行
EXEC sp_dboption 'your_dbname', 'trunc. log on chkpt.', 'TRUE'
就可以了
但是,要注意的是,这样做了之后,虽然日志不会增大,但是也意味着你一旦出现误操作,将不会有利用日志恢复的机会。(如何利用日志来恢复请参见精华区的FAQ)
所以,绝对不建议在生产数据库上截断日志,除非你有充足的理由和足够的把握,或者……
承担责任的不是你。
既然这种方法不安全,下面我将介绍一种安全的方法。
大家都知道,SQL Server 在完成事务日志备份时将自动截断事务日志中的不活动部分。这些不活动的部分包含已完成的事务,因此在恢复过程中不再使用。相反,事务日志的活动部分包含仍在运行但尚未完成的事务。SQL Server 将重新使用事务日志中这些截断的非活动空间,而不是任由事务日志继续增大并占用更多的空间。
所以,我们备份事务日志就可以使日志文件不再增大了。
但是呢,日志文件一直放着也不是个办法,删除呢,又会失去恢复的可能性。
我们可以结合完全备份来做。做过完全备份之前的事务日志就可以删除了。
比如说,一个备份计划,每天一次完全备份,保留7天内的,每15分钟一次事务日志备份,保留2天的。
用数据库维护计划向导可以很方便的建立备份计划,不过一定要记得设置保留多久的备份哦,否则硬盘空间被备份给占满了就坏事了。
Wrotten by Lucky@Dev-club
March 8, 2002
Create Procedure AtoC
@ChangeMoney Money
as
Set Nocount ON
Declare @String1 char(20)
Declare @String2 char(30)
Declare @String4 Varchar(100)
Declare @String3 Varchar(100) --从原A值中取出的值
Declare @i int --循环变量
Declare @J Int --A的值乘以100的字符串长度
Declare @Ch1 Varchar(100) --数字的汉语读法
Declare @Ch2 Varchar(100) --数字位的汉字读法
Declare @Zero Int --用来计算连续有几个零
Declare @ReturnValue VarChar(100)
Select @ReturnValue = ''
Select @String1 = '零壹贰叁肆伍陆柒捌玖'
Select @String2 = '万仟佰拾亿仟佰拾万仟佰拾元角分'
Select @String4 = Cast(@ChangeMoney*100 as int)
select @J=len(cast((@ChangeMoney*100) as int))
Select @String2=Right(@String2,@J)
Select @i = 1
while @i<= @j Begin
Select @String3 = Substring(@String4,@i,1)
if @String3<>'0' Begin
Select @Ch1 = Substring(@String1, Cast(@String3 as Int) 1, 1)
Select @Ch2 = Substring(@String2, @i, 1)
Select @Zero = 0 --表示本位不为零
end
else Begin
If (@Zero = 0) Or (@i = @J - 9) Or (@i = @J - 5) Or (@i = @J - 1)
Select @Ch1 = '零'
Else
Select @Ch1 = ''
Select @Zero = @Zero 1 --表示本位为0

--如果转换的数值需要扩大,那么需改动以下表达式 I 的值。
Select Ch2 = ''
If @i = @J - 10 Begin
Select @Ch2 = '亿'
Select @Zero = 0
end

If @i = @J - 6 Begin
懒得翻译了,大意:
在有合适的索引的时候,Top n和set rowcount n是一样快的。但是对于一个无序堆来说,top n更快。
原理自己看英文去。
Q. Is using the TOP N clause faster than using SET ROWCOUNT N to return a specific number of rows from a query?
A. With proper indexes, the TOP N clause and SET ROWCOUNT N statement are equally fast, but with unsorted input from a heap, TOP N is faster. With unsorted input, the TOP N operator uses a small internal sorted temporary table in which it replaces only the last row. If the input is nearly sorted, the TOP N engine must delete or insert the last row only a few times. Nearly sorted means you're dealing with a heap with ordered inserts for the initial population and without many updates, deletes, forwarding pointers, and so on afterward.
A nearly sorted heap is more efficient to sort than sorting a huge table. In a test that used TOP N to sort a table with the same number of rows but with unordered inserts, TOP N was not as efficient anymore. Usually, the I/O time is the same both with an index and without; however, without an index SQL Server must do a complete table scan. Processor time and elapsed time show the efficiency of the nearly sorted heap. The I/O time is the same because SQL Server must read all the rows either way.

标签:[!--infotagslink--]

您可能感兴趣的文章: