Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

SQL SERVER ·ÖÒ³´æ´¢¹ý³Ì

´æ´¢¹ý³Ì´úÂ룺
 --drop procedure p_page
--go
create procedure p_page
(
@Tables varchar(1000), --±íÃûÈçtesttable
@PrimaryKey varchar(100),--±íµÄÖ÷¼ü,±ØÐëΨһÐÔ
@Sort varchar(200) = NULL,--ÅÅÐò×Ö¶ÎÈçf_Name asc»òf_name desc(×¢ÒâÖ»ÄÜÓÐÒ»¸öÅÅÐò×Ö¶Î)
@CurrentPage int = 1,--µ±Ç°Ò³
@PageSize int = 10,---ÿҳ´óС
@Fields varchar(1000) = '*',--ÏÔʾµÄ×Ö¶ÎÁбí
@Filter varchar(1000) = NULL,--Ìõ¼þÓï¾ä,²»¼Ówhere,Èç f_id>3
@Group varchar(1000) = NULL,--·Ö×é×Ö¶Î
@TotalPage int output --·µ»Ø×ÜÒ³Êý
)
WITH ENCRYPTION ---¼ÓÃÜ´æ´¢
AS
SET NOCOUNT ON
Declare @intResult Int
Begin Tran
DECLARE @sql nvarchar(4000)

if @Filter is null or @Filter=''
set @Sql = 'select @intResult = count(' + @PrimaryKey + ') from ' + @Tables
else
set @Sql = 'select @intResult = count(' + @PrimaryKey + ') from ' + @Tables + ' where + ' + @Filter
EXEC sp_executesql @sql,N'@intResult int OUTPUT',@intResult OUTPUT--¼ÆËã×ܼǼÊý
select @TotalPage=CEILING((@intResult+0.0)/@PageSize)--¼ÆËã×ÜÒ³Êý


IF @Sort IS NULL or @Sort = ''
SET @Sort = @PrimaryKey
DECLARE @SortTable varchar(100)
DECLARE @SortName varchar(100)
DECLARE @strSortColumn varchar(200)
DECLARE @operator char(2)
DECLARE @type varchar(100)
DECLARE @prec int

IF CHARINDEX('DESC',@Sort)>0
BEGIN
SET @strSortColumn = REPLACE(@Sort, 'DESC', '')
SET @operator = '<='
END
ELSE
IF CHARINDEX('ASC', @Sort) > 0
BEGIN
SET @strSortColumn = REPLACE(@Sort, 'ASC', '')
SET @operator = '>='
END

ELSE
BEGIN
SET @strSortColumn = @SORT
SET @operator = '>='
END

IF CHARINDEX('.', @str


Ïà¹ØÎĵµ£º

Oracle¿ª·¢Ö®SQLÓï¾ä°¸Àý—·ÖÎöº¯ÊýµÄʹÓÃ

´´½¨¹ÍÔ±±í£º
create table emp(deptno number(10),ename varchar2(100),sal number(10,2))£»
²åÈëÊý¾Ý
begin
insert into emp values('10','KING',5000);
insert into emp values('10','CLARK',2450);
insert into emp values('10','MILLER',1300);
insert into emp values('20','SCOTT',3000);
insert into emp v ......

Oracle SQL Óï¾ä¶Ôʱ¼ä²Ù×÷µÄ×ܽá

ÔÚSQLÓï¾äÖУ¬³£³£Óûá¶Ôʱ¼ä£¨»òÈÕÆÚ£©½øÐÐһЩ´¦Àí£¬ÏÂÃæÊDZȽÏͨÓõÄһЩÓï¾ä£º
ÑÓ³Ù£º
sysdate+(5/24/60/60)          ÔÚϵͳʱ¼ä»ù´¡ÉÏÑÓ³Ù5Ãë
sysdate+5/24/60               ÔÚϵͳʱ¼ä»ù´ ......

ÓÃSQL½¨Á¢Ë÷Òý

¡¡¡¡¼ÙÉèÄãÏëÕÒÊéÖеÄijһ¸ö¾ä×Ó¡£Äã¿ÉÒÔÒ»Ò³Ò»Ò³µØÖðÒ³ËÑË÷£¬µ«Õâ»á»¨ºÜ¶àʱ¼ä¡£¶øͨ¹ýʹÓÃË÷Òý£¬Äã¿ÉÒԺܿìµØÕÒµ½ÄãÒªËÑË÷µÄÖ÷Ìâ¡£
¡¡¡¡±íµÄË÷ÒýÓ븽ÔÚÒ»±¾ÊéºóÃæµÄË÷Òý·Ç³£ÏàËÆ¡£Ëü¿ÉÒÔ¼«´óµØÌá¸ß²éѯµÄËٶȡ£¶ÔÒ»¸ö½Ï´óµÄ±íÀ´Ëµ£¬Í¨¹ý¼ÓË÷Òý£¬Ò»¸öͨ³£Òª»¨·Ñ¼¸¸öСʱÀ´Íê³ÉµÄ²éѯֻҪ¼¸·ÖÖӾͿÉÒÔÍê³É¡£Òò´ËûÓÐÀíÓÉ¶Ô ......

sqlÓï¾ä»ù´¡

--sql structured query language
--DML--Data Manipulation Language--Êý¾Ý²Ù×÷ÓïÑÔ
query information (SELECT),
add new rows (INSERT),
modify existing rows (UPDATE),
delete existing rows (DELETE),
perform a conditional update or insert operation (MERGE),
see an execution plan of SQL (EXPLA ......

PL/SQLÖÐGOTOÓï¾äºÍ±êÇ©

ÔÚPL/SQLÖÐÒ²ÌṩGOTOÓï¾ä,ÆäÓï·¨ÊÇ
GOTO label;
ÕâÀïlabelÊÇÔÚPL/SQL¿éÖж¨ÒåµÄ±êÇ©.±êÇ©ÊÇÓÃË«¼ýÍ·À¨ºÅÀ¨ÆðÀ´µÄ.µ±Ö´ÐÐGOTOÓï¾äµÄʱºò,¿ØÖÆ»áÁ¢¼´×ªµ½ÓɱêÇ©±êʶµÄÓï¾ä.
1.¶ÔÓÚGOTOµÄÏÞÖÆ
a.¶ÔÓÚ¿é,Ñ­»·»òÕßIFÓï¾ä¶øÑÔ,ÏëÒª´ÓÍâ²ãÌøµ½ÄÚ²ãÊÇ·Ç·¨µÄ.
b.ʹÓÃGOTO×Ó¾ä´ÓÒ»¸öIF×Ó¾äÌøµ½ÁíÒ»¸ö×Ó¾äÖÐÒ²ÊÇ·Ç·¨µÄ.
begin
......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ