SQLite包含了如下时间/日期函数:
datetime().......................产生日期和时间
date()...........................产生日期
time()...........................产生时间
strftime().......................对以上三个函数产生的日期和时间进行格式化
datetime()的用法是:datetime(日期/时间,修正符,修正符...)
date()和time()的语法与datetime()相同。
在时间/日期函数里可以使用如下格式的字符串作为参数:
YYYY-MM-DD
YYYY-MM-DD HH:MM
YYYY-MM-DD HH:MM:SS
YYYY-MM-DD HH:MM:SS.SSS
HH:MM
HH:MM:SS
HH:MM:SS.SSS
now
其中now是产生现在的时间。
举例(写这个笔记的时间是2006年10月17日晚8点到10点,测试环境:SQLite 2.8.17,WinXP,北京时间):
例1.
select datetime('now');
结果:2006-10-17 12:55:54
例2.
select datetime('2006-10-17');
结果:2006-10-17 12:00:00
例3.
select datetime('2006-10-17 00:20:00','+1 hour','-12 minute');
结果:2006-10-17 01:08:00
例4.
select date('2006-10-17','+1 day','+1 year');
结果:2007-10-18
例5.
select datetime('now','start of year');
结果:2006-01-01 00:00:00
例6 ......
在SQL Server中,创建表格的时候,对于时间列有时候我们可以根据需要指定默认值为当前时间(也就是说记录生成的时候有默认的时间戳)。例如:
create table log(
content varchar(256),
logtime datetime default getdate()
)
然而在Sqlite中如何实现呢?查文档得知Sqlite中并没有getdate()函数,但其系统内置函数有datetime(),因此能不能按照下面的写法实现默认时间戳呢:
create table log(
content varchar(256),
logtime datetime default datetime('now')
)
答案是否定的,会提示语法错误。那么应该如何声明呢?如下所示:
create table log(
content varchar(256),
logtime TIMESTAMP default CURRENT_TIMESTAMP
)
这个可以达到效果,但是默认的时间是以格林尼治标准时间为基准的,因此在中国使用的话会正好早8个小时。为了解决这个问题,我们可以这样声明:
create table log(
co ......
--spid:死锁的进程,tableName :死锁的表
select request_session_id spid,OBJECT_NAME(resource_associated_entity_id)tableName from sys.dm_tran_locks
where resource_type='OBJECT'
--spid:要结束的进程id
kill spid ......
数学函数
在oracle 中distinct关键字可以显示相同记录只显示一条
1.绝对值
S:select abs(-1) value
O:select abs(-1) value from dual
2.取整(大)
S:select ceiling(-1.001) value
O:select ceil(-1.001) value from dual
3.取整(小)
S:select floor(-1.001) value
O:select floor(-1.001) value from dual
4.取整(截取)
S:select cast(-1.002 as int) value
O:select trunc(-1.002) value from dual
5.四舍五入
S:select round(1.23456,4) value 1.23460
O:select round(1.23456,4) value from dual 1.2346
6.e为底的幂
S:select Exp(1) value 2.7182818284590451
O:select Exp(1) value from dual 2.71828182
7.取e为底的对数
S:select log(2.7182818284590451) value 1
O:select ln(2.7182818284590451) value from dual; 1
8.取10为底对数
S:select log10(10) value 1
O:select log(10,10) value from dual; 1
9.取平方
S:select SQUARE(4) value 16
O:select power(4,2) value from dua ......
数学函数
在oracle 中distinct关键字可以显示相同记录只显示一条
1.绝对值
S:select abs(-1) value
O:select abs(-1) value from dual
2.取整(大)
S:select ceiling(-1.001) value
O:select ceil(-1.001) value from dual
3.取整(小)
S:select floor(-1.001) value
O:select floor(-1.001) value from dual
4.取整(截取)
S:select cast(-1.002 as int) value
O:select trunc(-1.002) value from dual
5.四舍五入
S:select round(1.23456,4) value 1.23460
O:select round(1.23456,4) value from dual 1.2346
6.e为底的幂
S:select Exp(1) value 2.7182818284590451
O:select Exp(1) value from dual 2.71828182
7.取e为底的对数
S:select log(2.7182818284590451) value 1
O:select ln(2.7182818284590451) value from dual; 1
8.取10为底对数
S:select log10(10) value 1
O:select log(10,10) value from dual; 1
9.取平方
S:select SQUARE(4) value 16
O:select power(4,2) value from dua ......
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm2 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
//返回值问题
function Add(x, y: Integer): Integer;
function Add_Res(x, y: Integer): Integer;
//关于函数的参数问题
//参数可以分为: 默认参数(传值)、var(传址)、out(输出)、const(常数)四类
function MyFun1(Value: Integer): Integer;
function MyFun2(var Value: Integer): Integer;
function MyFun3(out Value: Integer): Integer;
function MyFun4(const Value: Integer): Integer;
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
{ TForm2 }
function TForm2.Add(x, y: Integer): Integer;
begin
Add := x + y; //使用函数名作为返回存储变量 (少用)
// Add := Add + 1; // 函数名 ......
类的事件
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TMyEvent = procedure of object; //不带参数的过程
TMyEventExt = procedure(AName: string) of object; //带参数的过程
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TMyBase = class
private
FName : string;
FAge : Integer;
FOnEvent: TMyEvent; //定义 TMyEvent 类型事件
FOnEventExt: TMyEventExt;
procedure SetAge(const AValue: Integer);
public
//创建类时进行相应的一些初始化工作
constructor Create;
procedure SetEvent1;
procedure SetEvent2;
procedure SetEventExt1(ATmp: string);
//Name属性 不可更改
property Name: string read FName write FName;
//Age属性 可以更改
......