1.  什么是储过程,使用存过程处?

存储Stored Procedure 成特定功SQL 句集编译用户通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来执它。存储过程是数据库中的一个重对象,数据到存 

优点 
(1)就是程,调用 (2)操作  SQL 语句  SQL 的要 

(3)个需  SQL 码的完成 送数 

(4) 于没的用行存程。 

2.  Oracle储过么创建

存储 

create or replace procedure 存储过程名(param1 in typeparam2 out type as

1 类型(值范围);

2 类型(值范围);

Begin

 Select count(*) into 1 from A where列名=param1 

 If (判断条件) then 

 Select  into 2 from A where列名=param1 

 Dbms_outputPut_line(‘打印信息’);

 Elsif (判断条件) then

 Dbms_outputPut_line(‘打印信息’);

 Else 

 Raise 异常名(NO_DATA_FOUND;

 End if; 

Exception

 When others then 

 Rollback; 

End;

注意 

1. 范围,inout表示输出 

2. 接分 

3. count*存在 4. select into。。赋值 

5.   raise+常名 

3.  如何使Oracle游标?

1Oracle分为 
2cursor...is它可(select)返回  3插入  (insert)删除(delete)(update)  (select)PL/SQL 

4打开闭游PL/SQLSQL游标内部SQL语句 

4.  Oracle字符什么连

Oracle使  || 个符号连  abc  || d abcd 

5.  Oracle是如行分页询的

Oracle使rownum来进, 最好hibernate使rownumOralce分页 

select * from

 ( select rownum r,a from tabName where rownum <= 20 )  

where r > 10

6.  存储过和存储函数的特和区

特点 
1、一现的函数比较强。 

2、对返回回值 

3为一个独函数一个数可以返回可以FROM面。 

区别 

1,而过没有. 

2.而过须通execute执行. 

3SQL执行.不行.

 将比复杂函数.到存函数. 

7.  存储过程SQL对比? 

优势: 

1 

SQL行分 是预译的运行一个程时化器其进行分终被计划时便销。 

2 
存储供存数信的流量。 

3便 
数据库专业人员可以随时对存储过程进行修改,但对应用程序源代码却毫无影响,从而极大的提高了程序的移植性 

4 
1的某限限对数访问 
2)在通过网络调用,只有对执行过程的调是可见的 因此,恶意户无法看到表和数据库象名称、嵌入  Transact-SQL  

3使  SQL  参数非可代码者将令插入  Transact-SQL 并损更为 

4这有糊处 

劣势 
1据库但实序开兼职 2储过SQL灵活 

8.  你觉得储过程SQL该使用

1性要议采 
2参数SQL折中的方 

3高,建议过程 

9.  触发器作用有哪些?

1的相通过可以 

2)触发可以强比用  CHECK 定义的约更为复杂的束。与  CHECK 束不同触发器以引用它表中可以使  SELECT 入或数据数据显示 

3业务 
4修改据其 

10. 在千万的数据库查询中如何效率?

1方面 
a. 应尽量避考虑  where   order by 上建引。 b. 应尽量避免  where 子句中对字段  null 值判断,否则导致引擎放弃使用索引进行全表扫

如:  select id from t where num is null num0numnull,然询:  select id from t where num=0

c. 都有SQL数据当索,询可能一表sexmalefemale么即使sex也对询效率起 

d. 索引并不越多越好索引固然可提高相  select 的效,但同时降低了  insert   update 效率,因为  insert   update 时有可能会重,所以怎样建索引需要慎重考虑,视具体情况而定。一个表的索6个,不常使引是 

e. 能的引数索引数据列的理存序,一旦该列值将导致整个表记录的顺序的调整,会耗费相当大的资源。若应用系统需要频繁更新索引数据列,那么需要考虑否应将 

f. 尽量使用数型字段,若只含数值信息的字段尽量不要设计为字符型,这会降低查询和连接的性能,会增加存储开销。这是因为引擎在处理查询和连接时会逐个比较字符串中每一个字符,而对于数字型而言只需比较一 

g. 使用  varchar/nvarchar   char/nchar 变长储空间,其次个相效率 

h. 使临时大量常有 i. 避免除临时表的消耗。 

j. 临时表不是不可使用,适当地使用们可以使某些例程更有,例如,当需要重复引大型表或常用表中的,对使用 

k. 一次那么使  select into 代替  create table造成大量  log 如果和系create tableinsert  l. 如果使在存所有  truncate table   drop table 统表 

2)SQL 
a.   where 子句使!=<>,否使引而 

b. 应尽  where 子句使用  or 件,则将擎放使用引而表扫 select id from t where num=10 or num=20 以这  select id from t where num=10 union all select id from t where num=20
c. in   not in ,否  select id from t where num in(1,2,3) 续的数值  between 不要  in   select id from t where num between 1 and 3
d. 表扫  select id from t where name like %abc% 
e. 果在  where 句中使用扫描SQL行时但优化程序访择推必须在编选择然而如果访值还未知的,作为索引项。如下面语全表扫描  select  id  from  t  where num=@num 为强制查使  select id from t with(index()) where num=@num f. 应尽量  where 句中对段进表达式作,这导致擎放弃使用索引进行表扫描 select id from t where num/2=100 改为: select id from t where num=100*2
g. where句中这将使引而  select id  from  t  where  substring(name,1,3)=abc name  abc  id  select  id  from  t  where datediff(day,createdate,2005-11-30)=02005-11-30id 改为: select id from t where name like abc%  select id from t where createdate>=2005-11-30  and createdate<2005-12-1 

h.   where =术运将可法正使索引 

i. 不要义的查询表结  select col1,col2 into #t from t where 1=0 类代集,的,  create table #t() 
j.   exists   in 择:  select num from a where num in(select num from b) 用下  select num from a where exists(select 1 from b where num=a.num)
k. 使  select * from t 具体的字*,不要返 

l. 尽量使,因为游游标据超1行, m. 大数,应合理 

n. 提高 

3)java 

a. 

b.系统的位少量数据量的定不ORM框架 

c.使jDBC库操作数 
d.控制据流起来存再处理 e.据要 

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐