Control Structures of PL/SQL Control structures are probably the most useful (and important) part of PL/pgSQL.With PL/pgSQL's control structures, you can manipulate PostgreSQL data in a very flexible and powerful way. 1.Returning From a Function RETU…
1 PL/pgSQL Under the Hood This part discusses some implementation details that are frequently important for PL/pgSQL users to know. 1.1 Variable Substitution SQL statements and expressions within a PL/pgSQL function can refer to variables and paramet…
Cursors Rather than executing a whole query at once, it is possible to set up a cursor that encapsulates the query, and then read the query result a few rows at a time. A more interesting usage is to return a reference to a cursor that a function has…
1.Structure of PL/pgSQL The structure of PL/pgSQL is like below: [ <<label>> ] [ DECLARE declarations ] BEGIN statements END [ label ]; A label is only needed if you want to identify the block for use in an EXIT statement, or to qualify the na…
Trigger Procedures PL/pgSQL can be used to define trigger procedures on data changes or database events. A trigger procedure is created with the CREATE FUNCTION command, declaring it as a function with no arguments and a return type of trigger (for d…
IF条件 declare cursor s is select version from city_server t; s_ city_server.version%type; begin open s; fetch s into s_; if s_>2 then DBMS_OUTPUT.put_line(s_); end if; close s; end; LOOP循环 declare …
资料1 -- Created on 2014/8/20 declare -- Local variables here i integer; begin i := 12; -- Test statements here DBMS_OUTPUT.put_line(i); end; 资料2 declare cursor s is select * from city_app.city_server; s_ s%rowtype; begin …
从外部EXCEl文件导入sqlserver数据库操作命令 reconfigure reconfigure go select * into abc1_1 from OPENROWSET('MICROSOFT.JET.OLEDB.4.0' ,'Excel 5.0;HDR=YES;DATABASE=文件路径',SQLResults$) 注意:文件路径到excel下某个固定的sheet,sheet名字不要有空格 数据库合并 insert into [新数据库名(合并后的)] select [字段] F…
一.在PL\SQL语句块begin...end;中,不能直接使用select,必须与into结合查询. 例如: declare aa:=22; id2 integer; begin select * from tabname where id=aa : end;//提示错误该select语句中缺少into子句 正确:select count(*)into id2 from tabname where id=aa : 当然这样只能得到一条数据,如果需要多数据查询可以使用游标: 二.oracle循…
merge into when matched then... when not mached then... merge into t_road_pre_parameter a from dual ) b on (a.TIME_SEGMENT=? and a.ROAD_ID=? and a.RS_INDEX=? and a.FLAG=) when matched then update set a.week_num=?, a.temperature = ?, a.if_rain…
1.查询安装的排序规则选项喝当前的排序规则服务器属性 select * from fn_helpcollations(); 2.查看当前服务器的排序规则 select serverproperty('Collation') as ServerCollation; 3.修改数据库DB1的排序规则,使他区分大小写 create database DB1 go alter database DB1 collate SQL_Latin1_General_CP1_CS_AS; go select data…
以下内容根据此官方文档修改:http://technet.microsoft.com/zh-cn/library/ms189336(v=sql.105).aspx 嵌套事务的使用场景或者说目的主要是为了调用包含了事务的存储过程.不然没必要使用嵌套事务. 下列示例显示了嵌套事务的用途.在TransProc 存储过程中包含事务,在另外的代码中分别启动事务调用TransProc和不启动事务调用TransProc. SET QUOTED_IDENTIFIER OFF; GO SET NOCOUNT OF…
做个记入就好 USE [master] SELECT bs.database_name AS 'Database Name', bs.backup_start_date AS 'Backup Start', bs.backup_finish_date AS 'Backup Finished', DATEDIFF(MINUTE, bs.backup_start_date, bs.backup_finish_date) AS 'Duration (min)', bmf.physical_device…
http://blog.csdn.net/sqlserverdiscovery/article/details/7712068 Column name Data type Description blocked smallint ID of the session that is blocking the request. If this column is NULL, the request is not blocked, or the session information of…
本文主要摘自徐海蔚的<Microsoft SQL SERVER企业级平台管理实践> 表变量可以作为存储过程的返回参数,而临时表不行.(存疑?表值参数只在SQL SERVER2008才开始支持,并且限制很多,要首先定义表类型) use [test] go create type [user] as table(id int,name varchar(50)); go create procedure test_prd @u [user] readonly as begin select * fr…