学习日志 2012年7月9日
1.decode函数的语法
Decode(base_exp, exp1, value1, exp2, value2, exp3, value3 …)
decode(cfgtype, '9',
(Select max(smc_name)
From tbl_cfg_smc smc,tbl_cfg_smcmap smcmap
Where smcmap.dblinkid='0'
And smc.smc_number=smcmap.smc_number),
'0',smc_map) as smc,
decode(cfgtype,'9','全部','0','全部','1',smc_map)
2.excel求积的函数 product
3.判断DB是否运行
--判断 database link 是否有效 FUNCTION IsDBAlive(DBName VARCHAR2) RETURN BOOLEAN IS v_name VARCHAR2(20) := DBName; --注意传入的DBName参数以'@'开头,例如: @ln20 v_sql VARCHAR2(200); BEGIN IF v_name IS NULL or v_name = '@LocalDB' THEN --如果是本地数据库直接返回真? RETURN TRUE; ELSE v_sql := 'SELECT 1 FROM DUAL' || DBName; EXECUTE IMMEDIATE v_SQL; --测试 database link RETURN TRUE; --成功返回TRUE END IF; EXCEPTION WHEN OTHERS THEN RETURN FALSE; -- 异常返回FALSE END IsDBAlive; -- 数据库连接是否已存在 FUNCTION IsDBLinkExists(DBLinkName VARCHAR2) RETURN BOOLEAN IS v_num PLS_INTEGER; BEGIN SELECT 1 INTO v_num FROM USER_DB_LINKS -- Minus the db_domain WHERE DB_LINK LIKE UPPER(TRIM(DBLinkName)) || '.%' or DB_LINK = UPPER(TRIM(DBLinkName)); -- 防止数据库自动为 database link 名添加后缀,例如:ln20.us.oracle.com RETURN TRUE; EXCEPTION WHEN OTHERS THEN RETURN FALSE; END IsDBLinkExists; |
4.如何打包DB代码
(1)export导出DB
(2)压缩DB文件夹成.zip格式
(3)以二进制格式FTP压缩包到服务器上,并解压包: unzip db.zip
(4)修改目录名为小写db: mv '***' db
(5)进入db目录:cd db,修改db的格式 dos2unix *.*
(6)返回上级目录:cd .. 修改压缩包的权限chmod -R 777 db
(7)压缩db文件夹 tar -cvf 'HUAWEI SMS-Service R001C20L00103.db.tar' db
(8)测试是否成功 tar -xvf 'HUAWEI SMS-Service R001C20L00103.db.tar'
安装业务数据库
5.怎样将当前时间转化为五分钟粒度?
select sysdate+5/24/60from dual;
SELECT TO_CHAR(sysdate, 'MI') from dual;
SELECT substr(TO_CHAR(sysdate, 'MI'),2,1) from dual;
SELECT floor(substr(TO_CHAR(sysdate, 'MI'),2,1)) from dual;
SELECT FLOOR(SUBSTR(TO_CHAR(sysdate, 'MI'),2,1) / 5) * 5 from dual;
select TRUNC(sysdate, 'HH24') +
FLOOR((TO_CHAR(sysdate, 'MI') / 10)) / 144 +
(FLOOR(SUBSTR(TO_CHAR(sysdate, 'MI'),2,1) / 5) * 5) / 1440
from dual;
1440 = 24*60
Number/1440: 即number分钟(将数字number转化为分钟)
6.case when的用法
v_Sql := 'INSERT INTO TBL_TMP_PER_ESMEG
(Period,SMC,MTMNET,SUCCMTMNET,ESMETimeout,SMSCReport)
SELECT '||v_Period||','||v_smc||',
SUM(case when exists (select 1 from TBL_CFG_ESMEDESC e where e.esmetype = orgaccount) then coun else 0 end),
SUM(case when (exists (select 1 from TBL_CFG_ESMEDESC e where e.esmetype = orgaccount)) and result = 0 then coun else 0 end),
SUM(case when (exists (select 1 from TBL_CFG_ESMEDESC e where e.esmetype = destaccount)) and StatusReport=0 and CS=68 and isLast=1 then coun else 0 end),
SUM(case when (exists (select 1 from TBL_CFG_ESMEDESC e where e.esmetype = destaccount)) and StatusReport=1 and isLast=1 then coun else 0 end)
FROM '||v_srcTablemt||v_DBLinkName||v_conSql||v_MapClause|| ' group by '|| v_Period||','||v_smc ;
Execute Immediate v_SQL Using pd_BeginTime,pd_EndTime;