April 26, 2008
key words:数据库 主键
在一个差屁股的项目中看到数据库的设计着实让人窝火,业务也算有点复杂,但是关键的表其实也就不超过10来个,但是能把你整晕,让人不得不佩服当初数据库设计的人员的构思. 总体来看存在问题就是主键命名不当,外键的命名也不规范,在和项目组人员的沟通过程中我就强烈暗示大家以后的项目中主键不要想花里胡哨的名字了,直接全部一刀切”ID”就OK了(要是非要找一个理由,不妨看看rails的最佳实践做法),直观明了,外键的名字用父表的表名_id .
另外,我的一位同事提到给表的前面加上业务前缀,或者叫模块前缀,也有实际意义,主要是在项目相对比较复杂,模块比较多的时候比较有用,比如 businessa_table,businessb_table,可能也会看起来麻烦一些,看情况了。
VN:F [1.6.3_896]
Rating: 0.0/10 (0 votes cast)
VN:F [1.6.3_896]
March 6, 2008
1.机器的ip经常改变,到公司一个ip,到客户那一个ip,到家又是一个ip,不知怎么搞的,今天到家oracle的dbconsole就启动不了了.
2.用命令行的方式启动 emctl.bat start dbconsole,结果还提示ORACLE_SID 还没有设置,晕,这个怎么没有了,set 一个吧 set ORACLE_SID=dggmcc (我的数据库实例)
3.还是有错,提示找不到192.168.0.52.这个地址,应该是ip和当初装数据库的时候IP不一样的缘故,将hosts设置一下 192.168.0.52 IDEA
4.OK
VN:F [1.6.3_896]
Rating: 0.0/10 (0 votes cast)
VN:F [1.6.3_896]
October 31, 2007
1.oracle structure:db – > AS – > apps
2.start infrastructure
#su – oracle
. oraenv
[sid] : ocsdb
ocsctl_sample –start infra
2. start apps
# su – oracle
# export ORACLE_HOME=/home/oracle/ocs/apps
# $ORACLE_HOME/bin/ocsctl_sample –start apps
(here you can set var to your .bash profile)
| ./opmnctl startproc gid=OC4J_Portal |
| ./opmnctl startproc gid=OC4J_Portal |
3. start single component
# ./opmnctl startproc gid=OC4J_Portal
4.the RTC components:
5.the portal components:
- OC4J_OCSClient
- OC4J_Portal
note difference with iLearning:
1.db startup
sql>startup
2.start app
opmnctl startall
3.web console
emctl start iasconsole
(emctl start dbconsole command to start oracle db console)
oc4j and deployment
dcmctl createcomponent -ct oc4j -co 【oc4j_name】
dcmctl deployapplication -co 【oc4j_name】 -f webs.war -a 【app_name】 -rc /【rc_name】
VN:F [1.6.3_896]
Rating: 0.0/10 (0 votes cast)
VN:F [1.6.3_896]
October 29, 2007
可以用命令的方式来备份,先全量备份,后增量备份,这个是专业的方式,还有一种方式我称它为土八路的方式,但是好使
就是直接把oradata目录的文件拷贝出来即可,下次重新安装oracle后 把oradata目录覆盖即可。
当然,如果你愿意,也可以把所有oracle的目录拷贝下来
简单就好
VN:F [1.6.3_896]
Rating: 0.0/10 (0 votes cast)
VN:F [1.6.3_896]
September 27, 2007
key words: invalid file operation,utl_file_dir
how to set utl_file_dir in oracle?
my db is Oracle10g,and the default boot method is spfile
1. sql> alter system set utl_file_dir=’c:\tmp’ scope=spfile
2.sql>shutdown immediate
3.sql>start
This time I change the mydbspfile.ora directly,but made mistake,late resolved it by
“create spfile from pfile”
reference here
VN:F [1.6.3_896]
Rating: 0.0/10 (0 votes cast)
VN:F [1.6.3_896]
August 23, 2007
key words: decode,分组
使用 decode可以实现将多个不同的行级别的记录转换到列,有时很有用
come from here
表、视图结构转化
现有一个商品销售表sale,表结构为:
month char(6) –月份
sell number(10,2) –月销售金额
现有数据为:
200001 1000
200002 1100
200003 1200
200004 1300
200005 1400
200006 1500
200007 1600
200101 1100
200202 1200
200301 1300
想要转化为以下结构的数据:
year char(4) –年份
month1 number(10,2) –1月销售金额
month2 number(10,2) –2月销售金额
month3 number(10,2) –3月销售金额
month4 number(10,2) –4月销售金额
month5 number(10,2) –5月销售金额
month6 number(10,2) –6月销售金额
month7 number(10,2) –7月销售金额
month8 number(10,2) –8月销售金额
month9 number(10,2) –9月销售金额
month10 number(10,2) –10月销售金额
month11 number(10,2) –11月销售金额
month12 number(10,2) –12月销售金额
结构转化的sql语句为:
create or replace view
v_sale(year,month1,month2,month3,month4,month5,month6,month7,month8,month9,month10,month11,month12)
as
select
substrb(month,1,4),
sum(decode(substrb(month,5,2),01,sell,0)),
sum(decode(substrb(month,5,2),02,sell,0)),
sum(decode(substrb(month,5,2),03,sell,0)),
sum(decode(substrb(month,5,2),04,sell,0)),
sum(decode(substrb(month,5,2),05,sell,0)),
sum(decode(substrb(month,5,2),06,sell,0)),
sum(decode(substrb(month,5,2),07,sell,0)),
sum(decode(substrb(month,5,2),08,sell,0)),
sum(decode(substrb(month,5,2),09,sell,0)),
sum(decode(substrb(month,5,2),10,sell,0)),
sum(decode(substrb(month,5,2),11,sell,0)),
sum(decode(substrb(month,5,2),12,sell,0))
from sale
group by substrb(month,1,4);
VN:F [1.6.3_896]
Rating: 0.0/10 (0 votes cast)
VN:F [1.6.3_896]
August 19, 2007
key words: update,ORA-01779
经常用到update语句,不过很少用到其他表的数据来更新当前表,这次用到了,总结一下
UPDATE
( SELECT /*+ BYPASS_UJVC */
a.groupname a1,b.groupname b1 from t_account_temp a,t_certificode_temp b
where a.certificode = b.certificode
)
SET a1=b1;
特别的地方是要加 /*+ BYPASS_UJVC */,让oracle不检查健的约束,否则会报ORA-01779错误,不过前提是你确认确实不会有多个b表的值出现,或者即使有多个值也没有影响。
相关参考如下
一种高效率的update多表关联更新测试
ORA-01779的处理方法
VN:F [1.6.3_896]
Rating: 0.0/10 (0 votes cast)
VN:F [1.6.3_896]
August 18, 2007
key words: plsql,导出数据,大数据量
最近的账务的项目中需要导出Excel报表,数据量比较大,解决方案如下 :
1.通过plsql在服务器端查询出符合要求的纪录,然后直接写到文本文件中
2.在web端通过流的方式读文本文件,通过POI写到Excel,将生成的Excel流写到respoonse实现下载
这样做的好处是不必一次性将满足条件的纪录全部取出来,而是通过流的方式.
这个方式原来在处理Blob类型的字段时有直接的getStream来支持的,这次普通的数据只好通过文件的方式来实现.
贴一段sample的代码
create or replace procedure alex_table_to_txt(filepath varchar2,filename varchar2) is
--var
v1 alex2.name%type;
v2 alex2.address%type;
v3 alex2.groupname%type;
output varchar2(200);
–file var
file_handle UTL_FILE.FILE_TYPE;
cursor readtable is select t.name,t.address,t.groupname from alex2 t;
begin
file_handle:=utl_file.fopen(filepath,filename,’w',6000);
open readtable;
loop
fetch readtable into v1,v2,v3;
exit when readtable%notfound;
output:=v1 || ‘,’ || v2 || ‘,’ || v3 ;
utl_file.put_line(file_handle,output);
end loop;
close readtable;
utl_file.fclose(file_handle);
end alex_table_to_txt;
/
欢迎讨论你的方案
VN:F [1.6.3_896]
Rating: 0.0/10 (0 votes cast)
VN:F [1.6.3_896]