Oracle TNS¼òÊö
Oracle TNS¼òÊö
ʲôÊÇTNS?
TNSÊÇOracle NetµÄÒ»²¿·Ö,רÃÅÓÃÀ´¹ÜÀíºÍÅäÖÃOracleÊý¾Ý¿âºÍ¿Í»§¶ËÁ¬½ÓµÄÒ»¸ö¹¤¾ß,ÔÚ´ó¶àÊýÇé¿öÏ¿ͻ§¶ËºÍÊý¾Ý¿âҪͨѶ,±ØÐëÅäÖÃTNS,µ±È»ÔÚÉÙÊýÇé¿öÏÂ,²»ÓÃÅäÖÃTNSÒ²¿ÉÒÔÁ¬½ÓOracleÊý¾Ý¿â,±ÈÈçͨ¹ýJDBC.Èç¹ûͨ¹ýTNSÁ¬½ÓOracle,ÄÇô¿Í»§¶Ë±ØÐë°²×°Oracle client³ÌÐò.
TNSÓÐÄÇЩÅäÖÃÎļþ?
TNSµÄÅäÖÃÎļþ°üÀ¨·þÎñÆ÷(°²×°OracleÊý¾Ý¿âµÄ»úÆ÷)¶ËºÍ¿Í»§¶ËÁ½²¿·Ö.·þÎñÆ÷ÓÐlistener.ora,sqlnet.ora,tnsnames.ora,Èç¹ûͨ¹ýOCM(Oracle Connection Manage)ºÍÓòÃû·þÎñ¹ÜÀí¿Í»§¶ËÁ¬½Ó,·þÎñÆ÷¶Ë¿ÉÄÜ»¹°üÀ¨cman.oraµÈÎļþ;¿Í»§¶ËÓÐtnsnames.ora,sqlnet.ora.
listener.ora:¼àÌýÆ÷ÅäÖÃÎļþ,³É¹¦Æô¶¯ºóÊÇפÁôÔÚ·þÎñÆ÷¶ËµÄÒ»¸ö·þÎñ.ʲôÊǼàÌýÆ÷?¼àÌýÆ÷ÊÇÓÃÀ´ÕìÌý¿Í»§¶ËµÄÁ¬½ÓÇëÇóÒÔ¼°½¨Á¢¿Í»§¶ËºÍ·þÎñÆ÷¶ËÁ¬½ÓͨµÀµÄÒ»¸ö·þÎñ³ÌÐò.ĬÈÏÇé¿öÏÂOracleÔÚ1521¶Ë¿ÚÉÏÕìÌýÊý¾Ý¿âÁ¬½ÓÇëÇó.
sqlnet.ora:ÓÃÀ´¹ÜÀíºÍÔ¼Êø»òÏÞÖÆtnsÁ¬½ÓµÄÅäÖÃ,ͨ¹ýÔÚ¸ÃÎļþÖÐÉèÖÃһЩ²ÎÊý,¿ÉÒÔ¹ÜÀíTNSÁ¬½Ó.¸ù¾Ý²ÎÊý×÷ÓõIJ»Í¬,ÐèÒª·Ö±ðÔÚ·þÎñÆ÷ºÍ¿Í»§¶ËÅäÖÃ.
tnsnames.ora:ÅäÖÿͻ§¶Ëµ½·þÎñÆ÷¶ËµÄÁ¬½Ó·þÎñ,°üÀ¨¿Í»§¶ËÒªÁ¬½Óµ½µÄ·þÎñÆ÷ºÍÊý¾Ý¿âµÄÅäÖÃÐÅÏ¢.
OracleËùÓеÄTNSÅäÖÃÎļþ¶¼´æ·ÅÔÚ
unix/linux: $ORACLE_HOME/network/admin
windows: %ORACLE_HOME%\network\admin
TNSÓÐÄÇЩÅäÖù¤¾ß?
ÎÒÃÇ¿ÉÒÔÊÖ¶¯ÅäÖÃ,Ò²¿ÉÒÔͨ¹ýOracle Net Configuretion AssitantÅäÖÃ.
OracleTNSÅäÖÃÁ÷³Ì
Ê×ÏÈÔÚOracle server¶Ë°²×°Íê³ÉÖ®ºó,Òò¸ÃÏÈ×ÅÊÖÅäÖÃLISTENER,listenerrÊǽøÐÐOracleͨѶµÄÊ×Òª×é¼þ,½ô½Ó×ÅÔÚ¿Í»§¶Ë°²×°Oracle client,ͬʱÅäÖÃtnsnames.oraÎļþ.
LISTENER(¼àÌýÆ÷)ÅäÖÃ
Ê×ÏȼàÌýÆ÷°üÀ¨Á½¸ö²¿·Ö:OracleÒª¼àÌýµÄµØÖ·¡¢¶Ë¿Ú¡¢Í¨Ñ¶ÐÒé;OracleÒª¼àÌýµÄÊý¾Ý¿âʵÀý.·ÇRAC»·¾³ÏÂ,LISTENERÖ»ÄܼàÌý±¾·þÎñÆ÷µÄµØÖ·ºÍʵÀý,RAC»·¾³ÏÂ,LISTENER»¹¿ÉÒÔ¼àÌýÔ¶³Ì·þÎñÆ÷.ÿ¸öÊý¾Ý¿â×îÉÙÒªÅäÖÃÒ»¸ö¼àÌýÆ÷
LISTENER=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=tcp)(HOST=sales-server)(PORT=1521))
(ADDRESS=(PROTOCOL=ipc)(KEY=extproc))
)
)
SID_LIST_LISTENER=
(SID_LIST=
(SID_DESC=
(SID_NAME=plsextproc)
(ORACLE_HOME=/oracle10g)
(PROGRAM=extproc)
)
(SID_DESC=
(SID_NAME=mayp)
(ORACLE_HOME=/oracle10g)
)
)
listener²¿·ÖÅäÖÃÁËOracleÒª¼àÌýµÄµØÖ·ÐÅÏ
Ïà¹ØÎĵµ£º
oracle±í¿Õ¼ä²Ù×÷Ïê½â
1
2
3×÷Õߣº À´Ô´£º ¸üÐÂÈÕÆÚ£º2006-01-04
5
6
7½¨Á¢±í¿Õ¼ä
8
9CREATE TABLESPACE data01
10DATAFILE '/ora ......
declare cursor myCursor is select * from ±íÃû;
myRow myCursor%rowtype;
begin
open myCursor;
loop
fetch myCursor into myRow;
exit when myCursor%notfound;
--ÒªÖ´ÐеÄSQLÓï¾ä
end loop;
end; ......
ÔÚ¶ÔÊý¾Ý¿â½øÐвÙ×÷¹ý³ÌÖÐÎÒÃÇ¿ÉÄÜ»áÓöµ½ÕâÖÖÇé¿ö£¬±íÖеÄÊý¾Ý¿ÉÄÜÖظ´³öÏÖ£¬Ê¹ÎÒÃǶÔÊý¾Ý¿âµÄ²Ù×÷¹ý³ÌÖдøÀ´ºÜ¶àµÄ²»±ã£¬ÄÇôÔõôɾ³ýÕâЩÖظ´Ã»ÓÐÓõÄÊý¾ÝÄØ?
¡¡¡¡Öظ´Êý¾Ýɾ³ý¼¼Êõ¿ÉÒÔÌṩ¸ü´óµÄ±¸·ÝÈÝÁ¿£¬ÊµÏÖ¸ü³¤Ê±¼äµÄÊý¾Ý±£Áô£¬»¹ÄÜʵÏÖ±¸·ÝÊý¾ÝµÄ³ÖÐøÑéÖ¤£¬Ìá¸ßÊý¾Ý»Ö¸´·þÎñˮƽ£¬·½±ãʵÏÖÊý¾ÝÈÝÔֵȡ£ Öظ´µÄÊý¾Ý ......
vi /opt/back.sh(oracleÓû§)
#!/bin/ksh
tim=`date +%Y%m%d`
unset USERNAME
#export DISPLAY=0.0.0.0:0.0
#export ORACLE_BASE=/home/oraprod3
#export ORACLE_HOME=/prod/oracle/prod3db/9.2.0
#export ORACLE_SID=PROD3_db
#export LD_LIBRARY_PATH=/prod/oracle/prod3db/9.2.0/lib
#export ORACLE_TERM=vt100 ......