oracle ´æ´¢¹ý³Ì
select myFunc(²ÎÊý1,²ÎÊý2..) to dual; --¿ÉÒÔÖ´ÐÐһЩҵÎñÂß¼
Ò»:OracleÖеĺ¯ÊýÓë´æ´¢¹ý³ÌµÄÇø±ð:
A:º¯Êý±ØÐëÓзµ»ØÖµ,¶ø¹ý³ÌûÓÐ.
B:º¯Êý¿ÉÒÔµ¥¶ÀÖ´ÐÐ.¶ø¹ý³Ì±ØÐëͨ¹ýexecuteÖ´ÐÐ.
C:º¯Êý¿ÉÒÔǶÈëµ½SQLÓï¾äÖÐÖ´ÐÐ.¶ø¹ý³Ì²»ÐÐ.
ÆäʵÎÒÃÇ¿ÉÒÔ½«±È½Ï¸´ÔӵIJéѯд³Éº¯Êý.È»ºóµ½´æ´¢¹ý³ÌÖÐÈ¥µ÷ÓÃÕâЩº¯Êý.
¶þ:ÈçºÎ´´½¨´æ´¢¹ý³Ì:
A:¸ñʽ
create or replace procedure <porcedure_name>
[(²ÎÊýÃû²ÎÊýÀàÐÍÒÔ¼°ÃèÊö,....)] ---×¢Òâ,ûÓзµ»ØÖµ
is
[±äÁ¿ÉùÃ÷]
begin
[¹ý³Ì´¦Àí];----------null;
exception
when Òì³£Ãû then
end;
×¢Òâ:²ÎÊýÖÐĬÈÏÊÇ°´Öµ´«µÝ.ÊÇin·½Ê½.Ò²¿ÉÒÔÊÇoutºÍin out·½Ê½.ÕâЩÌصãºÍº¯ÊýÒ»Ñù.
B:¾ÙÀý1:
create or replace procedure myPro----create or replace proc myPro ³ö´í ²»Äܼòд
(a in int:=0,b in int:=0)
is
c int:=0;
begin
c:=a+b;
dbms_output.put_line('C is value'||c);
end;
Ö´ÐÐ:
execute myPro(10,20); ---ÔÚSql ServerÖÐ.Ö´Ðд洢¹ý³ÌÊDz»ÐèÒªÀ¨»¡µÄ.×¢Ò⠷ֺŲ»Òªµ÷ÁË.
exec myPro(10,20); --¿ÉÒÔ¼òд
C:¾ÙÀý2:
Èç¹ûÔÚÒ»¸öº¯ÊýÀïÃæ°üº¬SelectÓï¾äµÄ»°,ÄÇô¸ÃSelectÓï¾ä±ØÐëÓÐinto,¹ý³ÌͬÑùÒ²ÐèÒª.
create or replace procedure myPro1
(a int:=0,b int:=0)
is
c int:=0;
begin
select empno+a+b into c from emp where ename='FORD';
dbms_output.put_line('C is values '||c);
end;
Ö´ÐÐ:
execute myPro1(10,20)
D:¼ÙÈçÔÚÒ»¸ö¹ý³ÌÀïÃæÒª·µ»ØÒ»¸ö½á¹û¼¯£¬Ôõô°ì?´ó¼Ò×¢Òâ.¾Í±ØÐëÒªÓõ½ÓαêÁË!ÓÃÓαêÀ´´¦ÀíÕâ¸ö½á¹û¼¯.
create or replace procedure Test
(
varEmpName emp.ename%type
)
is begin ------»á±¨´í.´íÎóÔÒòûÓÐinto×Ó¾ä.
select * from emp where ename like '%'||varEmpName||'%';
end;
Õâ¸ö³ÌÐòÎÒÃÇÎÞ·¨ÓÃinto£¬ÒòΪÔÚOracleÀïÃæûÓÐÒ»¸öÀàÐÍÈ¥½ÓÊÜÒ»¸ö½á¹û¼¯.Õâ¸öʱºòÎÒÃÇ¿ÉÒÔÉùÃ÷Óαê¶ÔÏóÈ¥½ÓÊÜËû.
PL/SQLÓαê:
A:·ÖÀà:
1:ÒþʽÓαê:·ÇÓû§Ã÷È·ÉùÃ÷¶ø²úÉúµÄÓαê. Äã¸ù±¾¿´²»µ½cursorÕâ¸ö¹Ø¼ü×Ö.
2:ÏÔʾÓαê:Óû§Ã÷ȷͨ¹ýcursor¹Ø¼ü×ÖÀ´ÉùÃ÷µÄÓαê.
B:ʲôÊÇÒþʽÓαê:
1:ʲôʱºò²úÉú:
»áÔÚÖ´ÐÐÈκκϷ¨µÄSQLÓï¾ä(DML---INSERT UPDATE DELETE DQL-----SELECT)ÖвúÉú.Ëû²»Ò»¶¨´æ·ÅÊý¾Ý.Ò²ÓпÉÄÜ´æ·Å¼Ç¼¼¯ËùÓ°ÏìµÄÐÐÊý.
Èç¹ûÖ´ÐÐSELECTÓï¾ä,Õâ¸öʱºòÓαê»á´æ·ÅÊý¾Ý.Èç¹ûÖ´ÐÐINSERT UPDATE DELETE»á´æ·Å¼Ç¼ӰÏìµÄÐÐÊý.
C:Ò
Ïà¹ØÎĵµ£º
package com.chinacache.boss.queryservice.service.impl;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.chinacache.boss.queryservice.excepti ......
CSDNÀïµÄÒ»¸öÅóÓÑÎʵ½ÁËÕâ¸öË÷Òý¸²¸ÇµÄ¸ÅÄî¡£ Õâ¸ö¸ÅÄîºÜСµÄ֪ʶµã£¬ÔÚÎÒµÄÂÛ̳ÀïÓнâÊÍ“”£¬²»¹ý×÷ΪOracle°æÖ÷£¬²»ÄÜÔÚ»ØÌûÀï¼ÓÉÏÍøÍâµÄµØÖ·Á´½Ó£¬ËùÒÔÕâÀïÔÚCSDNÀïÌûÉÏÒ»·Ý
±ÈÈçÓи´ºÏË÷ÒýΪ3¸ö×ֶΣºf1 + f2 + f3,ÇëÎÊ:
1: select f1, f2, f3, f4 from table where f1 = 'XX' and f2 = 'XX'. ......
1¡¢´´½¨±ít1 £ºcreate table t1 (id number,name nvarchar(8))£»
2¡¢´´½¨ÐòÁÐ £ºCREATE SEQUENCE t1_id INCREMENT BY 1 START WITH 1 MAXVALUE
1.0E28 MINVALUE 1 NOCYCLE CACHE 20 NOORDER
3. ´´½¨´¥·¢Æ÷ £º
CREATE TRIGGER tig_insert_t1
BEFORE INSERT ON "YINZQ"."T1"
begin
if (:new.id is null) then
......
¾¹ý³¤Ê±¼äѧϰ´´½¨Oracle±í¿Õ¼ä£¬ÓÚÊǺʹó¼Ò·ÖÏíһϣ¬¿´Íê±¾ÎÄÄã¿Ï¶¨Óв»ÉÙÊÕ»ñ£¬Ï£Íû±¾ÎÄÄ̻ܽáÄã¸ü¶à¶«Î÷¡£
1¡¢ÏȲéѯ¿ÕÏпռä
select tablespace_name,file_id,block_id,bytes,blocks from dba_free_space;
2¡¢Ôö¼ÓOracle±í¿Õ¼ä
ÏȲéѯÊý¾ÝÎļþÃû³Æ¡¢´óСºÍ·¾¶µÄÐÅÏ¢£¬Óï¾äÈçÏ£º
select&n ......
ÎÒÃǵÄOracle¹ÜÀí¹¤×÷Öо³£Éæ¼°µ½¸ü¸ÄOracleÓû§ÊôÐÔ¡¢ÃÜÂëÖ®ÀàµÄ³£ÓòÙ×÷£»µ«ÔÚijЩӦÓó¡¾°Ï£¬»áÓöµ½OracleÓû§Ãû¸ü¸ÄµÄÐèÇó£¬ÈçºÎ½â¾ö£¿ÏÂÃæͨ¹ýËĸö²½ÖèʵÏÖOracleÓû§ÃûµÄÐ޸ġ£
Ò»¡¢²éѯ¸ü¸ÄOracleÓû§Ãû
SQL> select user#,name,password from user$ where name ='TICKET ......