-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.xml
498 lines (485 loc) · 119 KB
/
search.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title><![CDATA[hexo引用自定义js文件和css样式]]></title>
<url>https://longhaoteng.github.io/2016/08/01/hexo%E5%BC%95%E7%94%A8%E8%87%AA%E5%AE%9A%E4%B9%89js%E6%96%87%E4%BB%B6%E5%92%8Ccss%E6%A0%B7%E5%BC%8F/</url>
<content type="html"><![CDATA[<p>博主用的是next主题,别的主题目录结构可能不太一样,但是整个框架是一样的,生成方式是一样的,所以引用方式也是相同的</p>
<a id="more"></a>
<h4 id="添加自定义js"><a href="#添加自定义js" class="headerlink" title="添加自定义js"></a>添加自定义js</h4><ul>
<li>首先把js文件放在<code>\themes\next\source\js\src</code>文件目录下</li>
</ul>
<p><img src="/2016/08/01/hexo引用自定义js文件和css样式/2016-08-01_231029.jpg" alt=""></p>
<ul>
<li>然后找到<code>\themes\next\layout</code>目录下的布局文件</li>
</ul>
<p><img src="/2016/08/01/hexo引用自定义js文件和css样式/2016-08-01_230833.jpg" alt=""></p>
<p><img src="/2016/08/01/hexo引用自定义js文件和css样式/2016-08-01_232149.jpg" alt=""></p>
<ul>
<li>把script引用代码加入到该文件中即可</li>
</ul>
<p><code><script type="text/javascript" src="/js/src/js文件名.js"></script></code></p>
<p><img src="/2016/08/01/hexo引用自定义js文件和css样式/2016-08-01_232729.jpg" alt=""></p>
<h4 id="添加自定义css样式"><a href="#添加自定义css样式" class="headerlink" title="添加自定义css样式"></a>添加自定义css样式</h4><ul>
<li><p>添加外部css样式目的无非是想改变主题默认标签属性,可以使用浏览器的开发者或者检查功能找到相应id选择器名称或者class选择器名称,然后进行修改,这里注意在属性后面一定要加上<code>!important</code></p>
</li>
<li><p>同理,添加外部css样式和引用自定义js代码是一样的,在对应css文件夹内添加自定义外部css样式文件,然后在layout文件中添加引用即可</p>
</li>
</ul>
]]></content>
</entry>
<entry>
<title><![CDATA[Oracle常用sql语句]]></title>
<url>https://longhaoteng.github.io/2016/07/13/Oracle%E5%B8%B8%E7%94%A8sql%E8%AF%AD%E5%8F%A5/</url>
<content type="html"><![CDATA[<p>Sql(structured query language) 结构化查询语言。</p>
<p>Sql语句主要包括DQL,DML,DDL,DCL和TCL。</p>
<p>DQL是数据查询语言:SELECT,用于查询数据。</p>
<p>DML(data manipulation language)是数据操作语言:它们是UPDATE、INSERT、DELETE,MERGE就象它的名字一样,这4条命令是用来对数据库里的数据进行操作的语言。</p>
<p>DDL(data definition language)是数据定义语言:DDL比DML要多,主要的命令有CREATE、ALTER、DROP、TRUNCATE、RENAME、COMMENT等,DDL主要是用在定义或改变表(TABLE)的结构,数据类型,表之间的链接和约束等初始化工作上,他们大多在建立表时使用。</p>
<p>DCL(Data Control Language)是数据库控制语言:是用来设置或更改数据库用户或角色权限的语句,包括(grant,deny,revoke等)语句。</p>
<p>TCL是事务控制语言:包括(COMMIT、ROLLBACK、SAVEPOINT),对事务进行控制。</p>
<a id="more"></a>
<h3 id="创建"><a href="#创建" class="headerlink" title="创建"></a>创建</h3><ul>
<li><h4 id="创建表"><a href="#创建表" class="headerlink" title="创建表"></a>创建表</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">create</span> <span class="keyword">table</span> 表名(</div><div class="line"> 列名 数据类型(大小),</div><div class="line"> 列名 数据类型(大小),</div><div class="line"> 列名 数据类型(大小)</div><div class="line"> <span class="comment">--所属表空间</span></div><div class="line"> <span class="keyword">tablespace</span> 表空间;</div><div class="line">);</div></pre></td></tr></table></figure>
</li>
<li><h4 id="创建保存点"><a href="#创建保存点" class="headerlink" title="创建保存点"></a>创建保存点</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">savepoint</span> 保存点名字;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="回滚保存点"><a href="#回滚保存点" class="headerlink" title="回滚保存点"></a>回滚保存点</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">rollback</span> <span class="keyword">to</span> 保存点名字;</div></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="增加"><a href="#增加" class="headerlink" title="增加"></a>增加</h3><ul>
<li><h4 id="向表中添加一个字段"><a href="#向表中添加一个字段" class="headerlink" title="向表中添加一个字段"></a>向表中添加一个字段</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">alter</span> <span class="keyword">table</span> 表名 <span class="keyword">add</span> (列名 数据类型,列名 数据类型);</div></pre></td></tr></table></figure>
</li>
<li><h4 id="向表中添加数据"><a href="#向表中添加数据" class="headerlink" title="向表中添加数据"></a>向表中添加数据</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">insert</span> <span class="keyword">into</span> 表名 [(列名<span class="number">1</span>,列名<span class="number">2</span>)] <span class="keyword">values</span>(值<span class="number">1</span>,值<span class="number">2</span>);</div></pre></td></tr></table></figure>
</li>
<li><h4 id="指定列名添加数据"><a href="#指定列名添加数据" class="headerlink" title="指定列名添加数据"></a>指定列名添加数据</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">insert</span> <span class="keyword">into</span> 表名 (列名<span class="number">1</span>,列名<span class="number">2</span>) <span class="keyword">values</span>(值<span class="number">1</span>,值<span class="number">2</span>);</div></pre></td></tr></table></figure>
</li>
<li><h4 id="默认列名添加数据(不可省略)"><a href="#默认列名添加数据(不可省略)" class="headerlink" title="默认列名添加数据(不可省略)"></a>默认列名添加数据(不可省略)</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">insert</span> <span class="keyword">into</span> 表名 <span class="keyword">values</span>(值<span class="number">1</span>,值<span class="number">2</span>);</div></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="删除"><a href="#删除" class="headerlink" title="删除"></a>删除</h3><ul>
<li><h4 id="删除表结构-不产生事务,不能回滚"><a href="#删除表结构-不产生事务,不能回滚" class="headerlink" title="删除表结构(不产生事务,不能回滚)"></a>删除表结构(不产生事务,不能回滚)</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">drop</span> <span class="keyword">table</span> 表名;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="删除表中字段"><a href="#删除表中字段" class="headerlink" title="删除表中字段"></a>删除表中字段</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">alter</span> <span class="keyword">table</span> 表名 <span class="keyword">drop</span> <span class="keyword">column</span> 列名;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="删除表中的数据"><a href="#删除表中的数据" class="headerlink" title="删除表中的数据"></a>删除表中的数据</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">delete</span> <span class="keyword">from</span> 表名 [<span class="keyword">where</span> 列名=值];</div></pre></td></tr></table></figure>
</li>
<li><h4 id="删除表数据-不产生事务,速度极快,不能回滚,不写日志"><a href="#删除表数据-不产生事务,速度极快,不能回滚,不写日志" class="headerlink" title="删除表数据(不产生事务,速度极快,不能回滚,不写日志)"></a>删除表数据(不产生事务,速度极快,不能回滚,不写日志)</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">truncate</span> <span class="keyword">table</span> 表名;</div></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="修改"><a href="#修改" class="headerlink" title="修改"></a>修改</h3><ul>
<li><h4 id="修改表名"><a href="#修改表名" class="headerlink" title="修改表名"></a>修改表名</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">rename</span> 旧表名 <span class="keyword">to</span> 新表名;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="修改表中字段的长度-或者改变数据类型"><a href="#修改表中字段的长度-或者改变数据类型" class="headerlink" title="修改表中字段的长度,或者改变数据类型"></a>修改表中字段的长度,或者改变数据类型</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">alter</span> <span class="keyword">table</span> 表名 <span class="keyword">modify</span>(字段名 数据类型,字段名 数据类型);</div></pre></td></tr></table></figure>
</li>
<li><h4 id="修改表中数据"><a href="#修改表中数据" class="headerlink" title="修改表中数据"></a>修改表中数据</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">update</span> 表名 <span class="keyword">set</span> 字段名=值 <span class="keyword">where</span> 字段名=值</div></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="索引"><a href="#索引" class="headerlink" title="索引"></a>索引</h3><ul>
<li><h4 id="增加索引"><a href="#增加索引" class="headerlink" title="增加索引"></a>增加索引</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">create</span> <span class="keyword">index</span> 索引名 <span class="keyword">on</span> 表名(字段名<span class="number">01</span>,字段名<span class="number">02.</span>.)</div><div class="line"><span class="keyword">tablespace</span> 表空间名;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="增加唯一索引"><a href="#增加唯一索引" class="headerlink" title="增加唯一索引"></a>增加唯一索引</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">create</span> <span class="keyword">union</span> <span class="keyword">index</span> 索引名 <span class="keyword">on</span> 表名(字段名<span class="number">01</span>,字段名<span class="number">02.</span>.)</div><div class="line"><span class="keyword">tablespace</span> 表空间名;</div></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="拷贝表"><a href="#拷贝表" class="headerlink" title="拷贝表"></a>拷贝表</h3><ul>
<li><h4 id="拷贝表结构"><a href="#拷贝表结构" class="headerlink" title="拷贝表结构"></a>拷贝表结构</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">create</span> <span class="keyword">table</span> 新表 <span class="keyword">as</span> <span class="keyword">select</span> * <span class="keyword">from</span> 旧表;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="拷贝表数据"><a href="#拷贝表数据" class="headerlink" title="拷贝表数据"></a>拷贝表数据</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">insert</span> <span class="keyword">into</span> 新表 <span class="keyword">select</span> * <span class="keyword">from</span> 旧表;</div></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="查询"><a href="#查询" class="headerlink" title="查询"></a>查询</h3><ul>
<li><h4 id="查询表"><a href="#查询表" class="headerlink" title="查询表"></a>查询表</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> * <span class="keyword">from</span> 表名;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="查看表结构"><a href="#查看表结构" class="headerlink" title="查看表结构"></a>查看表结构</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">desc 表名;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="编辑表结构"><a href="#编辑表结构" class="headerlink" title="编辑表结构"></a>编辑表结构</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">edit 表名;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="查询表数据"><a href="#查询表数据" class="headerlink" title="查询表数据"></a>查询表数据</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> 列名(*号为通配符,代表所有的列) <span class="keyword">from</span> [<span class="keyword">where</span> 列名<span class="number">1</span>=值<span class="number">1</span> <span class="keyword">and</span> 列名<span class="number">2</span>=值<span class="number">2</span>];</div></pre></td></tr></table></figure>
</li>
<li><h4 id="查询多条件均满足的数据"><a href="#查询多条件均满足的数据" class="headerlink" title="查询多条件均满足的数据"></a>查询多条件均满足的数据</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> * <span class="keyword">from</span> 表名 <span class="keyword">where</span> 列名<span class="number">1</span>=值<span class="number">1</span> <span class="keyword">and</span> 列名<span class="number">2</span>=值<span class="number">2</span>;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="查询多条件满足其一的数据"><a href="#查询多条件满足其一的数据" class="headerlink" title="查询多条件满足其一的数据"></a>查询多条件满足其一的数据</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> * <span class="keyword">from</span> 表名 <span class="keyword">where</span> 列名<span class="number">1</span>=值<span class="number">1</span> <span class="keyword">or</span> 列名<span class="number">2</span>=值<span class="number">2</span>;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="查询列名除某些值外的数据"><a href="#查询列名除某些值外的数据" class="headerlink" title="查询列名除某些值外的数据"></a>查询列名除某些值外的数据</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> * <span class="keyword">from</span> 表名 <span class="keyword">where</span> 列名 <span class="keyword">not</span> <span class="keyword">in</span>(值<span class="number">1</span>,值<span class="number">2</span>,值<span class="number">3</span>);</div></pre></td></tr></table></figure>
</li>
<li><h4 id="查询列名不为空的数据"><a href="#查询列名不为空的数据" class="headerlink" title="查询列名不为空的数据"></a>查询列名不为空的数据</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> * <span class="keyword">from</span> 表名 <span class="keyword">where</span> 列名 <span class="keyword">is</span> <span class="keyword">not</span> <span class="literal">null</span>;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="查询列名指定范围值得数据"><a href="#查询列名指定范围值得数据" class="headerlink" title="查询列名指定范围值得数据"></a>查询列名指定范围值得数据</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> * <span class="keyword">from</span> 表名 <span class="keyword">where</span> 列名[>,=,<,<=,>=]值;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="查询指定列名数据"><a href="#查询指定列名数据" class="headerlink" title="查询指定列名数据"></a>查询指定列名数据</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> 列名<span class="number">1</span>,列名<span class="number">2</span> <span class="keyword">from</span> 表名;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="模糊查询-忽略多个字符,-忽略单个字符"><a href="#模糊查询-忽略多个字符,-忽略单个字符" class="headerlink" title="模糊查询(%忽略多个字符,_忽略单个字符)"></a>模糊查询(%忽略多个字符,_忽略单个字符)</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> * <span class="keyword">from</span> 表名 <span class="keyword">where</span> 列名=<span class="string">'%'</span>;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="去除重复的数据-distinct"><a href="#去除重复的数据-distinct" class="headerlink" title="去除重复的数据(distinct)"></a>去除重复的数据(distinct)</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> <span class="keyword">distinct</span> 列名 <span class="keyword">from</span> 表名;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="升序查询"><a href="#升序查询" class="headerlink" title="升序查询"></a>升序查询</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> * <span class="keyword">from</span> 表名 <span class="keyword">order</span> <span class="keyword">by</span> 列名 <span class="keyword">asc</span>;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="降序查询"><a href="#降序查询" class="headerlink" title="降序查询"></a>降序查询</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> * <span class="keyword">from</span> 表名 <span class="keyword">order</span> <span class="keyword">by</span> 列名 <span class="keyword">desc</span>;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="使用列的别名查询显示"><a href="#使用列的别名查询显示" class="headerlink" title="使用列的别名查询显示"></a>使用列的别名查询显示</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> 列名<span class="number">1</span> <span class="string">"别名1"</span>,列名<span class="number">2</span> <span class="keyword">as</span> <span class="string">"别名2"</span> <span class="keyword">from</span> 表名;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="查询最高-max-与最低-min"><a href="#查询最高-max-与最低-min" class="headerlink" title="查询最高(max)与最低(min)"></a>查询最高(max)与最低(min)</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> <span class="keyword">max</span>(列名),<span class="keyword">min</span>(列名) <span class="keyword">from</span> 表名;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="查询平均值-avg"><a href="#查询平均值-avg" class="headerlink" title="查询平均值(avg)"></a>查询平均值(avg)</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> <span class="keyword">avg</span>(列名) <span class="keyword">from</span> 表名;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="查询总和-sum"><a href="#查询总和-sum" class="headerlink" title="查询总和(sum)"></a>查询总和(sum)</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> <span class="keyword">sum</span>(列名) <span class="keyword">from</span> 表名;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="统计-count"><a href="#统计-count" class="headerlink" title="统计(count)"></a>统计(count)</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> <span class="keyword">sum</span>(列名) 总和, <span class="keyword">count</span>(*) 总人数 <span class="keyword">from</span> 表名;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="查询所有表"><a href="#查询所有表" class="headerlink" title="查询所有表"></a>查询所有表</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> * <span class="keyword">from</span> all_tables;</div></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="分页查询"><a href="#分页查询" class="headerlink" title="分页查询"></a>分页查询</h3><ul>
<li><h4 id="分页"><a href="#分页" class="headerlink" title="分页"></a>分页</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> * <span class="keyword">from</span> (<span class="keyword">select</span> a.*, <span class="keyword">rownum</span> rn <span class="keyword">from</span> 表名 a <span class="keyword">where</span> <span class="keyword">rownum</span><=[<span class="keyword">end</span>]) <span class="keyword">where</span> rn>[<span class="keyword">start</span>];</div><div class="line"><span class="comment">-- start = (当前页数-1)*单页显示条数</span></div><div class="line"><span class="comment">-- end = 当前页数*单页显示条数</span></div></pre></td></tr></table></figure>
</li>
<li><h4 id="总页数"><a href="#总页数" class="headerlink" title="总页数"></a>总页数</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> <span class="keyword">ceil</span>(<span class="keyword">count</span>(*)/单页显示条数) ct <span class="keyword">from</span> t_user;</div></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="多表查询"><a href="#多表查询" class="headerlink" title="多表查询"></a>多表查询</h3><ul>
<li><h4 id="所有同名列连接"><a href="#所有同名列连接" class="headerlink" title="所有同名列连接"></a>所有同名列连接</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> * <span class="keyword">from</span> 表<span class="number">1</span> <span class="keyword">natural</span> <span class="keyword">join</span> 表<span class="number">2</span>;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="指定同名列连接"><a href="#指定同名列连接" class="headerlink" title="指定同名列连接"></a>指定同名列连接</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> * <span class="keyword">from</span> 表<span class="number">1</span> <span class="keyword">join</span> 表<span class="number">2</span> <span class="keyword">using</span>(相同列);</div></pre></td></tr></table></figure>
</li>
<li><h4 id="指定任意连接条件"><a href="#指定任意连接条件" class="headerlink" title="指定任意连接条件"></a>指定任意连接条件</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> * <span class="keyword">from</span> 表<span class="number">1</span> <span class="keyword">join</span> 表<span class="number">2</span> <span class="keyword">on</span> 表<span class="number">1</span>列 = 表<span class="number">2</span>列(与表<span class="number">1</span>相同列。语法:表.列);</div></pre></td></tr></table></figure>
</li>
<li><h4 id="不等连接"><a href="#不等连接" class="headerlink" title="不等连接"></a>不等连接</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> * <span class="keyword">from</span> 表<span class="number">1</span> <span class="keyword">join</span> 表<span class="number">2</span> <span class="keyword">on</span> 列 <span class="keyword">between</span> 列(表<span class="number">1</span>) <span class="keyword">and</span> 列(表<span class="number">2</span>);</div></pre></td></tr></table></figure>
</li>
<li><h4 id="自连接"><a href="#自连接" class="headerlink" title="自连接"></a>自连接</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> 别名<span class="number">1.</span>列,别名<span class="number">2.</span>列 <span class="keyword">from</span> 表 别名<span class="number">1</span> <span class="keyword">join</span> 表 别名<span class="number">2</span> <span class="keyword">on</span> 别名<span class="number">1.</span>列<span class="number">1</span> = 别名<span class="number">2.</span>列<span class="number">2</span>;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="外部左连接"><a href="#外部左连接" class="headerlink" title="外部左连接"></a>外部左连接</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> * <span class="keyword">from</span> 表<span class="number">1</span> <span class="keyword">left</span> <span class="keyword">outer</span> <span class="keyword">join</span> 表<span class="number">2</span> <span class="keyword">on</span> 表<span class="number">1.</span>列 = 表<span class="number">2.</span>列;</div><div class="line"><span class="keyword">select</span> * <span class="keyword">from</span> 表<span class="number">1</span>,表<span class="number">2</span> <span class="keyword">where</span> 表<span class="number">1.</span>列(+) = 表<span class="number">2.</span>列;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="外部右连接"><a href="#外部右连接" class="headerlink" title="外部右连接"></a>外部右连接</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> * <span class="keyword">from</span> 表<span class="number">1</span> <span class="keyword">right</span> <span class="keyword">outer</span> <span class="keyword">join</span> 表<span class="number">2</span> <span class="keyword">on</span> 表<span class="number">1.</span>列 = 表<span class="number">2.</span>列;</div><div class="line"><span class="keyword">select</span> * <span class="keyword">from</span> 表<span class="number">1</span>,表<span class="number">2</span> <span class="keyword">where</span> 表<span class="number">1.</span>列 = 表<span class="number">2.</span>列(+);</div></pre></td></tr></table></figure>
</li>
<li><h4 id="完全外部连接"><a href="#完全外部连接" class="headerlink" title="完全外部连接"></a>完全外部连接</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> * <span class="keyword">from</span> 表<span class="number">1</span> <span class="keyword">full</span> <span class="keyword">outer</span> <span class="keyword">join</span> 表<span class="number">2</span> <span class="keyword">on</span> 表<span class="number">1.</span>列 = 表<span class="number">2.</span>列;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="多表连接"><a href="#多表连接" class="headerlink" title="多表连接"></a>多表连接</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> * <span class="keyword">from</span> 表<span class="number">1</span> <span class="keyword">join</span> 表<span class="number">2</span> <span class="keyword">on</span> 表<span class="number">1.</span>列 = 表<span class="number">2.</span>列 <span class="keyword">join</span> 表<span class="number">3</span> <span class="keyword">on</span> 表<span class="number">1.</span>列 = 表<span class="number">3.</span>列;</div></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="同义词"><a href="#同义词" class="headerlink" title="同义词"></a>同义词</h3><ul>
<li><h4 id="新建同义词"><a href="#新建同义词" class="headerlink" title="新建同义词"></a>新建同义词</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="comment">--例:建立scott用户emp表同义词</span></div><div class="line"><span class="keyword">create</span> <span class="keyword">public</span> <span class="keyword">synonym</span> emp <span class="keyword">for</span> scott.emp;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="删除同义词"><a href="#删除同义词" class="headerlink" title="删除同义词"></a>删除同义词</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">drop</span> <span class="keyword">public</span> <span class="keyword">synonym</span> 同义词名;</div></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="表分区"><a href="#表分区" class="headerlink" title="表分区"></a>表分区</h3><ul>
<li><h4 id="新建表分区"><a href="#新建表分区" class="headerlink" title="新建表分区"></a>新建表分区</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div></pre></td><td class="code"><pre><div class="line"><span class="comment">--例表user_info_t</span></div><div class="line"><span class="keyword">create</span> <span class="keyword">table</span> user_info_t(</div><div class="line">city_code <span class="built_in">number</span>,</div><div class="line">user_id <span class="built_in">number</span>(<span class="number">10</span>)</div><div class="line">)<span class="keyword">tablespace</span> <span class="keyword">users</span></div><div class="line"><span class="keyword">Partition</span> <span class="keyword">by</span> <span class="keyword">range</span>(city_code)</div><div class="line">(<span class="keyword">partition</span> part_740 <span class="keyword">values</span> <span class="keyword">less</span> <span class="keyword">than</span>(<span class="string">'750'</span>)</div><div class="line"><span class="keyword">tablespace</span> <span class="keyword">users</span>,</div><div class="line"><span class="keyword">partition</span> part_750 <span class="keyword">values</span> <span class="keyword">less</span> <span class="keyword">than</span>(<span class="string">'751'</span>)</div><div class="line"><span class="keyword">tablespace</span> <span class="keyword">users</span>,</div><div class="line"><span class="keyword">partition</span> part_751 <span class="keyword">values</span> <span class="keyword">less</span> <span class="keyword">than</span>(<span class="string">'752'</span>)</div><div class="line"><span class="keyword">tablespace</span> <span class="keyword">users</span></div><div class="line"><span class="comment">--不在分区内可存储在part_max分区中</span></div><div class="line"><span class="comment">--partition part_max values less than(maxvalue)</span></div><div class="line"><span class="comment">--tablespace users</span></div><div class="line">)</div></pre></td></tr></table></figure>
</li>
<li><h4 id="分区查询"><a href="#分区查询" class="headerlink" title="分区查询"></a>分区查询</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> * <span class="keyword">from</span> user_info_t</div><div class="line"><span class="keyword">where</span> city_code=<span class="string">'740'</span>;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="添加分区"><a href="#添加分区" class="headerlink" title="添加分区"></a>添加分区</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">alter</span> <span class="keyword">table</span> user_info_t <span class="keyword">add</span> <span class="keyword">partition</span> part_752;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="分区删除数据"><a href="#分区删除数据" class="headerlink" title="分区删除数据"></a>分区删除数据</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">alter</span> <span class="keyword">table</span> user_info_t <span class="keyword">truncate</span> <span class="keyword">partition</span> part_740;</div></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="函数"><a href="#函数" class="headerlink" title="函数"></a>函数</h3><ul>
<li><h3 id="单行函数"><a href="#单行函数" class="headerlink" title="单行函数"></a>单行函数</h3></li>
<li><h4 id="所有字符转换为小写"><a href="#所有字符转换为小写" class="headerlink" title="所有字符转换为小写"></a>所有字符转换为小写</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> <span class="keyword">lower</span>(<span class="string">'HeLLo'</span>) <span class="keyword">from</span> dual;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="所有字符转换为大写"><a href="#所有字符转换为大写" class="headerlink" title="所有字符转换为大写"></a>所有字符转换为大写</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> <span class="keyword">upper</span>(<span class="string">'HelLO'</span>) <span class="keyword">from</span> dual;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="首字母大写"><a href="#首字母大写" class="headerlink" title="首字母大写"></a>首字母大写</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> initcap(<span class="string">'HeLLo'</span>) <span class="keyword">from</span> dual;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="去除指定字符"><a href="#去除指定字符" class="headerlink" title="去除指定字符"></a>去除指定字符</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> <span class="keyword">trim</span>(<span class="string">'H'</span> <span class="keyword">from</span> <span class="string">'HHellohHH'</span>) <span class="keyword">from</span> dual;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="从字符串首去除指定字符"><a href="#从字符串首去除指定字符" class="headerlink" title="从字符串首去除指定字符"></a>从字符串首去除指定字符</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> <span class="keyword">ltrim</span>(<span class="string">'HHellohHH'</span>, <span class="string">'H'</span>) <span class="keyword">from</span> dual;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="从字符串尾去除指定字符"><a href="#从字符串尾去除指定字符" class="headerlink" title="从字符串尾去除指定字符"></a>从字符串尾去除指定字符</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> <span class="keyword">rtrim</span>(<span class="string">'HelLO'</span>) <span class="keyword">from</span> dual;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="显示指定位数,不足用指定字符补全,数值首补全"><a href="#显示指定位数,不足用指定字符补全,数值首补全" class="headerlink" title="显示指定位数,不足用指定字符补全,数值首补全"></a>显示指定位数,不足用指定字符补全,数值首补全</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> <span class="keyword">lpad</span>(<span class="number">1000</span>, <span class="number">7</span>, <span class="string">'*'</span>) <span class="keyword">from</span> dual;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="显示指定位数,不足用指定字符补全,数值尾补全"><a href="#显示指定位数,不足用指定字符补全,数值尾补全" class="headerlink" title="显示指定位数,不足用指定字符补全,数值尾补全"></a>显示指定位数,不足用指定字符补全,数值尾补全</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> rpad(<span class="string">'HelLO'</span>) <span class="keyword">from</span> dual;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="查询指定字符在字符串中第一次出现下标"><a href="#查询指定字符在字符串中第一次出现下标" class="headerlink" title="查询指定字符在字符串中第一次出现下标"></a>查询指定字符在字符串中第一次出现下标</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> <span class="keyword">instr</span>(<span class="string">'hello world'</span>, <span class="string">'world'</span>) <span class="keyword">from</span> dual;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="截取指定下标范围"><a href="#截取指定下标范围" class="headerlink" title="截取指定下标范围"></a>截取指定下标范围</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> <span class="keyword">substr</span>(<span class="string">'hello world'</span>, <span class="number">7</span>, <span class="number">5</span>) <span class="keyword">from</span> dual;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="字符连接"><a href="#字符连接" class="headerlink" title="字符连接"></a>字符连接</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> <span class="keyword">concat</span>(<span class="string">'hello '</span>, <span class="string">'world'</span>) <span class="keyword">from</span> dual;</div></pre></td></tr></table></figure>
</li>
<li><h4 id="字符替换"><a href="#字符替换" class="headerlink" title="字符替换"></a>字符替换</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">select</span> <span class="keyword">replace</span>(<span class="string">'helloh'</span>,<span class="string">'h'</span>,<span class="string">'x'</span>) <span class="keyword">from</span> dual;</div></pre></td></tr></table></figure>
</li>
<li><h3 id="多行函数"><a href="#多行函数" class="headerlink" title="多行函数"></a>多行函数</h3></li>
<li><h4 id="求和"><a href="#求和" class="headerlink" title="求和"></a>求和</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">sum()</div></pre></td></tr></table></figure>
</li>
<li><h4 id="求平均值"><a href="#求平均值" class="headerlink" title="求平均值"></a>求平均值</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">avg()</div></pre></td></tr></table></figure>
</li>
<li><h4 id="计数"><a href="#计数" class="headerlink" title="计数"></a>计数</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">count()</div></pre></td></tr></table></figure>
</li>
<li><h4 id="求最大值"><a href="#求最大值" class="headerlink" title="求最大值"></a>求最大值</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">max()</div></pre></td></tr></table></figure>
</li>
<li><h4 id="求最小值"><a href="#求最小值" class="headerlink" title="求最小值"></a>求最小值</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">min()</div></pre></td></tr></table></figure>
</li>
<li><h3 id="转换函数"><a href="#转换函数" class="headerlink" title="转换函数"></a>转换函数</h3></li>
<li><h4 id="转换成字符串类型"><a href="#转换成字符串类型" class="headerlink" title="转换成字符串类型"></a>转换成字符串类型</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">to_char()</div><div class="line"><span class="comment">-- 示例:to_char(1234.5, '$9999.9')</span></div></pre></td></tr></table></figure>
</li>
<li><h4 id="转换成日期类型"><a href="#转换成日期类型" class="headerlink" title="转换成日期类型"></a>转换成日期类型</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">to_date()</div><div class="line"><span class="comment">-- 示例:to_date('1949-01-01','yyyy-mm-dd')</span></div></pre></td></tr></table></figure>
</li>
<li><h4 id="转换成数值类型"><a href="#转换成数值类型" class="headerlink" title="转换成数值类型"></a>转换成数值类型</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">to_number()</div><div class="line"><span class="comment">-- 示例:to_number('1234.5')</span></div></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="序列"><a href="#序列" class="headerlink" title="序列"></a>序列</h3><ul>
<li><h4 id="添加序列"><a href="#添加序列" class="headerlink" title="添加序列"></a>添加序列</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">create</span> <span class="keyword">sequence</span> 序列名</div><div class="line"><span class="keyword">start</span> <span class="keyword">with</span> <span class="number">1</span> <span class="comment">--开始值</span></div><div class="line"><span class="keyword">minvalue</span> <span class="number">1</span> <span class="comment">--最小值</span></div><div class="line">maxvalue <span class="number">999</span> <span class="comment">--最大值</span></div><div class="line"><span class="keyword">increment</span> <span class="keyword">by</span> <span class="number">1</span>; <span class="comment">--增值</span></div></pre></td></tr></table></figure>
</li>
<li><h4 id="删除序列"><a href="#删除序列" class="headerlink" title="删除序列"></a>删除序列</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">drop</span> <span class="keyword">sequence</span> 序列名</div></pre></td></tr></table></figure>
</li>
<li><h4 id="修改序列"><a href="#修改序列" class="headerlink" title="修改序列"></a>修改序列</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">alter</span> <span class="keyword">sequence</span> 序列名 修改的属性 属性值</div></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="添加主键外键约束"><a href="#添加主键外键约束" class="headerlink" title="添加主键外键约束"></a>添加主键外键约束</h3><ul>
<li><h4 id="主键约束"><a href="#主键约束" class="headerlink" title="主键约束"></a>主键约束</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">alter</span> <span class="keyword">table</span> 表名</div><div class="line"><span class="keyword">add</span> <span class="keyword">constraint</span> PK_字段名<span class="comment">--"PK"为主键的缩写,字段名为要在其上创建主键的字段名,'PK_字段名'就为约束名</span></div><div class="line">primary <span class="keyword">key</span> (字段名) <span class="comment">--字段名同上</span></div></pre></td></tr></table></figure>
</li>
<li><h4 id="外键约束"><a href="#外键约束" class="headerlink" title="外键约束"></a>外键约束</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">alter</span> <span class="keyword">table</span> 表名</div><div class="line"><span class="keyword">add</span> <span class="keyword">constraint</span> FK_字段名<span class="comment">--"FK"为外键的缩写</span></div><div class="line">foreign <span class="keyword">key</span> (字段名) <span class="keyword">references</span> 关联的表名(关联的字段名) <span class="comment">--注意'关联的表名'和'关联的字段名'</span></div></pre></td></tr></table></figure>
</li>
<li><h4 id="唯一约束"><a href="#唯一约束" class="headerlink" title="唯一约束"></a>唯一约束</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">alter</span> <span class="keyword">table</span> 表名</div><div class="line"><span class="keyword">add</span> <span class="keyword">constraint</span> UQ_字段名</div><div class="line"><span class="keyword">unique</span> (字段名)</div></pre></td></tr></table></figure>
</li>
<li><h4 id="检查约束"><a href="#检查约束" class="headerlink" title="检查约束"></a>检查约束</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">alter</span> <span class="keyword">table</span> 表名</div><div class="line"><span class="keyword">add</span> <span class="keyword">constraint</span> CK_字段名</div><div class="line"><span class="keyword">check</span> (条件表达式) <span class="comment">--条件表达式中的条件用关系运算符连接</span></div></pre></td></tr></table></figure>
</li>
<li><h4 id="默认值约束"><a href="#默认值约束" class="headerlink" title="默认值约束"></a>默认值约束</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">alter</span> <span class="keyword">table</span> 表名</div><div class="line"><span class="keyword">add</span> <span class="keyword">constraint</span> DF_字段名</div><div class="line"><span class="keyword">default</span> <span class="string">'默认值'</span> <span class="keyword">for</span> 字段名<span class="comment">--其中的'默认值'为你想要默认的值,注意'for'</span></div></pre></td></tr></table></figure>
</li>
<li><h4 id="删除创建的约束"><a href="#删除创建的约束" class="headerlink" title="删除创建的约束"></a>删除创建的约束</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">alter</span> <span class="keyword">table</span> 表名</div><div class="line"><span class="keyword">drop</span> <span class="keyword">constraint</span> 约束名<span class="comment">--约束名为你前面创建的如:PK_字段这样的约束名</span></div><div class="line"><span class="comment">--注意:如果约束是在创建表的时候创建的,则不能用命令删除</span></div></pre></td></tr></table></figure>
</li>
</ul>
<h3 id="提交"><a href="#提交" class="headerlink" title="提交"></a>提交</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">commit</span>;</div></pre></td></tr></table></figure>
<h3 id="回滚"><a href="#回滚" class="headerlink" title="回滚"></a>回滚</h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">rollback</span>;</div></pre></td></tr></table></figure>
<h3 id="符号"><a href="#符号" class="headerlink" title="符号"></a>符号</h3><ul>
<li><h4 id="连接符号"><a href="#连接符号" class="headerlink" title="连接符号"></a>连接符号</h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">||</div></pre></td></tr></table></figure>
</li>
<li><h4 id="逻辑运算符"><a href="#逻辑运算符" class="headerlink" title="逻辑运算符"></a>逻辑运算符</h4><figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">大于:>,小于:<,等于:=,不等于:<>、!=</div></pre></td></tr></table></figure>
</li>
</ul>
]]></content>
</entry>
<entry>
<title><![CDATA[Pycharm自动生成编码格式和author]]></title>
<url>https://longhaoteng.github.io/2016/07/07/Pycharm%E8%87%AA%E5%8A%A8%E7%94%9F%E6%88%90%E7%BC%96%E7%A0%81%E6%A0%BC%E5%BC%8F%E5%92%8Cauthor/</url>
<content type="html"><![CDATA[<p>Pycharm自动生成编码格式和author设置..</p>
<a id="more"></a>
<h5 id="File-–-gt-Settings"><a href="#File-–-gt-Settings" class="headerlink" title="File –> Settings"></a>File –> Settings</h5><p><img src="/2016/07/07/Pycharm自动生成编码格式和author/2016-07-07_164958.jpg" alt=""></p>
<h5 id="Editor-–-gt-File-and-Code-Templates-–-gt-Python-Script"><a href="#Editor-–-gt-File-and-Code-Templates-–-gt-Python-Script" class="headerlink" title="Editor –> File and Code Templates –> Python Script"></a>Editor –> File and Code Templates –> Python Script</h5><figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#!/usr/bin/env python3</span></div><div class="line"><span class="comment"># coding=utf-8</span></div><div class="line">__author__ = <span class="string">'$USER'</span></div></pre></td></tr></table></figure>
<p><code>#!/usr/bin/env python3</code></p>
<p>取得权限的情况下在Mac和Linux上直接运行</p>
<p><code># coding=utf-8</code></p>
<p>编码格式</p>
<p><code>__author__ = '$USER'</code></p>
<p>作者</p>
<p><img src="/2016/07/07/Pycharm自动生成编码格式和author/2016-07-07_162430.jpg" alt=""></p>
<h5 id="保存后重启Pycharm"><a href="#保存后重启Pycharm" class="headerlink" title="保存后重启Pycharm"></a>保存后重启Pycharm</h5><p>新建个py文件看看效果</p>
<p><img src="/2016/07/07/Pycharm自动生成编码格式和author/2016-07-07_162554.jpg" alt=""></p>
]]></content>
</entry>
<entry>
<title><![CDATA[git常用命令]]></title>
<url>https://longhaoteng.github.io/2016/07/06/git%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/</url>
<content type="html"><![CDATA[<p>整理了下Git常用的基本命令,便于忘记的时候查询</p>
<a id="more"></a>
<h4 id="创建仓库"><a href="#创建仓库" class="headerlink" title="创建仓库"></a>创建仓库</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git init</div></pre></td></tr></table></figure>
<h4 id="查看当前目录"><a href="#查看当前目录" class="headerlink" title="查看当前目录"></a>查看当前目录</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">pwd</div></pre></td></tr></table></figure>
<h4 id="查看当前状态"><a href="#查看当前状态" class="headerlink" title="查看当前状态"></a>查看当前状态</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git status</div></pre></td></tr></table></figure>
<h4 id="添加文件"><a href="#添加文件" class="headerlink" title="添加文件"></a>添加文件</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git add file</div></pre></td></tr></table></figure>
<h4 id="提交文件"><a href="#提交文件" class="headerlink" title="提交文件"></a>提交文件</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git commit -m "description"</div></pre></td></tr></table></figure>
<h4 id="查看操作日志"><a href="#查看操作日志" class="headerlink" title="查看操作日志"></a>查看操作日志</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git log</div></pre></td></tr></table></figure>
<h4 id="查看简略操作日志"><a href="#查看简略操作日志" class="headerlink" title="查看简略操作日志"></a>查看简略操作日志</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git log --pretty=oneline</div></pre></td></tr></table></figure>
<h4 id="查看命令历史"><a href="#查看命令历史" class="headerlink" title="查看命令历史"></a>查看命令历史</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git reflog</div></pre></td></tr></table></figure>
<h4 id="版本回退-(HEAD是当前版本-是上一版本-是上上版本)"><a href="#版本回退-(HEAD是当前版本-是上一版本-是上上版本)" class="headerlink" title="版本回退 (HEAD是当前版本 ^是上一版本 ^^是上上版本)"></a>版本回退 (HEAD是当前版本 ^是上一版本 ^^是上上版本)</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git reset --hard HEAD^</div></pre></td></tr></table></figure>
<h4 id="回退到指定id版本"><a href="#回退到指定id版本" class="headerlink" title="回退到指定id版本"></a>回退到指定id版本</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git reset --hard commit_id</div></pre></td></tr></table></figure>
<h4 id="直接丢弃工作区的修改"><a href="#直接丢弃工作区的修改" class="headerlink" title="直接丢弃工作区的修改"></a>直接丢弃工作区的修改</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git checkout --file</div></pre></td></tr></table></figure>
<h4 id="丢弃暂存区的修改"><a href="#丢弃暂存区的修改" class="headerlink" title="丢弃暂存区的修改"></a>丢弃暂存区的修改</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git reset HEAD file</div></pre></td></tr></table></figure>
<h4 id="创建远程仓库"><a href="#创建远程仓库" class="headerlink" title="创建远程仓库"></a>创建远程仓库</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ssh-keygen -t rsa -C "[email protected]"</div></pre></td></tr></table></figure>
<h4 id="链接远程仓库"><a href="#链接远程仓库" class="headerlink" title="链接远程仓库"></a>链接远程仓库</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git remote add origin [email protected]:UserExample/Repositories.git</div></pre></td></tr></table></figure>
<h4 id="第一次把所有内容推送到远程仓库"><a href="#第一次把所有内容推送到远程仓库" class="headerlink" title="第一次把所有内容推送到远程仓库"></a>第一次把所有内容推送到远程仓库</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git push -u origin master</div></pre></td></tr></table></figure>
<h4 id="把所有内容推送到远程仓库"><a href="#把所有内容推送到远程仓库" class="headerlink" title="把所有内容推送到远程仓库"></a>把所有内容推送到远程仓库</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git push origin master</div></pre></td></tr></table></figure>
<h4 id="克隆远程库到本地库"><a href="#克隆远程库到本地库" class="headerlink" title="克隆远程库到本地库"></a>克隆远程库到本地库</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git clone</div></pre></td></tr></table></figure>
<h4 id="克隆指定远程库分支"><a href="#克隆指定远程库分支" class="headerlink" title="克隆指定远程库分支"></a>克隆指定远程库分支</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git clone -b branch</div></pre></td></tr></table></figure>
<h4 id="查看分支"><a href="#查看分支" class="headerlink" title="查看分支"></a>查看分支</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git branch</div></pre></td></tr></table></figure>
<h4 id="创建分支"><a href="#创建分支" class="headerlink" title="创建分支"></a>创建分支</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git branch <name></div></pre></td></tr></table></figure>
<h4 id="切换分支"><a href="#切换分支" class="headerlink" title="切换分支"></a>切换分支</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git checkout <name></div></pre></td></tr></table></figure>
<h4 id="创建-切换分支"><a href="#创建-切换分支" class="headerlink" title="创建+切换分支"></a>创建+切换分支</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git checkout -b <name></div></pre></td></tr></table></figure>
<h4 id="合并某分支到当前分支"><a href="#合并某分支到当前分支" class="headerlink" title="合并某分支到当前分支"></a>合并某分支到当前分支</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git merge <name></div></pre></td></tr></table></figure>
<h4 id="删除分支"><a href="#删除分支" class="headerlink" title="删除分支"></a>删除分支</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git branch -d <name></div></pre></td></tr></table></figure>
<h4 id="查看分支合并图"><a href="#查看分支合并图" class="headerlink" title="查看分支合并图"></a>查看分支合并图</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git log --graph</div></pre></td></tr></table></figure>
<h4 id="“储存”现场"><a href="#“储存”现场" class="headerlink" title="“储存”现场"></a>“储存”现场</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git stash</div></pre></td></tr></table></figure>
<h4 id="“恢复”现场"><a href="#“恢复”现场" class="headerlink" title="“恢复”现场"></a>“恢复”现场</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git stash pop</div></pre></td></tr></table></figure>
<h4 id="查看远程库信息"><a href="#查看远程库信息" class="headerlink" title="查看远程库信息"></a>查看远程库信息</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git remote</div></pre></td></tr></table></figure>
<h4 id="查看详细远程库信息"><a href="#查看详细远程库信息" class="headerlink" title="查看详细远程库信息"></a>查看详细远程库信息</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git remote -v</div></pre></td></tr></table></figure>
<h4 id="添加一个新标签"><a href="#添加一个新标签" class="headerlink" title="添加一个新标签"></a>添加一个新标签</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git tag <name></div></pre></td></tr></table></figure>
<h4 id="查看所有标签"><a href="#查看所有标签" class="headerlink" title="查看所有标签"></a>查看所有标签</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git tag</div></pre></td></tr></table></figure>
<h4 id="对指定commit添加标签"><a href="#对指定commit添加标签" class="headerlink" title="对指定commit添加标签"></a>对指定commit添加标签</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git tag <name> commit_id</div></pre></td></tr></table></figure>
<h4 id="创建带有说明的标签"><a href="#创建带有说明的标签" class="headerlink" title="创建带有说明的标签"></a>创建带有说明的标签</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git tag -a <name> -m "description" commit_id</div></pre></td></tr></table></figure>
<h4 id="查看说明文字"><a href="#查看说明文字" class="headerlink" title="查看说明文字"></a>查看说明文字</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git show <tagname></div></pre></td></tr></table></figure>
<h4 id="用私钥-PGP-签名一个标签"><a href="#用私钥-PGP-签名一个标签" class="headerlink" title="用私钥(PGP)签名一个标签"></a>用私钥(PGP)签名一个标签</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git tag -s <name> -m "description" commit_id</div></pre></td></tr></table></figure>
<h4 id="推送一个本地标签"><a href="#推送一个本地标签" class="headerlink" title="推送一个本地标签"></a>推送一个本地标签</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git push origin <tagname></div></pre></td></tr></table></figure>
<h4 id="推送全部未推送过的本地标签"><a href="#推送全部未推送过的本地标签" class="headerlink" title="推送全部未推送过的本地标签"></a>推送全部未推送过的本地标签</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git push origin --tags</div></pre></td></tr></table></figure>
<h4 id="删除一个本地标签"><a href="#删除一个本地标签" class="headerlink" title="删除一个本地标签"></a>删除一个本地标签</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git tag -d <tagname></div></pre></td></tr></table></figure>
<h4 id="删除一个远程标签"><a href="#删除一个远程标签" class="headerlink" title="删除一个远程标签"></a>删除一个远程标签</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">git push origin :refs/tags/<tagname></div></pre></td></tr></table></figure>
]]></content>
</entry>
<entry>
<title><![CDATA[Python网络爬虫(Lesson Three)]]></title>
<url>https://longhaoteng.github.io/2016/07/01/Python%E7%BD%91%E7%BB%9C%E7%88%AC%E8%99%AB-Lesson-Three/</url>
<content type="html"><![CDATA[<h4 id="序言"><a href="#序言" class="headerlink" title="序言"></a>序言</h4><p>回顾一下我们现在爬虫所具有的能力,能对指定目标进行下载到本地,能爬取整个html页面,但是在爬取页面后,无法锁定需要下载的目标,所以我们要对爬取的html页面进行分析,从而锁定需爬取目标</p>
<a id="more"></a>
<h4 id="挖坑待填-…"><a href="#挖坑待填-…" class="headerlink" title="挖坑待填 ^.^…"></a>挖坑待填 ^.^…</h4>]]></content>
</entry>
<entry>
<title><![CDATA[Python网络爬虫(Lesson Second)]]></title>
<url>https://longhaoteng.github.io/2016/07/01/Python%E7%BD%91%E7%BB%9C%E7%88%AC%E8%99%AB-Lesson-Second/</url>
<content type="html"><![CDATA[<h3 id="序言"><a href="#序言" class="headerlink" title="序言"></a>序言</h3><p>上篇我们实现了Python爬虫的下载功能,最基本的功能虽然实现了,但是我们的爬虫真正工作的时候,面对的是各种不同的html,而不是如上篇那样直接传入的下载目标,所以我们需要对html网页进行分析,找到爬取目标,而在此之前,我们需要获取到整个html,才能进行下一步的分析,接下来我们来实现Html页面的爬取</p>
<a id="more"></a>
<h4 id="Html页面的爬取"><a href="#Html页面的爬取" class="headerlink" title="Html页面的爬取"></a>Html页面的爬取</h4><p>和之前一样,我们先新建.py文件</p>
<ul>
<li>新建 .py文件</li>
</ul>
<p><img src="/2016/07/01/Python网络爬虫-Lesson-Second/2016-07-01_165727.bmp" alt=""></p>
<ul>
<li>用编辑器打开写入代码</li>
</ul>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#coding:utf-8</span></div><div class="line">__author__ = <span class="string">'Mr.龙'</span></div><div class="line"></div><div class="line"><span class="keyword">import</span> urllib.request</div><div class="line"><span class="function"><span class="keyword">def</span> <span class="title">getHtml</span><span class="params">(url)</span>:</span></div><div class="line"> page=urllib.request.urlopen(url)</div><div class="line"> html=page.read()</div><div class="line"> html=html.decode(<span class="string">"utf-8"</span>)</div><div class="line"> <span class="keyword">return</span> html</div><div class="line"></div><div class="line"><span class="function"><span class="keyword">def</span> <span class="title">test</span><span class="params">()</span>:</span></div><div class="line"> html=getHtml(<span class="string">"http://www.baidu.com"</span>)</div><div class="line"> print(html)</div></pre></td></tr></table></figure>
<p>在运行之前,先来详细的理解下代码</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#coding:utf-8`</span></div><div class="line">`__author__ = <span class="string">'Mr.龙'</span></div></pre></td></tr></table></figure>
<p>代码头</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">import</span> urllib.request</div></pre></td></tr></table></figure>
<p>导入urllib模块</p>
<h6 id="第一部分,也是主要的功能实现"><a href="#第一部分,也是主要的功能实现" class="headerlink" title="第一部分,也是主要的功能实现"></a>第一部分,也是主要的功能实现</h6><figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">def</span> <span class="title">getHtml</span><span class="params">(url)</span>:</span></div></pre></td></tr></table></figure>
<p>定义一个getHtml函数,形参为url</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">page=urllib.request.urlopen(url)</div></pre></td></tr></table></figure>
<p>打开url赋值到page中</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">html=page.read()</div></pre></td></tr></table></figure>
<p>对page读取然后赋值到html中</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">html=html.decode(<span class="string">"utf-8"</span>)</div></pre></td></tr></table></figure>
<p>设置html编码格式</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">return</span> html</div></pre></td></tr></table></figure>
<p>返回html</p>
<h6 id="第二部分,调用功能函数,测试功能函数"><a href="#第二部分,调用功能函数,测试功能函数" class="headerlink" title="第二部分,调用功能函数,测试功能函数"></a>第二部分,调用功能函数,测试功能函数</h6><figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">def</span> <span class="title">test</span><span class="params">()</span>:</span></div></pre></td></tr></table></figure>
<p>定义功能函数</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">html=getHtml(<span class="string">"http://www.baidu.com"</span>)</div></pre></td></tr></table></figure>
<p>调用getHtml函数,传入百度的网址,然后赋值给html</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">print(html)</div></pre></td></tr></table></figure>
<p>最后打印html</p>
<ul>
<li>运行代码</li>
</ul>
<p>代码解读完了,我们来运行一下代码看看结果</p>
<p><img src="/2016/07/01/Python网络爬虫-Lesson-Second/2016-07-02_110141.bmp" alt=""></p>
<p>可以看到已经把百度首页的html代码打印了出来,说明我们的html爬取功能是成功的</p>
]]></content>
</entry>
<entry>
<title><![CDATA[Python网络爬虫(Lesson One)]]></title>
<url>https://longhaoteng.github.io/2016/06/30/Python%E7%BD%91%E7%BB%9C%E7%88%AC%E8%99%AB-Lesson-One/</url>
<content type="html"><![CDATA[<h3 id="序言"><a href="#序言" class="headerlink" title="序言"></a>序言</h3><p>阅读这篇文章之前,先来了解下爬虫是什么。</p>
<p>爬虫在百度百科中的解释是这样的:</p>
<blockquote>
<p>网络爬虫(又被称为网页蜘蛛,网络机器人,在FOAF社区中间,更经常的称为网页追逐者),是一种按照一定的规则,自动地抓取万维网信息的程序或者脚本。另外一些不常使用的名字还有蚂蚁、自动索引、模拟程序或者蠕虫。</p>
</blockquote>
<a id="more"></a>
<p>写爬虫不一定就要用Python,但是Python可以说是最适合写爬虫的语言。<br>所以我们的爬虫将使用Python这门语言。</p>
<p>没听过Python这门语言或者对Python这门语言不熟练的同学请先学习下Python,Python这门语言简单易学,花点时间学习后再回来继续学习爬虫吧。</p>
<p>我们先来实现爬虫中最重要也是最简单的功能,把爬取到的内容下载到本地。</p>
<h4 id="实现下载功能"><a href="#实现下载功能" class="headerlink" title="实现下载功能"></a>实现下载功能</h4><ul>
<li>新建 .py文件</li>
</ul>
<p><img src="/2016/06/30/Python网络爬虫-Lesson-One/2016-07-01_111427.bmp" alt=""></p>
<ul>
<li>用编辑器打开写入代码</li>
</ul>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#coding:utf-8</span></div><div class="line">__author__ = <span class="string">'Mr.龙'</span></div><div class="line"></div><div class="line"><span class="keyword">import</span> urllib.request</div><div class="line"></div><div class="line">result=urllib.request.urlopen(<span class="string">"http://ww4.sinaimg.cn/mw600/4bf31e43jw1ew3gd4dh6sj20u018ggza.jpg"</span>)</div><div class="line">img=result.read()</div><div class="line"><span class="keyword">with</span> open(<span class="string">"img.jpg"</span>,<span class="string">"wb"</span>) <span class="keyword">as</span> f:</div><div class="line"> f.write(img)</div></pre></td></tr></table></figure>
<p>代码很简单,逐行解释一下</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="comment">#coding:utf-8</span></div></pre></td></tr></table></figure>
<p>代码头,声明编码格式</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">__author__ = <span class="string">'Mr.龙'</span></div></pre></td></tr></table></figure>
<p>代码头,作者名,由编译器自动生成</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">import</span> urllib.request</div></pre></td></tr></table></figure>
<p>导入外部包,这里我们使用urllib模块,urllib是python的一个获取url(Uniform Resource Locators,统一资源定址器)的模块。</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">result=urllib.request.urlopen(<span class="string">"http://ww4.sinaimg.cn/mw600/4bf31e43jw1ew3gd4dh6sj20u018ggza.jpg"</span>)</div></pre></td></tr></table></figure>
<p>urllib.request.urlopen的作用是打开一个网址,参数可以是一个url,也可以是request对象。这里我给的是一张图片的地址</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">img=result.read()</div></pre></td></tr></table></figure>
<p>对result返回结果进行读取,然后赋值到一个img变量里</p>
<figure class="highlight python"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">with</span> open(<span class="string">"img.jpg"</span>,<span class="string">"wb"</span>) <span class="keyword">as</span> f:</div><div class="line"> f.write(img)</div></pre></td></tr></table></figure>
<p>进行文件写入,”open”为打开文件,”img.jpg”为文件名,”wb”是权限,当文件不存在时会先创建文件,”f.write(img)”写入刚刚读取的二进制</p>
<ul>
<li>运行.py代码</li>
</ul>
<p>双击.py文件或者用ide运行代码,可以在.py文件所在目录看到新建的”img.jpg”文件,说明代码运行成功,成功下载了一张图片</p>
<p><img src="/2016/06/30/Python网络爬虫-Lesson-One/2016-07-01_114725.bmp" alt=""></p>
<p>这样就实现了Python爬虫的下载功能</p>
]]></content>
</entry>
<entry>
<title><![CDATA[Markdown基础语法]]></title>
<url>https://longhaoteng.github.io/2016/06/26/Markdown/</url>
<content type="html"><![CDATA[<p><em><a href="http://sspai.com/25137" target="_blank" rel="external">详细文档</a></em></p>
<p>Markdown 是一种轻量级的「标记语言」,它的优点很多,目前也被越来越多的写作爱好者,撰稿者广泛使用。看到这里请不要被「标记」、「语言」所迷惑,Markdown 的语法十分简单。常用的标记符号也不超过十个,这种相对于更为复杂的HTML 标记语言来说,Markdown 可谓是十分轻量的,学习成本也不需要太多,且一旦熟悉这种语法规则,会有一劳永逸的效果。</p>
<a id="more"></a>
<h3 id="标题"><a href="#标题" class="headerlink" title="标题"></a>标题</h3><blockquote>
<p># 一级标题</p>
<p>## 二级标题</p>
<p>### 三级标题</p>
<p>#### 四级标题</p>
<p>##### 五级标题</p>
<p>###### 六级标题</p>
</blockquote>
<h3 id="序列"><a href="#序列" class="headerlink" title="序列"></a>序列</h3><blockquote>
<p>- + *</p>
</blockquote>
<ul>
<li>序列1</li>
</ul>
<ul>
<li>序列2</li>
</ul>
<ul>
<li>序列3</li>
</ul>
<h3 id="斜体"><a href="#斜体" class="headerlink" title="斜体"></a>斜体</h3><blockquote>
<p>*body*</p>
</blockquote>
<p><em>body</em></p>
<h3 id="粗体"><a href="#粗体" class="headerlink" title="粗体"></a>粗体</h3><blockquote>
<p>*<em>body*</em></p>
</blockquote>
<p><strong>body</strong></p>
<h3 id="引用"><a href="#引用" class="headerlink" title="引用"></a>引用</h3><blockquote>
<p>> body</p>
<p>body</p>
</blockquote>
<h3 id="表格"><a href="#表格" class="headerlink" title="表格"></a>表格</h3><blockquote>
<p>| Header One | Header Two |</p>
<p>| :————- | :————- |</p>
<p>| Item One | Item Two |</p>
</blockquote>
<table>
<thead>
<tr>
<th style="text-align:left">Header One</th>
<th style="text-align:left">Header Two</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">Item One</td>
<td style="text-align:left">Item Two</td>
</tr>
</tbody>
</table>
<h3 id="普通代码框"><a href="#普通代码框" class="headerlink" title="普通代码框"></a>普通代码框</h3><blockquote>
<p>`code`</p>
</blockquote>
<p><code>测试内容</code></p>
<h3 id="高亮代码"><a href="#高亮代码" class="headerlink" title="高亮代码"></a>高亮代码</h3><blockquote>
<p>```code</p>
<p>```</p>
</blockquote>
<figure class="highlight html"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="meta"><!DOCTYPE html></span></div><div class="line"><span class="tag"><<span class="name">html</span>></span></div><div class="line"> <span class="tag"><<span class="name">head</span>></span></div><div class="line"> <span class="tag"><<span class="name">meta</span> <span class="attr">charset</span>=<span class="string">"utf-8"</span>></span></div><div class="line"> <span class="tag"><<span class="name">title</span>></span><span class="tag"></<span class="name">title</span>></span></div><div class="line"> <span class="tag"></<span class="name">head</span>></span></div><div class="line"> <span class="tag"><<span class="name">body</span>></span></div><div class="line"> <span class="tag"></<span class="name">body</span>></span></div><div class="line"><span class="tag"></<span class="name">html</span>></span></div></pre></td></tr></table></figure>
<h3 id="链接插入"><a href="#链接插入" class="headerlink" title="链接插入"></a>链接插入</h3><blockquote>
<p>[body](link)</p>
</blockquote>
<p><a href="http://sspai.com/25137" target="_blank" rel="external">link</a></p>
<h3 id="图片插入"><a href="#图片插入" class="headerlink" title="图片插入"></a>图片插入</h3><blockquote>
<p>![链接](link)</p>
</blockquote>
<p><img src="http://cdn.sspai.com/attachment/thumbnail/2014/04/15/54b0855cf47d559c8c59e8f503af17d410f70_mw_800_wm_1_wmp_3.jpg" alt=""></p>
<h3 id="分割线"><a href="#分割线" class="headerlink" title="分割线"></a>分割线</h3><blockquote>
<p>***</p>
</blockquote>
<hr>
]]></content>
</entry>
</search>