My PL/SQL practice 8/2/10
SQLPlus :http://www.orafaq.com/wiki/SQL*Plus_FAQ
http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/sqloperations.htm
1. Transfer values from a sql scripts:
CNT=`sqlplus -s username/password1@dbname @getUVQuery_NULLCNT`;
Note : Remeber to use option "-s" (-s or -silent -- start sqlplus in silent mode. Not recommended for beginners!)
if not use "-s" , will return something as below :
SQL*Plus: Release 10.2.0.3.0 - Production on Tue Feb 9 11:03:08 2010
Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
0
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
2.getUVQuery_NULLCNT.sql
set term off
column cnt noprint new_value total
SELECT count(inquiry_id) cnt
from inquire_all_current a
WHERE FORM_COMPLETE_STATUS = 'Y'
and ITEM_POPULATE_STATUS = 'N'
and expand_type='uvall'
and uv_query is null
ORDER BY INQUIRY_ID ASC;
set term on
prompt &total
exit
3. Define cursor and use cursor:
DECLARE
CURSOR cur IS
SELECT inquiry_id
from inquire_all_current a
WHERE FORM_COMPLETE
相关文档:
Last login: Mon Feb 8 14:13:19 2010 from 192.168.1.249
ipnet
-bash-3.00$
-bash-3.00$ ipnet
-bash: ipnet: command not found
-bash-3.00$ su - oracle
Password:
eastcsu: incorrect password
-bash-3.00$ eastcom
-bash: eastcom: command not found
-bash-3.00$ su - oracle
Password:
[oracl ......
1、在数据库建表的时候字段直接设置为DATETIME类型;
2、执行插入的时候使用如下语句:
PreparedStatement pstmt = conn.prepareStatement("insert into guestbook(gst_user,gst_title,gst_content,gst_ip,gst_time) values(?,?,?,?,getdate())");
3、要把日期从数据库中取出,执行如下语句:
......
由于代码过于简单,直接贴出:
SqlDataSourceEnumerator SseInstance = SqlDataSourceEnumerator.Instance;
//ServerName:服务器名;
//InstanceName:实例名;
//IsClustered:是否为群集服务器的一部分;
//Version:版本,8.*是SQL 2000,9.*是SQL 2005
DataTable DtSqlInstance = SseInstance.GetDataSources();
注: ......
1 用UNION替换OR (适用于索引列)
通常情况下, 用UNION替换WHERE子句中的OR将会起到较好的效果. 对索引列使用OR将造成全表扫描. 注意, 以上规则只针对多个索引列有效.
如果有column没有被索引, 查询效率可能会因为你没有选择OR而降低. 在下面的例子中, LOC_ID 和REGION上都建有索引.
高效: SELECT LOC_ID , LOC_DESC , ......
表中主键必须为标识列,[ID] int IDENTITY (1,1)
1.分页方案一:(利用Not In和SELECT TOP分页)
语句形式:
SELECT TOP 页记录数量 *
from 表名
WHERE (ID NOT IN
(SELECT TOP (每页行数*(页数-1)) ID
from 表名
ORDER BY ID))
ORDER BY ID
//自己还可以加上一些查 ......