ʵ¼ùÖ¸ÄÏ£ºÔÚOracleÖÐʵÏÖ±í¼¶Ö»¶ÁȨÏÞ
ÔÚOracleÖÐʵÏÖ±í¼¶Ö»¶ÁȨÏÞÊÇÊý¾Ý¿âÖÎÀíÖг£¼ûÇÒÖ÷ÒªµÄ²Ù×÷¡£Í¨¹ýÉèÖÃÖ»¶ÁȨÏÞ£¬¿ÉÒÔÈ·±£²¿·ÖÓû§Ö»ÄÜÅÌÎʱíµÄÊý¾Ý£¬¶ø²»¿É¾ÙÐÐÐ޸IJÙ×÷£¬´Ó¶øÓÐÓñ£»¤Êý¾ÝµÄÍêÕûÐÔºÍÇå¾²ÐÔ¡£ÏÂÃ潫ÏêϸÏÈÈÝÔÚOracleÖÐÔõÑùʵÏÖ±í¼¶Ö»¶ÁȨÏÞ£¬ÒÔ¼°ÏêϸµÄ´úÂëʾÀý¡£
°ì·¨Ò»£º½¨Éè±í
Ê×ÏÈ£¬ÔÚOracleÖн¨ÉèÒ»¸öʾÀý±í£¬ÓÃÓÚÑÝʾÔõÑùÉèÖÃ±í¼¶Ö»¶ÁȨÏÞ¡£¼ÙÉèÎÒÃǽ¨ÉèÁËÒ»¸öÃûΪ¡°example_table¡±µÄ±í£¬°üÀ¨Á½¸ö×ֶΣºidºÍname¡£
CREATE TABLE example_table ( id INT PRIMARY KEY, name VARCHAR2(50) ); INSERT INTO example_table (id, name) VALUES (1, 'Alice'); INSERT INTO example_table (id, name) VALUES (2, 'Bob');
µÇ¼ºó¸´ÖÆ
°ì·¨¶þ£º½¨ÉèÖ»¶Á½ÇÉ«
½ÓÏÂÀ´£¬ÎÒÃÇÐèÒª½¨ÉèÒ»¸öÖ»¶Á½ÇÉ«£¬ÓÃÓÚ¸¶ÓëÓû§Ö»¶ÁȨÏÞ¡£Ö´ÐÐÒÔÏÂSQLÓï¾ä£º
CREATE ROLE read_only_role;
µÇ¼ºó¸´ÖÆ
°ì·¨Èý£º¸¶Óë±í¼¶Ö»¶ÁȨÏÞ
½«Ö»¶ÁȨÏÞ¸¶Óë¸Õ½¨ÉèµÄÖ»¶Á½ÇÉ«£¬ÒÔÏÞÖƶԡ°example_table¡±±íµÄÐ޸IJÙ×÷¡£
GRANT SELECT ON example_table TO read_only_role;
µÇ¼ºó¸´ÖÆ
°ì·¨ËÄ£º½¨ÉèÖ»¶ÁÓû§
½¨ÉèÒ»¸öÖ»¶ÁÓû§£¬²¢½«Ö®Ç°½¨ÉèµÄÖ»¶Á½ÇÉ«¸¶Óë¸ÃÓû§¡£
CREATE USER read_only_user IDENTIFIED BY password; GRANT read_only_role TO read_only_user;
µÇ¼ºó¸´ÖÆ
°ì·¨Î壺Ñé֤ȨÏÞÉèÖÃ
×îºó£¬Ê¹ÓÃÖ»¶ÁÓû§µÇ¼OracleÊý¾Ý¿â£¬²¢ÊµÑé¶Ô¡°example_table¡±±í¾ÙÐÐÐ޸IJÙ×÷£¬Èç²åÈë¡¢¸üлòɾ³ýÊý¾Ý¡£¿ÉÒÔ¿´µ½Ö»¶ÁÓû§ÎÞ·¨Ö´ÐÐÕâЩ²Ù×÷£¬Ö»ÄܾÙÐÐÅÌÎʲÙ×÷¡£
×ܽá
ͨ¹ýÒÔÉÏ°ì·¨£¬ÎÒÃÇÀÖ³ÉʵÏÖÁËÔÚOracleÖÐÉèÖÃ±í¼¶Ö»¶ÁȨÏ޵IJÙ×÷¡£Í¨¹ý½¨ÉèÖ»¶Á½ÇÉ«£¬½«Ö»¶ÁȨÏÞ¸¶ÓëÌض¨±í£¬ÔÙ½«Ö»¶Á½ÇÉ«¸¶ÓëÓû§£¬¾Í¿ÉÒÔÓÐÓÃÏÞÖÆÓû§¶Ô±íµÄ²Ù×÷£¬°ü¹ÜÊý¾ÝµÄÇå¾²ÐÔºÍÍêÕûÐÔ¡£ÔÚÏÖʵӦÓÃÖУ¬Æ¾Ö¤ÏêϸÐèÇó¿ÉÒÔÎÞаµ÷½âȨÏÞÉèÖã¬È·±£Êý¾ÝµÄÇå¾²¡£
Ï£ÍûÒÔÉÏʵ¼ùÖ¸ÄϺʹúÂëʾÀýÄܹ»×ÊÖúÄú¸üºÃµØÃ÷È·ÔÚOracleÖÐʵÏÖ±í¼¶Ö»¶ÁȨÏÞµÄÒªÁ죬²¢Äܹ»ÀÖ³ÉÓ¦ÓÃÓÚÄúµÄÊý¾Ý¿âÖÎÀíÊÂÇéÖС£×£Äú˳Ë죡
ÒÔÉϾÍÊÇʵ¼ùÖ¸ÄÏ£ºÔÚOracleÖÐʵÏÖ±í¼¶Ö»¶ÁȨÏÞµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡