Home » SQL & PL/SQL » SQL & PL/SQL » Use of ALTER SESSION in procedure?
Use of ALTER SESSION in procedure? [message #47090] Thu, 22 July 2004 00:41 Go to next message
Klaus
Messages: 2
Registered: February 2003
Junior Member
Hello all together,

I try to create a procedure which should generate the statistc histogramms from the db tables. As I found, I have to ALTER the session first to avoid a bug in dbms_stats.

Now I have no idea, how I can alter the session in this function. If I try the code below, I always get the error, that ALTER is not allowd after the keyword BEGIN.

Any ideas??

I use oracle 9i with patchset 4.

�Thanks in advance



Klaus



BEGIN

-- wegen Bug von dbms_stats


ALTER SESSION SET NLS_NUMERIC_CHARACTERS='.,';

�dbms_stats.gather_schema_stats(

ownname => 'IFADMIN',


-- ESTIMATE_PERCENT => 10, /* sample von 10% */


ESTIMATE_PERCENT => NULL, /* alle Daten */


method_opt => 'FOR ALL INDEXED COLUMNS SIZE 254',

degree => 1,

cascade => TRUE);

END;

/
Re: Use of ALTER SESSION in procedure? [message #47095 is a reply to message #47090] Thu, 22 July 2004 02:43 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9105
Registered: November 2002
Location: California, USA
Senior Member
scott@ORA92> BEGIN
2 EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_NUMERIC_CHARACTERS=''.,''';
3 END;
4 /

PL/SQL procedure successfully completed.
Re: Use of ALTER SESSION in procedure? [message #47374 is a reply to message #47095] Fri, 13 August 2004 02:53 Go to previous messageGo to next message
Shampa Srivastava
Messages: 9
Registered: August 2004
Junior Member
I wnated to use NLS_DATE_LNAGUAGE
And it worked fine.Thanks
But in case I wnatto set the NLS_DATE_LANGUAGE to default then what should be the valid value?
Re: Use of ALTER SESSION in procedure? [message #47393 is a reply to message #47374] Sat, 14 August 2004 17:10 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9105
Registered: November 2002
Location: California, USA
Senior Member
I am not quite sure what you are asking. If you are asking how to set the value of nls_date_language back to the original value, after changing it, then the following demonstrates that.

sys@ORA92> alter session set nls_date_format = 'day-month-yyyy'
  2  /

Session altered.

sys@ORA92> set serveroutput on
sys@ORA92> declare
  2    initial_date_lang varchar2(64);
  3    current_date_lang varchar2(64);
  4  begin
  5    -- store value of initial nls_date_language to variable and display it:
  6    select value
  7    into   initial_date_lang
  8    from   v$nls_parameters
  9    where  parameter = 'NLS_DATE_LANGUAGE';
 10    dbms_output.put_line ('initial nls_date_language: ' || initial_date_lang);
 11    dbms_output.put_line (sysdate);
 12    --
 13    -- change the value of the nls_date_language and display it:
 14    EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_LANGUAGE = ''FRENCH''';
 15    select value
 16    into   current_date_lang
 17    from   v$nls_parameters
 18    where  parameter = 'NLS_DATE_LANGUAGE';
 19    dbms_output.put_line ('current nls_date_language: ' || current_date_lang);
 20    dbms_output.put_line (sysdate);
 21    --
 22    --
 23    -- change the value of the nls_date_language and display it:
 24    EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_LANGUAGE = ''ITALIAN''';
 25    select value
 26    into   current_date_lang
 27    from   v$nls_parameters
 28    where  parameter = 'NLS_DATE_LANGUAGE';
 29    dbms_output.put_line ('current nls_date_language: ' || current_date_lang);
 30    dbms_output.put_line (sysdate);
 31    --
 32    -- change the value of the nls_date_language and display it:
 33    EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_LANGUAGE = ''GERMAN''';
 34    select value
 35    into   current_date_lang
 36    from   v$nls_parameters
 37    where  parameter = 'NLS_DATE_LANGUAGE';
 38    dbms_output.put_line ('current nls_date_language: ' || current_date_lang);
 39    dbms_output.put_line (sysdate);
 40    --
 41    -- change the value back to the stored initial value and dispaly it:
 42    EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_LANGUAGE = ''' || initial_date_lang || '''';
 43    select value
 44    into   current_date_lang
 45    from   v$nls_parameters
 46    where  parameter = 'NLS_DATE_LANGUAGE';
 47    dbms_output.put_line ('current nls_date_language: ' || current_date_lang);
 48    dbms_output.put_line (sysdate);
 49  end;
 50  /
initial nls_date_language: AMERICAN
saturday -august   -2004
current nls_date_language: FRENCH
samedi  -ao�t     -2004
current nls_date_language: ITALIAN
sabato   -agosto   -2004
current nls_date_language: GERMAN
samstag   -august   -2004
current nls_date_language: AMERICAN
saturday -august   -2004

PL/SQL procedure successfully completed.
Re: Use of ALTER SESSION in procedure? [message #47410 is a reply to message #47393] Mon, 16 August 2004 23:07 Go to previous message
Shampa Srivastava
Messages: 9
Registered: August 2004
Junior Member
Thanks Barbara!
It worked !
Previous Topic: Connection not open
Next Topic: Dynamic SQl
Goto Forum:
  


Current Time: Sat May 17 14:27:40 CDT 2025