oracle dbms_session package

Any tables, views, materialized views, sequences, private synonyms, PL/SQL packages, functions, procedures, and cache groups owned by the same user share one namespace and so the names for each of these objects must be unique within that namespace. Indexes are created in their own namespace.
(每个用户一个命名空间)

ORA-04063: package body 有错误——是package里面有错误,一般不是call方法错了

CREATE OR REPLACE CONTEXT sc_test USING set_contxt; 

CREATE OR REPLACE PROCEDURE set_contxt IS lcontext dbms_session.appctxtabtyp; 
lsize    NUMBER; 
BEGIN 
  FOR i IN 1..5 LOOP 
    dbms_session.set_context('SC_TEST', 'ATTR' || i, i * 100); 
  END LOOP; 

  FOR j IN (SELECT * FROM session_context ORDER BY 2) LOOP 
    dbms_output.put_line(j.attribute || ', ' || j.value); 
  END LOOP; 

  dbms_output.put_line('*****'); 
  dbms_session.list_context (lcontext, lsize); 
  FOR k IN 1 .. (lcontext.COUNT) 
  LOOP 
    dbms_output.put_line('Namespace: ' || lcontext(k).namespace || ' Attribute: ' || lcontext(k).attribute || ' Value: ' || 
lcontext(k).value); 
  END LOOP; 
  dbms_output.put_line('*****'); 

  dbms_output.put_line('List Size: ' || lsize); 

  dbms_session.clear_context('SC_TEST', NULL, 'ATTR2'); 
  dbms_output.put_line( '*** ATTR2 has now been cleared ***' ); 

  FOR l IN (SELECT * FROM session_context ORDER BY 2) LOOP 
    dbms_output.put_line(l.attribute || ', ' || l.value); 
  END LOOP; 
END set_contxt; 
CREATE OR REPLACE PROCEDURE show_context_info IS context_info DBMS_SESSION.AppCtxTabTyp;
   info_count PLS_INTEGER;
   indx PLS_INTEGER;
BEGIN
   DBMS_SESSION.LIST_CONTEXT (
      context_info,
      info_count);
   indx := context_info.FIRST;   
   LOOP
      EXIT WHEN indx IS NULL;
      DBMS_OUTPUT.PUT_LINE (
         context_info(indx).namespace || '.' ||
         context_info(indx).attribute || ' = ' ||
         context_info(indx).value);
      indx := context_info.NEXT (indx);
   END LOOP;   
END;

然后在command窗口执行

set serveroutput on

然后

exec 过程名

或者

call 过程名()

你可能感兴趣的:(oracle)