SQL语句PART10
oracle tips
Exist的用法:
select gw.ndocid from
(select ndocid from wf_doc_gw_shouwen union select ndocid from wf_doc_gw_fawen) gw
where
not exists (select null from wf_doc_gw_sn sn where sn.ndocid=gw.ndocid)
2。把GW表和SN表里相同的NDOCID显示出来
select gw.ndocid from
(select ndocid from wf_doc_gw_shouwen union select ndocid from wf_doc_gw_fawen) gw
where
exists (select null from wf_doc_gw_sn sn where sn.ndocid=gw.ndocid)
DECODE的语法:DECODE(value,if1,then1,if2,then2,if3,then3,...,else),
e.g.:
select decode(max(documentid), null, 1, (max(documentid)+1))) from document;
results:
if null, display 1
else display max(documentid)+1
1. export database
cmd
%oracle_home%\bin\exp carmot/carmot@132.159.178.236_igrp2 file=d:\a.dmp
2. oracle enterprise console
connect as sysdba
安全性,右键,建立用户carmot_hunan_1,密码用carmot
给dba权限。
3. import database
cmd
%oracle_home%\bin\imp carmot_hunan_1/carmot@132.159.178.236_igrp2 file=d:\a.dmp fromuser=carmot
** remarks:
carmot_hunan_1/carmot@132.159.178.236_igrp2
用户名/密码@配置在TOAD中的数据库名称
例如: TOAD中数据库的名称是: IGRP2_132.159.178.236, 则为: carmot_hunan_1/carmot@igrp2_132.159.178.236
Example for complicated select:
select distinct first_value(ndocid) over (partition by ndocid order by lv desc) as ndocid,
--first_value(curtitle) over (partition by ndocid order by lv desc) as
curtitle,
first_value(realname) over (partition by ndocid order by lv desc) as realname
from(
select ndocid,curtitle, sys_connect_by_path(realname,' ') realname, level lv from
(select ndocid, curtitle,realname, lag(realname,1,null) over (partition by ndocid order by realname) realname_1
from (select g.ndocid,g.curtitle, u.realname
from wf_doc_gw g, tbuser u
where instr(','||g.cprocuserlist||',',','||u.userid||',')>0)) connect by prior realname=realname_1) order by ndocid
e.g.:
select g.ndocid, g.cproc
相关文档:
因为要根据很复杂的规则处理用户数据,所以这里用到数据库的游标。平时不怎么用这个,写在这里纯粹为自己备个忘。
--将学籍号重复的放入临时表 tmp_zdsoft_unitive_code(除高中学段外)
drop table tmp_zdsoft_unitive_code;
select s.id ,sch.school_code,sch.school_name,s.student_name,s.unitive_code,s.identity_car ......
using System;
using System.Text.RegularExpressions;
using Microsoft.SqlServer.Server;
public partial class UserDefinedFunctions
{
[Microsoft.SqlServer.Server.SqlFunction(IsDeterministic = true,IsPrecise = true)]
public static bool RegExIsMatch(string pattern,string matchString)
{
......
第一题:
为管理业务培训信息,建立3个表:
S(S#,SN,SD,SA)S#,SN,SD,SA分别代表学号,学员姓名,所属单位,学员年龄
C(C#,CN)C#,CN分别代表课程编号,课程名称
SC(S#,C#,G) S#,C#,G分别代表学号,所选的课程编号,学习成绩
(1)使用标准SQL嵌套语句查询选修课程名称为’税收基础’的学员学号和姓名?
(2) ......
1、对象类型规范
创建对象类型规范的语法如下
CREATE [OR REPLACE] TYPE [schema.] type_name
[AUTHID {CURRENT_USER|DEFINER}] AS OBJECT (
Attribute1 datatype,
[attribute2 datatype,…]
[method 1]
[method 2]);
/
其中AUTHID指示将来执行该方法时, ......
Confirming granted privileges
Data Dictionary View Description
ROLE_SYS_PRIVS System privileges granted to roles
ROLE_TAB_PRIVS & ......