??xml version="1.0" encoding="utf-8" standalone="yes"?>国产在线不卡一区二区三区,色综合咪咪久久,日本一区免费网站http://www.aygfsteel.com/lingy/category/39870.htmlzh-cnWed, 18 Aug 2010 23:12:54 GMTWed, 18 Aug 2010 23:12:54 GMT60Oracle DDL,DML,DCL,TCL 基础概念 http://www.aygfsteel.com/lingy/archive/2010/08/17/329116.html林光?/dc:creator>林光?/author>Tue, 17 Aug 2010 08:50:00 GMThttp://www.aygfsteel.com/lingy/archive/2010/08/17/329116.htmlDDL
Data Definition Language (DDL) statements are used to define the database structure or schema. Some examples:
CREATE - to create objects in the database
ALTER - alters the structure of the database
DROP - delete objects from the database
TRUNCATE - remove all records from a table, including all spaces allocated for the records are removed
Transaction Control (TCL) statements are used to manage the changes made by DML statements. It allows statements to be grouped together into logical transactions.
COMMIT - save work done
SAVEPOINT - identify a point in a transaction to which you can later roll back
ROLLBACK - restore database to original since the last COMMIT
SET TRANSACTION - Change transaction options like isolation level and what rollback segment to use
加了whereqo条g的SQL:
select areaname,sys_connect_by_path(areaname,',')
from areas bb
where bb.areaid>861000
start with areaname='中国大陆'
connect by parentareaid=prior areaid
加了connect by的过滤条Ӟ
select areaname,sys_connect_by_path(areaname,',')
from areas bb
where bb.areaid>861000
start with areaname='中国大陆'
connect by parentareaid=prior areaid and areaname<>'q东'
中间Z么要断掉Q?,9 目的是Z区别每个分支?到后面看具体的SQLQ就明白q里的说法了?br />
杀手锏
既然我们有了树, 可以用树型函数SYS_CONNECT_BY_PATH和connect by啦,来拼接我们所需要的多列倹{?br />
脚本如下Q?br />
select no,sys_connect_by_path(q,',')
from (
select no,q,
no+row_number() over( order by no) rn,
row_number() over(partition by no order by no) rn1
from test
)
start with rn1=1
connect by rn-1=prior rn
l极武器
最l我们要的|是单列| 其实xQ?也就是最长的一行咯?那么好办了?我们直接GROUP BY Q然后取MAX倹{?br />
脚本如下Q?br />
select no,max(sys_connect_by_path(q,','))
from (
select no,q,
no+row_number() over( order by no) rn,
row_number() over(partition by no order by no) rn1
from test
)
start with rn1=1
connect by rn-1=prior rn
group by no
declare
l_routin varchar2(100) := 'gen2161.get_rowcnt';
l_tblnam varchar2(20) := 'emp';
l_cnt number;
l_status varchar2(200);
begin
execute immediate 'begin ' || l_routin || '(:2, :3, :4); end;'
using in l_tblnam, out l_cnt, in out l_status;
if l_status != 'OK' then
dbms_output.put_line('error');
end if;
end;
5. 返回g递到PL/SQL记录cd;同样也可?rowtype变量
declare
type empdtlrec is record (empno number(4),
ename varchar2(20),
deptno number(2));
empdtl empdtlrec;
begin
execute immediate 'select empno, ename, deptno ' ||
'from emp where empno = 7934'
into empdtl;
end;
6. 传递ƈ索?INTO子句用在USING子句?br />
declare
l_dept pls_integer := 20;
l_nam varchar2(20);
l_loc varchar2(20);
begin
execute immediate 'select dname, loc from dept where deptno = :1'
into l_nam, l_loc
using l_dept ;
end;
Microsoft SQL Server 引入一U功能,此功能可删除或截断超q?128 个区的表Q而无需同时保留需要删除的所有区的锁。有兌l信息,请参?a id="ctl00_MTContentSelector1_mainContentContainer_ctl04" onclick="javascript:Track('ctl00_MTContentSelector1_mainContentContainer_cpe28768_c|ctl00_MTContentSelector1_mainContentContainer_ctl04',this);" >删除q新生成大型对?/a>?/p>
USE AdventureWorks;
GO
SELECT COUNT(*) AS BeforeTruncateCount
FROM HumanResources.JobCandidate;
GO
TRUNCATE TABLE HumanResources.JobCandidate;
GO
SELECT COUNT(*) AS AfterTruncateCount
FROM HumanResources.JobCandidate;
GO
]]>over partition by与group by 的区?/title>http://www.aygfsteel.com/lingy/archive/2009/06/29/284658.html林光?/dc:creator>林光?/author>Mon, 29 Jun 2009 11:04:00 GMThttp://www.aygfsteel.com/lingy/archive/2009/06/29/284658.html各位好!
over partition by ?group by 都是与统计类函数用,q两个有什么区别呢Q?br />
目前我只知道一个这L区别Q?br />
比如有一张表saraly:CREATE TABLE SALARY AS SELECT 'A' NAME,10 DEPT,1000 SALARY FROM DUAL UNION ALL SELECT 'B',10,2000 FROM DUAL UNION ALL SELECT 'C' ,20,1500 FROM DUAL UNION ALL SELECT 'D',20,3000 FROM DUAL UNION ALL
SELECT 'E',10,1000 FROM DUAL;
NAME DEPT SALARY
A 10 1000
B 10 2000
C 20 1500
D 20 3000
E 10 1000
用over partition by 我就可以查询到每位员工本来的具体信息和它所在部门的d资:
select name,dept,salary,sum(salary) over (partition by dept) total_salary from salary;
name dept salary tatal_salary
A 10 1000 4000
B 10 2000 4000
E 10 1000 4000
C 20 1500 4500
D 20 3000 4500
用goup by 没办法做到q点Q只能查询到每个部门的d资:
select dept,sum(salary) total_salary from salary group by dept
dept total_salary
10 4000
20 4500
另外over partion by q可以做到查询每位员工占部门d资的癑ֈ比:
select name,dept,salary,salary*100/sum(salary) over (partition by dept) percent from salary;
name dept salary percent
A 10 1000 25
B 10 2000 50
E 10 1000 25
C 20 1500 33.3333333333333
D 20 3000 66.6666666666667
用group by 也没办法做到q个.不知道我的理解正不正,请各位朋友指点,特别是over partition by 与group by 的更多区别请各位一起分享,谢谢Q?br />
20 4500
]]>能否按照DECODE条g来COUNTQ?Q?/title>http://www.aygfsteel.com/lingy/archive/2009/06/29/284556.html林光?/dc:creator>林光?/author>Mon, 29 Jun 2009 02:57:00 GMThttp://www.aygfsteel.com/lingy/archive/2009/06/29/284556.html表A
DW WP BJ
Q-Q-Q-Q-Q-Q-Q-Q-
A M1 Y
B M2 N
C M3 Y
D M1 Y
]]>oracle merge into 的用法详?实例 http://www.aygfsteel.com/lingy/archive/2009/06/18/283070.html林光?/dc:creator>林光?/author>Thu, 18 Jun 2009 08:10:00 GMThttp://www.aygfsteel.com/lingy/archive/2009/06/18/283070.htmloracle merge into 的用法详?实例
oracle merge into 的用法详?实例
作用Qmerge into 解决用B表跟新A表数据,如果A表中没有Q则把B表的数据插入A表;
语法Q?/p>
MERGE INTO [your table-name] [rename your table here]
USING ( [write your query here] )[rename your query-sql and using just like a table]
ON ([conditional expression here] AND [...]...)
WHEN MATHED THEN [here you can execute some update sql or something else ]
WHEN NOT MATHED THEN [execute something else here ! ]
merge into tfa_alarm_act_nms a
using (select FP0,FP1,FP2,FP3,REDEFINE_SEVERITY
from tfa_alarm_status) b
on (a.fp0=b.fp0 and a.fp1=b.fp1 and a.fp2=b.fp2 and a.fp3=b.fp3)
when matched then update set a.redefine_severity=b.redefine_severity
when not matched then insert (a.fp0,a.fp1,a.fp2,a.fp3,a.org_severity,a.redefine_severity,a.event_time
,a.int_id)
values (b.fp0,b.fp1,b.fp2,b.fp3,b.REDEFINE_SEVERITY,b.redefine_severity,sysdate,7777778);
作用Q利用表 tfa_alarm_status跟新?font color="#0000ff">tfa_alarm_act_nms 的b.redefine_severityQ?/font>条g?font color="#0000ff">a.fp0=b.fp0 and a.fp1=b.fp1 and a.fp2=b.fp2 and a.fp3=b.fp3Q?/font>如果tfa_alarm_act_nms表中没有该条件的数据插入?/font>
]]>怎样从一个过E返回一个结果集http://www.aygfsteel.com/lingy/archive/2009/06/18/283045.html林光?/dc:creator>林光?/author>Thu, 18 Jun 2009 06:22:00 GMThttp://www.aygfsteel.com/lingy/archive/2009/06/18/283045.htmlcreate or replace procedure p_stu_lst(result out sys_refcursor) is
BEGIN
OPEN RESULT FOR SELECT * FROM test;
end p_stu_lst;
SQL> select * from test;
NAME KM CJ
---------- ---------- ----------
张三 语文 80
张三 数学 86
张三 p 75
李四 语文 78
李四 数学 85
李四 p 78
李四 物理 90
已选择7行?br />
SQL> exec p_stu_lst(:aaa);
PL/SQL q程已成功完成?br />
SQL> print aaa
NAME KM CJ
---------- ---------- ----------
张三 语文 80
张三 数学 86
张三 p 75
李四 语文 78
李四 数学 85
李四 p 78
李四 物理 90
/*声明部分Q以declare开?/
declare v_id integer;
v_name varchar(20);
cursor c_emp is select * from employee where emp_id=3;
/*执行部分Q以begin开?/
begin open c_emp; //打开游标
loop
fetch c_emp into v_id,v_name; //从游标取数据
exit when c_emp%notfound ;
end loop ;
close c_emp; //关闭游标
dbms_output.PUT_LINE(v_name);
/*异常处理部分Q以exception开?/
exception
when no_data_found then
dbms_output.PUT_LINE('没有数据');
end ;
2. 控制l构
PL/SQLE序D中有三U程序结构:条gl构、@环结构和序l构?
1) 条gl构
与其它语a完全cMQ语法结构如下:
if condition then
statement1
else
statement2
end if ;
2) 循环l构
q一l构与其他语a不太一P在PL/SQLE序中有三种循环l构Q?
a. loop … end loop;
b. while condition loop … end loop;
c. for variable in low_bound . . upper_bound loop … end loop;
Create or replace procedure test_procedure as
V_f11 number :=1; /*声明变量q赋初?/
V_f12 number :=2;
V_f21 varchar2(20) :='first';
V_f22 varchar2(20) :='second';
Begin
Insert into t1 values (V_f11, V_f21);
Insert into t1 values (V_f12, V_f22);
End test_procedure; /*test_procedure可以省略*/
]]>oracle 存储q程的基本语?/title>http://www.aygfsteel.com/lingy/archive/2009/06/18/282994.html林光?/dc:creator>林光?/author>Thu, 18 Jun 2009 02:43:00 GMThttp://www.aygfsteel.com/lingy/archive/2009/06/18/282994.html
oracle 存储q程的基本语?/h1>
1.基本l构
CREATE OR REPLACE PROCEDURE 存储q程名字
(
参数1 IN NUMBER,
参数2 IN NUMBER
) IS
变量1 INTEGER :=0;
变量2 DATE;
BEGIN
END 存储q程名字
2.SELECT INTO STATEMENT
select查询的结果存入到变量中,可以同时多个列存储多个变量中,必须有一?br />
记录Q否则抛出异?如果没有记录抛出NO_DATA_FOUND)
例子Q?
BEGIN
SELECT col1,col2 into 变量1,变量2 FROM typestruct where xxx;
EXCEPTION
WHEN NO_DATA_FOUND THEN
xxxx;
END;
...
3.IF 判断
IF V_TEST=1 THEN
BEGIN
do something
END;
END IF;
4.while 循环
WHILE V_TEST=1 LOOP
BEGIN
XXXX
END;
END LOOP;
5.变量赋?br />
V_TEST := 123;
6.用for in 使用cursor
...
IS
CURSOR cur IS SELECT * FROM xxx;
BEGIN
FOR cur_result in cur LOOP
BEGIN
V_SUM :=cur_result.列名1+cur_result.列名2
END;
END LOOP;
END;
7.带参数的cursor
CURSOR C_USER(C_ID NUMBER) IS SELECT NAME FROM USER WHERE TYPEID=C_ID;
OPEN C_USER(变量?;
LOOP
FETCH C_USER INTO V_NAME;
EXIT FETCH C_USER%NOTFOUND;
do something
END LOOP;
CLOSE C_USER;
SELECT fname, lname, pcode FROM cust WHERE id = 674;
SELECT fname, lname, pcode FROM cust WHERE id = 234;
SELECT fname, lname, pcode FROM cust WHERE id = 332;
含绑定变量的sql 语句Q?br />
SELECT fname, lname, pcode FROM cust WHERE id = :cust_no;
Sql*plus 中用绑定变量:
sql> variable x number;
sql> exec :x := 123;
sql> SELECT fname, lname, pcode FROM cust WHERE id =:x;
]]>如何得到一个存储过E的创徏脚本http://www.aygfsteel.com/lingy/archive/2009/05/27/278279.html林光?/dc:creator>林光?/author>Wed, 27 May 2009 15:21:00 GMThttp://www.aygfsteel.com/lingy/archive/2009/05/27/278279.html1Q如何得C个存储过E的创徏脚本
查询数据字典Quser_source ?dba_source
SQL>select text from dba_source where name='p_******' and type='PROCEDURE';
2Q如何得到数据库中无效的存储q程
查询数据字典Qdba_objects
SQL> select object_name from dba_objects where object
]]>Oracle function ?http://www.aygfsteel.com/lingy/archive/2009/05/26/277972.html林光?/dc:creator>林光?/author>Tue, 26 May 2009 03:11:00 GMThttp://www.aygfsteel.com/lingy/archive/2009/05/26/277972.html阅读全文