Search This Blog

2016/12/26

Authority with Synonym

Authorities / Grant option:
Alter
Delete
Index
Insert
References
Select
Update

When drop synonym
Private synonym: Drop any synonym
Public synonym: Drop public synonym

Delete data by using synonym in Oracle

Code:
DELETE FROM syn_table_name;

Attention
User have delete authority.

Why don't use truncate?
As Synonyms can't be used in drop table/view or truncate table/cluster statements. It will cause ORA-00942: table or view does not exist.

2016/12/21

VBA: Get all files' name and content in folder

As an example, save txt files in C://temp/

Code:
Dim file As String
Dim r As Integer
Dim text As String

Path = "C://temp/"
'get first file name
fileName =Dir(Path + "*.txt")
r = 1
'Start the loop.
Do While Len(fileName) > 0
    'output file name
    Cells(r, 1).Value = fileName
    'get content
    filePath = Path + fileName
    Open filePath For Input As #1
        Do Until EOF(1)
            Line Input #1, text
        Loop
        'output content
        Cells(r, 2).Value = text
    Close #1

    'Get next file.
    file = Dir()
Loop
Reference:
Dir Function:Returns a string representing the name of a file, directory, or folder that matches a specified pattern or file attribute, or the volume label of a drive.

VBA: Get max row/column number|最大行/列取得

Max row number
MaxRow = Range("A1").End(xlToRight).End(xlDown).Row
Max Column number
MaxCol = Range("A1").End(xlToRight).End(xlToRight).Column
Or count back of end
MaxRow = Range("A666666").End(xlUp).Row
MaxCol = Range("IV1").End(xlToLeft).Column
In Micsoft Excel 2010, the maximum row is 1048576, the maximum column is XFD

2016/12/20

Insert: Ignore duplicate key|插入数据时无视一致性错误|インサート: 一意制約を無視する

Use hint:
IGNORE_ROW_ON_DUPKEY_INDEX

Example|例
example_tbl and example_tbl_pk
Code:
INSERT /*+ IGNORE_ROW_ON_DUPKEY_INDEX(example_tbl, example_tbl_pk) */
INTO example_tbl
VALUES (id, ...);

If this id (primary key) isn't exist in example_tbl, insert this record. Or ignore this record and do next function.


2016/12/19

Automatically number rows in Select自動採番

Use rownum, number count from 1;

Example:
insert into table2
select rownum, t3.name
from table1 t1
join table3 t3 on t1.id=t3.id


2016/12/14

Oracle performance tuning Tips: speed up

In order to speed up, index is important.
Avoid doing Full Scan.

Speed:
Index Unique scan > Index range scan > Index full scan

Index points:
Unique index 一意性が高い索引を
Start with frequently-used columns 使用頻度の高い列を先頭に
Start with low selectivity columns 選択率の低い列を先頭に
Include key with non-unique index 非ユニーク索引にはキー圧縮

Other:
Use hint efficiently.
/*+ INDEX( e e_index_1) */

It's better to use NVL(e1,e2) = e2 instead of "is null" if null data is less than no-null data.

2016/12/12

Window Startup setting

Set the startup application.

Use key [Win+R]
Input [msconfig] and press Enter key or click OK button.

Select tab [startup]
Uncheck/check the app and Apply or OK.
Unchecked app means it wantn't startup with Windows, and when it been uncheck is recorded.

2016/12/08

Page Redirect/画面遷移/页面跳转

By meta tag:
<meta http-equiv="refresh" content="seconds;URL=url">

Example:
<meta http-equiv="refresh" content="0;URL=https://randinblogger.blogspot.com">

By JavaScript:
window.location = "url";
window.location.href = "url";
window.location.assign = "url";
window.location.replace = "url";

By .htaccess file:
mod_rewrite need be actived.
Redirect 301 / url 

How to set PHPExcel header

Code:
//.xls file
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=download.xls");

//.xlsx file
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header("Content-Disposition: attachment; filename=download.xlsx");

//Same part:
header("Cache-Control: max-age=0");

// Sample
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-ravalidate, post-check=0, pre-check=0');
header('Content-Type: application/force-download');
header('Content-Type: application/octet-stream');
header('Content-Type: application/download');
header("Content-disposition: attachment; filename=sample.xls");

References:
https://support.microsoft.com/en-us/kb/936496

2016/12/06

SQL Developer "Enter the full pathname for java.exe"

When start Oracle SQL Developer first time, it will ask for full pathname for the "java.exe".

SQL Developer path:
...\sqldeveloper\sqldeveloper\bin
java.exe path:
...\jdk
"..." means "C:\\app\[user]\product\[Oracle version number]\client_1
For example:
SQL Developer path:
C:\\app\administrator\product\11.2.0\client_1\sqldeveloper\sqldeveloper\bin
java.exe path:
C:\\app\administrator\product\11.2.0\client_1\jdk
Or modify
...\sqldeveloper\sqldeveloper\bin\sqldeveloper.conf

Add "SetJavaHome ..\..\..\jdk, then no need to input java.exe pathname anymore.

2016/11/30

A quick way to get iPhone / iPad safari version 版本快速查询

You can also check version of other browsers by inputing below in address.
Or you can just click it.
通过点击下方代码链接即可获得现在使用中的浏览器版本。也可将其复制保存为书签后访问。

javascript:(function()%7Balert(navigator.userAgent);%7D)();

This JavaScript will make alert with message of your device info.
点击后将出现类似图片中的信息。

2016/11/29

A sample html page

Simple sample:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <title>Sample page title</title>
    <!--[if lt IE 9]>
        <script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script>
    <![endif]-->
</head>
  <body>
    <div>Output something</div>
  </body>
</html>

Other

meta:
<meta name="viewport"
      content="
          height = [pixel_value | "device-height"] ,
          width = [pixel_value | "device-width"] ,
          initial-scale = float_value ,
          minimum-scale = float_value ,
          maximum-scale = float_value ,
          user-scalable = ["yes" | "no"]
          " />

2016/11/28

CSS different child elements within a same parent同一阶层下的元素对应

HTML structure:
<div>
<span>element 1</span>
<p>element 2</p>
<p>element 3</p>
</div>

CSS:
div span {clear:both;}
div span + p {color: aquamarine;}
div span + p + p {color: blueviolet;}

2016/11/24

jQuery 取得form值

Code:
<form name="return" action="/" method ="post" id ="form">
<input type ="checkbox" name ="box1" group ="checkbox" checked="checked">
<input type ="checkbox" name ="box2" group ="checkbox">
<input type ="checkbox" name ="box3" group ="checkbox">
<select name="select1">
<option value="0">0</option>
<option value="1">1</option>
</select>
</form>


<script>
function get(){
// get value of selected checkbox
//取得checkbox被选中的项目

// 用,连接各个值
var check = jQuery('[group ="checkbox"]:checked').map(function(){
Return jQuery(this).val();
}).get().join(',');


jQuery('[group ="checkbox"]').each(function(I){
Var count = i + 1;
var check2=jQuery('[name="box'+count+'"]').map(function(){return count;}).get();
}
}
</script>

2016/11/09

When img failed show others|无法取得img时显示其他图片

Use onerror to show other img:
使用onerror来实现:
<img src="invaild path" onerror="script">

Ex./例:
<img src="invaild path" onerror="this.scr='right.img';">

Replace invaild img with right.img
图片不存在时,将图片替换成图片right.img

Or by jQuery/或者使用
<img src="invaild path" id="image">
<script>
$("#image").error().attr("src","right.img");
</script>

2016/09/26

Make higher color codes in blogger by [highlight.js].

When I write codes in blogger, I want to make higher color with code likes eclipse or Sublime Text. So I try to use highlight.js in blogger.

As google drive is stop hosting file for website, it turns to copy&paste code in blogger template or use a prebuilt version of highlight.js hosted by CDNs.

Copy and paste the code below inside of <head></head> in blogger template. (Before you edit your template, it's better to make a backup)
<link href='https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/styles/default.min.css' rel='stylesheet'/>
<script src='https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/highlight.min.js'/>
<script>hljs.initHighlightingOnLoad();</script>

Then, just need to put the codes inside tag <pre><code>...</code></pre>. (You need to edit in HTML mode)

Check the example site: SFDC