首页 > 编程技术 > php

金额阿拉伯数字转换为中文的存储过程

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

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
如何缩小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
懒得翻译了,大意:
在有合适的索引的时候,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.

Q. 如何得到随机排序结果?
A. 要得到随机排序的列,或者返回x条随机选择的列,你可以使用随机数。但是RAND函数在一个查询中只能返回一个结果。你可以在NOWID函数返回的列上做ORDER BY。请看示例:
SELECT *
FROM Northwind..Orders
ORDER BY NEWID()
SELECT TOP 10 *
FROM Northwind..Orders
ORDER BY NEWID()
这段话翻译得真是费劲,干脆不管原文,直接意译了。
不过提醒大家注意,这种方法是要对整个表扫描,然后产生一个计算列再排序的,最好不要对大的表作这样的操作,否则会很慢的。
Q. How can I randomly sort query results?
A. To randomly order rows, or to return x number of randomly chosen rows, you can use the RAND function inside the SELECT statement. But the RAND function is resolved only once for the entire query, so every row will get same value. You can use an ORDER BY clause to sort the rows by the result from the NEWID function, as the following code shows:
SELECT *
FROM Northwind..Orders
ORDER BY NEWID()
SELECT TOP 10 *
FROM Northwind..Orders
ORDER BY NEWID()
—SQL Server MVPs

MySQL修改密码方法总结

首先要声明一点,大部分情况下,修改MySQL是需要有mysql里的root权限的,所以一般用户无法更改密码,除非请求管理员。
方法一
使用phpmyadmin,这是最简单的了,修改mysql库的user表,
不过别忘了使用PASSWORD函数。
方法二
使用mysqladmin,这是前面声明的一个特例。
mysqladmin -u root -p password mypasswd
输入这个命令后,需要输入root的原密码,然后root的密码将改为mypasswd。
把命令里的root改为你的用户名,你就可以改你自己的密码了。
当然如果你的mysqladmin连接不上mysql server,或者你没有办法执行mysqladmin,
那么这种方法就是无效的。
而且mysqladmin无法把密码清空。
下面的方法都在mysql提示符下使用,且必须有mysql的root权限:
方法三
mysql> INSERT INTO mysql.user (Host,User,Password)
VALUES(%,jeffrey,PASSWORD(iscuit));
mysql> FLUSH PRIVILEGES
确切地说这是在增加一个用户,用户名为jeffrey,密码为biscuit。
在《mysql中文参考手册》里有这个例子,所以我也就写出来了。
注意要使用PASSWORD函数,然后还要使用FLUSH PRIVILEGES。
方法四
和方法三一样,只是使用了REPLACE语句
mysql> REPLACE INTO mysql.user (Host,User,Password)
VALUES(%,jeffrey,PASSWORD(iscuit));
mysql> FLUSH PRIVILEGES
方法五
使用SET PASSWORD语句,
mysql> SET PASSWORD FOR jeffrey@"%" = PASSWORD(iscuit);
你也必须使用PASSWORD()函数,
但是不需要使用FLUSH PRIVILEGES。
方法六
使用GRANT ... IDENTIFIED BY语句
mysql> GRANT USAGE ON *.* TO jeffrey@"%" IDENTIFIED BY iscuit;
这里PASSWORD()函数是不必要的,也不需要使用FLUSH PRIVILEGES。
注意: PASSWORD() [不是]以在Unix口令加密的同样方法施行口令加密。

标签:[!--infotagslink--]

您可能感兴趣的文章: