0

I have a problem with my code (bellow), with assumption the path 'E:\Oracle\test' doesn't exist (the psychical folder doesn't exist), so it should go to the error exception handler and write an error log, but it doesn't. Instead it successfully create the Oracle Directory, why does this happen? where do my code went wrong?

Can someone please help me, thanks a lot The database is Oracle 11g

DECLARE
var1 VARCHAR2(2000) := 'somepath';
var2 VARCHAR2(2000) := 'directoryname';
err  VARCHAR2(2000);

BEGIN
file_path_ := 'E:\Oracle\test\' || var1 || '\';
temp_dir_ := 'TEST_DIR_' || var2;
plsql_block_ := 'CREATE OR REPLACE DIRECTORY ' || temp_dir_ || ' AS ' || '''' ||file_path_ || '''';
EXECUTE IMMEDIATE plsql_block_;

SAVEPOINT Start_Trans;

<some code here>

EXCEPTION
WHEN OTHERS THEN
ROLLBACK TO Start_Trans;
err := substr(SQLERRM,1,2000);
Write_Log('ERROR', var1, err_);

END;

1 Answer 1

1

The created directory in the Oracle database is just an alias for the real thing on disk. Oracle doesn't verify that the directory you specify actually exists.

Sign up to request clarification or add additional context in comments.

3 Comments

But, when I simply execute CREATE OR REPLACE TEST_DIR AS 'E:\Oracle\Test\' (which the physical folder doesn't exist) it does returns an error
Strange, should not make a difference. Does the exception occur when the directory is first created (so no replace)?
@erwin Can you add the "bad" code and the error message it generates? On my test database I can certainly create a directory with a bad path and get no error messages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.