工作中积攒的几个自定义SQL函数
工作中积攒的几个自定义SQL函数:
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: 字符串切割函数
-- =============================================
ALTER function [dbo].[Split]
(
@Text nvarchar(4000),
@Sign nvarchar(4000)
)
returns @tempTable table(id int identity(1,1) primary key,[value] nvarchar(4000))
AS
begin
declare @StartIndex int --开始查找的位置
declare @FindIndex int --找到的位置
declare @Content varchar(4000) --找到的值
set @StartIndex = 1
set @FindIndex=0
--遍历每个字符
while(@StartIndex <= len(@Text))
begin
SELECT @FindIndex = charindex(@Sign,@Text,@StartIndex)
--判断有没找到 没找到返回0
IF(@FindIndex =0 OR @FindIndex IS NULL)
begin
set @FindIndex = len(@Text)+1
end
set @Content = ltrim(rtrim(substring(@Text,@StartIndex,@FindIndex-@StartIndex)))
set @StartIndex = @FindIndex+1
insert into @tempTable ([value]) values (@Content)
end
return
end
-- ==========
相关文档:
import java.sql.*;
/*
* JAVA连接ACCESS,SQL Server,MySQL,Oracle数据库
*
* */
public class JDBC {
public static void main(String[] args)throws Exception {
Connection conn=null;
//====连接ACCESS数据库 ......
http://www.umgr.com/blog/PostView.aspx?bpId=36294
1. 执行sql语句
int sqlite3_exec(sqlite3*, const char *sql, sqlite3_callbacksql 语法
, void *, char **errmsg );
这就是执行一条 sql 语句的函数。
第1个参数不再说了,是前面open函数得到的指针。说了是关键数据结构。
第2个参数const char ......
在脑子里老是记得当初写SQL的时候,总是有人提醒对于主键的条件要写在前面,至于为什么现在总是记不清楚了。但是SQL中where 条件的执行顺序跟主键以及索引有很大的关系。
把上片中的表a 加上主键:
alter table
add constraint pk_a_id primary key (id)
然后在运行上篇中出错的例句:
select * from a where id in (1 ......
以下是我在学习中的点滴记录,如果有错误的地方或者缺少部分,请各位大侠不吝指教。小弟在此谢过了
1.select count(*) 和select count(id) 之间的区别。
select count(*) 统计所有记录个数,包括空记录。
Select count(Id) 统计所有记录个数,不包括null记录。
2.delete & truncate 的区别
trunc ......