Home » SQL & PL/SQL » SQL & PL/SQL » ORA-14552: cannot perform a DDL, commit or rollback inside a query or DML
ORA-14552: cannot perform a DDL, commit or rollback inside a query or DML [message #47813] Tue, 21 September 2004 07:44 Go to next message
Shampa Srivastava
Messages: 9
Registered: August 2004
Junior Member
Is there no way to execute a DDL inside a query?

I am trying the following query:

declare

retval DATE;

select FUNC1 ('01-Aug-04' )  into retval from dual;

Func1 has the following statement in its body besides other logic : EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_LANGUAGE="AMERICAN"'

The function runs fine but is it possible to derive the result of function through query?

Thanks
Re: ORA-14552: cannot perform a DDL, commit or rollback inside a query or DML [message #47814 is a reply to message #47813] Tue, 21 September 2004 07:47 Go to previous messageGo to next message
shoblock
Messages: 325
Registered: April 2004
Senior Member
do you really need to use the function in a query? how about:

declare
retval DATE;
begin
retval := FUNC1 ('01-Aug-04' );
Re: ORA-14552: cannot perform a DDL, commit or rollback inside a query or DML [message #47815 is a reply to message #47814] Tue, 21 September 2004 07:59 Go to previous messageGo to next message
Shampa
Messages: 2
Registered: September 2004
Junior Member
I know this works.
Actually the query used to fetch proper results till sometime time back before I made this change(DDL) in func due to language settings on DB server.
Now for this new change , I was wondering if I can adjust the queries which r older..
Re: ORA-14552: cannot perform a DDL, commit or rollback inside a query or DML [message #47820 is a reply to message #47813] Tue, 21 September 2004 17:01 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9092
Registered: November 2002
Location: California, USA
Senior Member
scott@ORA92> alter session set nls_date_format = 'dd-Mon-yyyy'
  2  /

Session altered.

scott@ORA92> alter session set nls_date_language = 'FRENCH'
  2  /

Session altered.

scott@ORA92> select sysdate - 51 from dual
  2  /

SYSDATE-51
-----------
01-Aou-2004

scott@ORA92> create or replace function Func1
  2    (p_date VARCHAR2)
  3    return date
  4  as
  5    <b>PRAGMA AUTONOMOUS_TRANSACTION;</b>
  6  begin
  7    EXECUTE IMMEDIATE 'ALTER SESSION SET NLS_DATE_LANGUAGE="AMERICAN"';
  8    return TO_DATE (p_date, 'dd-Mon-yy');
  9  end Func1;
 10  /

Function created.

scott@ORA92> show errors
No errors.
scott@ORA92> set serveroutput on
scott@ORA92> declare
  2    retval DATE;
  3  begin
  4    select FUNC1 ('01-Aug-04' ) into retval from dual;
  5    dbms_output.put_line (retval);
  6  end;
  7  /
01-Aug-2004

PL/SQL procedure successfully completed.
Re: ORA-14552: cannot perform a DDL, commit or rollback inside a query or DML [message #47823 is a reply to message #47820] Tue, 21 September 2004 23:27 Go to previous messageGo to next message
Shampa Srivastava
Messages: 9
Registered: August 2004
Junior Member
It worked!
Thanks Barbara.
U again helped!
Re: ORA-14552: cannot perform a DDL, commit or rollback inside a query or DML [message #47826 is a reply to message #47823] Wed, 22 September 2004 05:37 Go to previous messageGo to next message
shoblock
Messages: 325
Registered: April 2004
Senior Member
to_date takes a 3rd optional param. you could do this instead:

create or replace function Func1
(p_date VARCHAR2) return date as
begin
return TO_DATE (p_date, 'dd-Mon-yy',
'NLS_DATE_LANGUAGE = American');
end Func1;
/
Re: ORA-14552: cannot perform a DDL, commit or rollback inside a query or DML [message #47910 is a reply to message #47826] Thu, 30 September 2004 21:45 Go to previous message
Shampa Srivastava
Messages: 9
Registered: August 2004
Junior Member
This could have been good option, but it does not work!
SELECT TO_DATE('02-08-04','dd-mm-yy','NLS_DATE_LANGUAGE = FRENCH') FROM dual

Ans. 08/02/2004
Previous Topic: sql worksheet
Next Topic: selecting mutually exclusive rows
Goto Forum:
  


Current Time: Thu May 02 01:41:21 CDT 2024