select convert(numeric(10,4),iinvnowcost) from ...
decimal 和 numeric (来源sql 联机丛书)
带定点精度和小数位数的 numeric 数据类型。
decimal[(p[, s])] 和 numeric[(p[, s])]
定点精度和小数位数。使用最大精度时,有效值从 - 10^38 +1 到 10^38 - 1。decimal 的 SQL-92 同义词是 dec 和 dec(p, s)。
p(精度)
指定小数点左边和右边可以存储的十进制数字的最大个数。精度必须是从 1 到最大精度之间的值。最大精度为 38。
s(小数位数)
指定小数点右边可以存储的十进制数字的最大个数。小数位数必须是从 0 到 p 之间的值。默认小数位数是 0,因而 0 <= s <= p。最大存储大小基于精度而变化。
精度存储字节数
1 - 9
5
10-19
9
20-28
13
29-38
17
......
--ksh下的一个WHILE 循环的例子
integer i=1
while ((i<67))
do
pirnt $i
i=i+1
done
--ksh 下一个FOR循环的例子
for i in `cat listdate.txt`
do
echo "执行 $i "
done
--- date.pl 用于生成一个时间段文件
#!/usr/local/bin/perl
use DBI;
if($#ARGV<1)
{
die "USAGE:date.pl <startdate> <enddate> \n";
return(0);
}
$rundate1=$ARGV[0];
$rundate2=$ARGV[1];
$dbh=DBI->connect('dbi:Oracle:host=192.xx.xx.2;sid=ora7','report/system','')||
die('cann\'t connect to database');
$date=$dbh->prepare("select cal_date from calendar where cal_date between to_date(?,'yyyymmdd') and to_date(?,'yyyymmdd')");
$date->bind_param( 1, $rundate1);
$date->bind_param( 2, $rundate2);
$date->execute;
while (@row = $date->fetchrow_array)
{
printf("$row[0]\n");
}
$dbh->disconnect;
---实例 批处理执行一段时间 每天 要执行的程序
date.pl 20100101 20100307 > listdate.txt
for i in `cat listdate.txt`
do
ech ......
Student(S#,Sname,Sage,Ssex) 学生表
Course(C#,Cname,T#) 课程表
SC(S#,C#,score) 成绩表
Teacher(T#,Tname) 教师表
问题:
1、查询“001”课程比“002”课程成绩高的所有学生的学号;
select a.S# from (select s#,score from SC where C#='001') a,(select s#,score
from SC where C#='002') b
where a.score>b.score and a.s#=b.s#;
2、查询平均成绩大于60分的同学的学号和平均成绩;
select S#,avg(score)
from sc
group by S# having avg(score) >60;
3、查询所有同学的学号、姓名、选课数、总成绩;
select Student.S#,Student.Sname,count(SC.C#),sum(score)
from Student left Outer join SC on Student.S#=SC.S#
group by Student.S#,Sname
4、查询姓“李”的老师的个数;
select count(distinct(Tname))
from Teacher
where Tname like '李%';
5、查询没学过“叶平”老师课的同学的学号、姓名;
select Student.S#,Stu ......
问题描述:
本题用到下面三个关系表:
CARD 借书卡。 CNO 卡号,NAME 姓名,CLASS 班级
BOOKS 图书。 BNO 书号,BNAME 书名,AUTHOR 作者,PRICE 单价,QUANTITY 库存册数
BORROW 借书记录。 CNO 借书卡号,BNO 书号,RDATE 还书日期
备注:限定每人每种书只能借一本;库存册数随借书、还书而改变。
要求实现如下15个处理:
1. 写出建立BORROW表的SQL语句,要求定义主码完整性约束和引用完整性约束。
2. 找出借书超过5本的读者,输出借书卡号及所借图书册数。
3. 查询借阅了"水浒"一书的读者,输出姓名及班级。
4. 查询过期未还图书,输出借阅者(卡号)、书号及还书日期。
5. 查询书名包括"网络"关键词的图书,输出书号、书名、作者。
6. 查询现有图书中价格最高的图书,输出书名及作者。
7. 查询当前借了"计算方法"但没有借"计算方法习题集"的读者,输出其借书卡号,并按卡号降序排序输出。
8. 将"C01"班同学所借图书的还期都延长一周。
9. 从BOOKS表中删除当前无人借阅的图书记 ......
1 如何锁一个表的某一行
A 连接中执行
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ
begin tran
select * from tablename with (rowlock) where id=3
waitfor delay '00:00:05'
commit tran
B连接中如果执行
update tablename set colname='10' where id=3 --则要等待5秒
update tablename set colname='10' where id<>3 --可立即执行
2 锁定数据库的一个表
SELECT * from table WITH (HOLDLOCK) & ......
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="Default" value="Default" />
</appSettings>
<connectionStrings>
<add name="Default" connectionString="Data Source=192.168.1.197;User ID=diamond;Password=88888888;Initial Catalog=EmailAnalyse" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
namespace OfficeOutlook
{
/// <summary>
///DataBase 的摘要说明
/// </summary>
public class DataBase
{
protected SqlConnection BaseSqlConnection = new SqlConnection();//连接对象
&n ......
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="Default" value="Default" />
</appSettings>
<connectionStrings>
<add name="Default" connectionString="Data Source=192.168.1.197;User ID=diamond;Password=88888888;Initial Catalog=EmailAnalyse" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
namespace OfficeOutlook
{
/// <summary>
///DataBase 的摘要说明
/// </summary>
public class DataBase
{
protected SqlConnection BaseSqlConnection = new SqlConnection();//连接对象
&n ......
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="Default" value="Default" />
</appSettings>
<connectionStrings>
<add name="Default" connectionString="Data Source=192.168.1.197;User ID=diamond;Password=88888888;Initial Catalog=EmailAnalyse" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Text;
namespace OfficeOutlook
{
/// <summary>
///DataBase 的摘要说明
/// </summary>
public class DataBase
{
protected SqlConnection BaseSqlConnection = new SqlConnection();//连接对象
&n ......