易截截图软件、单文件、免安装、纯绿色、仅160KB
热门标签: c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 最新文章 : sql

SQL 2005 存储过程分页

create PROCEDURE [dbo].[P_PageTest]
    @SQL Nvarchar(max),  --SQL语句不包括排序
    @CurPage int,    --当前页
    @PageRows int,    --页面尺寸
 @Order Nvarchar(20),  --排序字段
 @OrderType Nvarchar(10), --排序类型倒序desc或正序asc
    @TotalRecorder int output
AS
BEGIN
    SET NOCOUNT ON;
    declare @ExceSQL nvarchar(4000)
    --设置开始行号
    declare  @start_row_num AS int
 declare  @end_row_num AS int
 if(@CurPage=1)
  begin
  SET @start_row_num = (@CurPage - 1) * @PageRows
  SET @end_row_num = @start_row_num+@PageRows
  end
 else
  begin
  SET @start_row_num = ((@CurPage - 1) * @PageRows)+1
  SET @end_row_num = (@start_row_num+@PageRows)-1
  end
    --设置表示
    declare @RowNumber nvarchar( ......

PL/SQL 学习笔记1

PL/SQL 不具备输入输出的能力
但是可以依靠环境来执行数值的输入输出给PL/SQL 块
SQLPLUS 环境用substitution variables 和 host(bind) variable 来传入数值给PL/SQL块
substitution variable: such as a preceding ampersand  &a
host(bind) variable : such as a  preceding colon :x
替代变量可以不用声明,但是会在执行的时候有一个交互式提示
绑定变量需要声明并且赋值的时候用exec语句
SQL> var df df
Usage: VAR[IABLE] [ <variable> [ NUMBER | CHAR | CHAR (n [CHAR|BYTE]) |
VARCHAR2 (n [CHAR|BYTE]) | NCHAR | NCHAR (n) |
NVARCHAR2 (n) | CLOB | NCLOB | REFCURSOR |
BINARY_FLOAT | BINARY_DOUBLE ] ]
SQL> var a number
SQL> exec :a :=123
PL/SQL procedure successfully completed.
SQL> edit
Wrote file afiedt.buf
1 declare
2 begin
3 dbms_output.put_line('result='||'&a'||:a);
4* end;
SQL> /
Enter value for a: i love u
old 3: dbms_output.put_line('result='||'&a'||:a);
new ......

PL/SQL 学习笔记2

变量声明
Syntax:
identifier [CONSTANT] datatype [NOT NULL]   [:= | DEFAULT expr];
SQL> declare
2 a date;
3 b number(20) not null :=100;
4 c varchar2(10);
5 d constant number(20) default 1000;
6 begin
7 null;
8 end;
9 /
PL/SQL procedure successfully completed.

SQL> var v_bind number
SQL> exec :v_bind := 2984;
PL/SQL procedure successfully completed.
SQL> r
1 declare
2 v_a number(20);
3 v_b constant number := 1000;
4 v_c constant number default 2000;
5 v_d varchar2(20) not null default 'asf';
6 begin
7 v_a := 2003;
8 dbms_output.put_line(v_a ||' '|| v_b ||' '|| v_c ||' ' || v_d || ' ' || '&a' || ' '||:v_bind) ;
9* end;
Enter value for a: 34567
old 8: dbms_output.put_line(v_a ||' '|| v_b ||' '|| v_c ||' ' || v_d || ' ' || '&a' || ' '||:v_bind) ;
new 8: dbms_output.put_line(v_a ||' '|| v_b ||' '|| v_c ||' ' || v_d || ' ' || '34567' || ' '||:v_bind) ;
2003 100 ......

SQL SERVER 游标

SqlServer 2000 游标用法小例 翻弹押尾桑Cannon(卡侬) »
--------------------------------------------------------------------------------
DECLARE CURSOR (T-SQL)创建游标
September 14th, 2006 by OoperMan  (1 votes, average: 5 out of 5) Loading ...
SQL Server 2005 联机丛书
DECLARE CURSOR (Transact-SQL)
更新日期: 2005 年 12 月 5 日
定义 Transact-SQL 服务器游标的属性,例如游标的滚动行为和用于生成游标所操作的结果集的查询。DECLARE CURSOR 接受基于 SQL-92 标准的语法和使用一组 Transact-SQL 扩展插件的语法。
Transact-SQL 语法约定
语法
SQL 92 Syntax
DECLARE cursor_name [ INSENSITIVE ] [ SCROLL ] CURSOR 
     FOR select_statement 
     [ FOR ...{ READ ONLY | UPDATE [ OF column_name [ ,...n ] ] } ]
[;]
Transact-SQL Extended Syntax
DECLARE cursor_name CURSOR [ LOCAL | GLOBAL ]
     [ FORWARD_ONLY | SCROLL ]
     [ STATIC | KEYSET | DYNAMIC | FAST_FORWARD ]
    ......

SQL code动态sql语句基本语法

SQL code动态sql语句基本语法
 1 :普通SQL语句可以用Exec执行
eg: Select * from tableName
Exec('select * from tableName')
Exec sp_executesql N 'select * from tableName'
 -- 请注意字符串前一定要加N
2:字段名,表名,数据库名之类作为变量时,必须用动态SQL
eg: declare @fname varchar(20)
 set @fname = 'filedName'
 Select @fname from tableName
 -- 错误,不会提示错误,但结果为固定值FiledName,并非所要。
 Exec('select ' + @fname + ' from tableName')
 -- 请注意 加号前后的 单引号的边上加空格  当然将字符串改成变量的形式也可
declare @fname varchar(20) set @fname = 'FiledName'
 --设置字段名
declare @s varchar(1000) set @s = 'select ' + @fname + ' from tableName'
Exec(@s)
 -- 成功
 exec sp_executesql @s
 -- 此句会报错
declare @s Nvarchar(1000)
 -- 注意此处改为nvarchar(1000)
set @s = 'select ' + @fname + ' from tableName'
Exec(@s)
 -- 成功
exec sp_executesql @s
-- 此句正确
3. 输出参数
 declare ......

sql分页

declare @p int
declare @p1 int
declare @count int
set @p=0
set @p1=10
set @count=2
if(@count<>0 or @count<>1)
set @p=@p1*@count-10
SELECT [t1].[userid], [t1].[username], [t1].[userorder]
from (
    SELECT ROW_NUMBER() OVER (ORDER BY [t0].[userorder]) AS [ROW_NUMBER], [t0].[userid], [t0].[username], [t0].[userorder]
    from [dbo].[users] AS [t0]
    ) AS [t1]
WHERE [t1].[ROW_NUMBER] BETWEEN @p + 1 AND @p + @p1 ......
总记录数:4346; 总页数:725; 每页6 条; 首页 上一页 [302] [303] [304] [305] 306 [307] [308] [309] [310] [311]  下一页 尾页
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号