您正在查看 "Oracle Pl Sql" 分类下的文章 2009年12月08日 星期二 14:17 select max(gmt_create) from t_tname where author_id=:1 and rownum=1;
这个sql是否满足author_id下取最大的时间。
答案是肯定的,不满足
这个sql会先取满足条件的 where author_id=:1 一条记录,再取MAX就没有任何意义了。
但是到author_id上存在索引的情况下,执行计划会是
SORT AGGREGATE
COUNT STOPKEY
FIRST RO |
2009年10月28日 星期三 17:37
--调整序列到表中最大ID的脚本
set linesize 2000
set feedback off
set define off
set head off
set timing off
--删除seq脚本
SELECT 'DROP SEQUENCE '||F.SEQUENCE_NAME ||';' FROM user_sequences f;
--获取创建seq脚本
select 'select ''create sequence SEQ_'|| t.TABLE_NAME||'_ID start with ''||'||
'decode((select max('||t.COLUMN_NAME||') from '||t.TABLE_NAME||'),null,1,(select max('||t.COLUMN_NAME||') from '|| t.TABLE_NAME||')+1)||'';'' from dua
|
2009年08月27日 星期四 14:56 一般我们采用复制表的方式主要是
create table table_name
as select /*+ parallel (t 10)*/ * from t_name t ...
insert /*+ append */ into table_name
select /*+ parallel (t 10)*/ * from tname t ...
这两者方法都没有问题,但如果数据量到达一定程度,比如说10亿,大小400G,而且表上还存在业务,这样的话,很容易出现01555的问题。 我在运行了3个小时后遇到了恼人的01555,将undo_retention改到一个足够大的值还是不行,毕竟表太大,而且表上有业务在更新数据。
有 |
2009年07月10日 星期五 14:21 1、PL/SQL Developer记住登陆密码
在使用PL/SQL Developer时,为了工作方便希望PL/SQL Developer记住登录Oracle的用户名和
密码;
设置方法:PL/SQL Developer 7.1.2 ->tools->Preferences->Oracle->Logon History , “Sto
re history”是默认勾选的,勾上“Store with password” 即可,重新登录在输入一次密码则记
住了。
--开发库使用
2、执行单条SQL语句
在使用PL/SQL Developer的SQL Window时,按F8键, |
2009年06月16日 星期二 18:16
SQL> select * from tmp_xf;
TEXT
--------------------
abcdefg
abc_defg
abc%defg
abc&defg
abc/defg
abc%defg
abc defg
7 rows selected.
SQL> select * from tmp_xf where text like 'abc\_%' escape '\';
TEXT
--------------------
abc_defg
转义字符为'\';
SQL> select * from tmp_xf where text like 'abc _%' escape ' ';
TEXT
--------------------
abc_defg
转
|
2009年06月12日 星期五 13:29 connect by 是结构化查询中用到的,其基本语法是:
select ... from tablename start with 条件1
connect by 条件2
where 条件3;
例:
select * from table
start with org_id = 'HBHqfWGWPy'
connect by prior org_id = parent_id;
简单说来是将一个树状结构存储在一张表里,比如一个表中存在两个字段:
org_id,parent_id那么通过表示每一条记录的parent是谁,就可以形成一个树状结构。
用上述语法的查询可以取得这棵树的所有记录。 |
2009年06月05日 星期五 17:43 create table tmp_xf_1 as select * from tmp_xf_tst;
1. 13:39:01 SQL> create table tmp_xf_1 as select * from tmp_xf_tst;
Table created.
Elapsed: 00:00:56.01
create table tmp_xf_2 nologging as select * from tmp_xf_tst;
2. 13:40:29 SQL> create table tmp_xf_2 nologging as select * from tmp_xf_tst;
Table created.
Elapsed: 00:00:44.69
create table tmp_xf_5 nologging parallel(d |
2009年05月11日 星期一 17:33 有需求要把clob字段做插入和更新操作,不允许用跳板机的工具来更新lob字段了。 用如下方式吧。
Tom在他的《Expert one on one oracle》给出了sqlplus中将文件load进BLOB或CLOB字段的例子。这里保存一份以备急用。
|
create directory ULTLOBDIR as 'd:'
create table blobtest(col1 BLOB);
create table | |
2009年05月07日 星期四 17:02 其实可以更简单,有的时候自己比较笨,用笨的方法还不亦乐乎
我需要对比初始化后的数字ID是否和原表中的吻合(其实脚本肯定是没问题了,但万一起见还是要验证的,而且程序那边也有可能有问题的)
select b.auction_id,b.auc_num_id aa,a.auction_id ba
from auctions@lnk_db a,feedbacks b where a.id = b.auction_id and b.id in(
select /*+ rowid(t) */ id from auction_feedbacks t
where rowid >='AAABigAAJAAAiYJAAA' and rowid <='AAABigAAJAAAisICcQ' );
我需要比较 aa和ba取出 |
2009年05月04日 星期一 17:32
insert into tmp_xf_test values(923456789012,'Ad62d45cf37fc5ae977429bd7189373d',sysdate);
|
2009年04月03日 星期五 17:17 Question: What is the difference between "alter table move" and shrink space?
Answer: There are several ways to reclaim wasted space in a table, but they work differently. Also, see my notes on identifying tables for space reclamation.
|
2009年04月01日 星期三 22:07 记录一下 http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14354/appb.htm#CJHIIICD
Oracle Reserved Words
The following words are reserved by Oracle. That is, they have a special meaning to Oracle and so cannot be redefined. For this reason, you cannot use them to name database objects such as columns, tables, or indexes.
|
2009年03月24日 星期二 10:54 create table tmp_xf_rowid as
select rowid rid from xf_detail
where isdo_bss is not null
order by 1;
declare
i number := 0;
begin
for c in (select * from tmp_xf_rowid) loop
update xf_detail t set isdo_bss = null where t.rowid = c.rid;
i := i + 1;
if mod(i, 100) = 0 then
commit;
end if;
end loop;
commit;
end |
2009年03月07日 星期六 10:36 相信很多人都有过统计某些数据的经历,比如,要统计财务的情况,可能要按每年,每季度,每月,甚至每个星期来分别统计。那在oracle中应该怎么来写sql语句呢,这个时候Oracle的日期函数会给我们很多帮助。--转帖,记录查询用
常用日期型函数
1。Sysdate 当前日期和时间
SQL> Select sysdate from dual;
SYSDATE
----------
21-6月 -05
2。Last_day 本月最后一天
SQL> Select last_day(sysdate) from dual;
LAST_DAY(S
----------
30-6月 -05
3。Add_m |
2009年03月06日 星期五 17:23 晕,这年头数据老是被篡改,开发环境都这样。。。。 应开发人员要求,简单记录一下操作
create table TMP_MONITOR
(
USERNAME VARCHAR2(100),
OSUSER VARCHAR2(100),
MACHINE VARCHAR2(100),
TERMINAL VARCHAR2(100),
PROGRAM VARCHAR2(100),
SQL_ID VARCHAR2(100),
MODULE VARCHAR2(100),
GMT_CREATE DATE,
SQLTEXT |
| | |