0

I want to create an error message for an column

Suppose I have a column - "Employee Number" with datatype varchar2 in a table "xyz".

Now I'm importing a .csv or .txt file and there is also a column of "employee number" with datatype varchar2 but I need only number data in this column...

3
  • Please have a look at minimal reproducible example and then try to edit your question by adding some more informations (table structure, code, sample data, …). As is, it's hard to give you a good answer Commented Sep 12, 2018 at 7:19
  • 2
    If you only want numbers in that column, define it as number. Do not store numbers in varchar columns Commented Sep 12, 2018 at 7:35
  • actually i want to create my own exception in which it will show my error message for invalid datatype for particular column. Commented Sep 12, 2018 at 12:15

1 Answer 1

1

It depends on how you will import your data.

Oracle SQL*Loader

SQL loader can automatically check the input types for you, and raise appropriate error messages.

PL/SQL

If you choose to write your own import program in PL/SQL, then you can use Custom exception when you detect the case. It will look like follows:

 declare
    ex_custom EXCEPTION;
    PRAGMA EXCEPTION_INIT( ex_custom, -20001 ); -- here you define a custom exception (by id number)
  begin
    -- here you import...
    if error_detected then
      raise_application_error( -20001, 'Wrong type ' );
    end;
  exception  -- then handle your exception
    when ex_custom
    then
      dbms_output.put_line( sqlerrm || 'error' );
 end;
SQL> /
ORA-20001: Wrong type error

I definitely advise you to choose the sqlloader solution in your case.

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

1 Comment

Then you may use the second part of the answer.

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.