SQL中可供使用的函数是非常多的,这些函数的功能包括
1. 转化字符串大小写
2. 求一个数的对数
3. 计算两个日期之间的天数间隔等
熟练掌握这些函数将能帮助我们更快地完成业务功能。
创建数据表的SQL语句:
MySQL:
CREATE TABLE T_Person(
FIdNumber VARCHAR(20),
FName VARCHAR(20),
FBirthday DATETIME,
FRegDay DATETIME,
FWeight DECIMAL(10, 2)
)
Oracle:
CREATE TABLE T_Person(
FIdNumber VARCHAR(20),
FName VARCHAR(20),
FBirthday DATE,
FRegDay DATE,
FWeight NUMBERIC(10,2)
)
插入初始数据:
MySQL:
INSERT INTO T_Person(FIdNumber, FName, FBirthday, FRegday, FWeight) VALUES('123456789120', 'Tom', '1981-03-22', '1998-05-01', 56.67)
INSERT INTO T_Person(FIdNumber, FName, FBirthday, FRegday, FWeight) VALUES('123456789121', 'Jim', '1981-03-22', '1998-05-01', 36.17)
INSERT INTO T_Person(FIdNumber, FName, FBirthday, FRegday, FWeight) VALUES('123456789122', 'Tom', '1981-03-22', '1999-08-21', 40.33)
INSERT INTO T_Person(FIdNumber, FName, FBirthday, FRegday, FWeight) VALUES('123456789123', 'Tom', '1981-03-22', '2001-09-18', 46.23)
INSERT INTO T_Person(FIdNumber, FName, FBirthday, FRegday, FWeight) VALUES('123456789124', 'Tom', '1981-03-22', '2000-03-01', 48.68)
INSERT INTO T_Person(FIdNumber, FName, FBirthday, FRegday, FWeight) VALUES('123456789125', 'Tom', '1981-03-22', '1998-05-01', 66.67)
INSERT INTO T_Person(FIdNumber, FName, FBirthday, FRegday, FWeight) VALUES('123456789126', 'Tom', '1981-03-22', '1998-05-01', 51.28)
INSERT INTO T_Person(FIdNumber, FName, FBirthday, FRegday, FWeight) VALUES('123456789127', 'Tom', '1981-03-22', '1998-05-01', 60.32)
Oracle:
INSERT INTO T_Person(FIdNumber, FName, FBirthday, FRegday, FWeight) VALUES('123456789127', 'Tom', TODATE('1981-03-22', 'YYYY-MM-DD HH24:MI:SS'), TODATE('1998-05-01','YYYY-MM-DD HH24:MI:SS'), 60.32)
INSERT INTO T_Person(FIdNumber, FName, FBirthday, FRegday, FWeight) VALUES('123456789127', 'Tom', TODATE('1981-03-22', 'YYYY-MM-DD HH24:MI:SS'), TODATE('1998-05-01','YYYY-MM-DD HH24:MI:SS'), 60.32)
INSERT INTO T_Person(FIdNumber, FName, FBirthday, FRegday, FWeight) VALUES('123456789127', 'Tom', TODATE('1981-03-22', 'YYYY-MM-DD HH24:MI:SS'), TODATE('1998-05-01','YYYY-MM-DD HH24:MI:SS'), 60.32)
INSERT INTO T_Person(FIdNumber, FName, FBirthday, FRegday, FWeight) VALUES('123456789127', 'Tom', TODATE('1981-03-22', 'YYYY-MM-DD HH24:MI:SS'), TODATE('1998-05-01','YYYY-MM-DD HH24:MI:SS'), 60.32)
INSERT INTO T_Person(FIdNumber, FName, FBirthday, FRegday, FWeight) VALUES('123456789127', 'Tom', TODATE('1981-03-22', 'YYYY-MM-DD HH24:MI:SS'), TODATE('1998-05-01','YYYY-MM-DD HH24:MI:SS'), 60.32)
INSERT INTO T_Person(FIdNumber, FName, FBirthday, FRegday, FWeight) VALUES('123456789127', 'Tom', TODATE('1981-03-22', 'YYYY-MM-DD HH24:MI:SS'), TODATE('1998-05-01','YYYY-MM-DD HH24:MI:SS'), 60.32)
INSERT INTO T_Person(FIdNumber, FName, FBirthday, FRegday, FWeight) VALUES('123456789127', 'Tom', TODATE('1981-03-22', 'YYYY-MM-DD HH24:MI:SS'), TODATE('1998-05-01','YYYY-MM-DD HH24:MI:SS'), 60.32)