The procedure for anonymous block PL SQL Exception Handling problem?

Hello

I am a newbie to PL/SQL.

I'm having trouble when trying to manage exceptions for block anonymous PLSQL procedure I created will format any block of 10 digits and format it in the next (XXX) - XXX - XXXX.

I need.

1. the handle if there is more than 10 digits

2. the handle if there are less than 10 numbers

3. the handle if there is no inappropriate character (no number)

4. the handle if there is no characters.

I created the following procedure.  However, my if/else attempts logic or raise exceptions have create errors so far.

Please enter the following code.

create or replace

PROCEDURE format_phone

(

p_phne_no IN OUT VARCHAR2

) IS

extra_digits EXCEPTION; -Number must be a 10-digit number. Please enter the 10-digit

no_digits EXCEPTION; -Please enter numbers there is no registration numbers.

invalid_char EXCEPTION; -You entered a wrong character please enter numbers 0-9.

less_digits EXCEPTION; -You have entered too few figures. Please enter a 10-digit phone number.

BEGIN

p_phne_no: ='(')

|| SUBSTR (p_phne_no, 1, 3).

')'

||' -'||

SUBSTR (p_phne_no, 4, 3)

||' -'||

SUBSTR(p_phne_no,7);

-DBMS_OUTPUT. Put_line (p_phne_no);

EXCEPTION

WHEN invalid_char

THEN

dbms_output.put_line ('you have entered an inappropriate character please enter 0-9 numeric values.');

WHEN no_digits

THEN

dbms_output.put_line (' Please enter the numbers there is no registration numbers.) ") ;

WHEN less_digits

THEN

dbms_output.put_line (' you entered too few figures.) Please enter a 10-digit phone number. ") ;

WHEN extra_digits

THEN

dbms_output.put_line (' you entered too many numbers.) Must include a 10-digit number. Please enter the 10 digits. ") ;

END format_phone;

Thank you for your concern.

>>

OK so I need to declare a variable, then pass p_phne_no parameter to this variable.

You could, Yes, but you don't need to. You could simply test the value of the passed parameter

Length (p_phne_no) > 10...

> - I need 3 scenarios more in which I test Val., which is always equal to the parameter p_phne_no?

Yes (or just test p_phne_no).

Tags: Database

Similar Questions

  • How to display the value of the variable for bottom of pl/sql

    How to display the value of the variable for bottom of pl/sql

    declare

    V_1 number: = 10;

    V_2 number: = 20;

    V_3 number: = 30;

    v_4 number: = 40;

    v_5 number: = 50;

    test varchar2 (100);

    Start

    I'm in 1.5

    loop

    test: = "v_" | I have;

    dbms_output.put_line(i||) e > ' | test);

    end loop;

    end;

    /

    How to get below output:

    1 > v_1

    2 > v_2

    3 > v_3

    4 > v_4

    5 > v_5

    But I want to output of

    1 > 10

    2 > 20

    3 > 30

    4 > 40

    5 > 50

    Hello

    You cannot reference variables as you did and get the value of the variable. Use pretty collection.

    set serveroutput on size 2000
    declare
      type      number_table is table of number;
      numbers   number_table := number_table(10, 20, 30, 40, 50);
    begin
      for i in numbers.first .. numbers.last
      loop
        dbms_output.put_line(i || '->' || numbers(i));
      end loop;
    end;
    /
    
    anonymous block completed
    1->10
    2->20
    3->30
    4->40
    5->50
    

    See the Collections of PL/SQL and Records http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/composites.htm#LNPLS005

  • What is the procedure for upgrading Thunderbird ESR 17.0.7 at 31.6 on Mac OSX 10.10.2?

    What is the procedure for upgrading from Thunderbird ESR 17.0.7 at 31.6 (last public version) on Mac OSX 10.10.2?

    Is it as simple as install new version and then run to see all local folders and my email and its folders from IMAP to my company as before the upgrade?

    Thank you

    Create a full backup of your Thunderbird profiles folder.
    Uninstall the old version of ESR.
    Download the latest version from https://www.mozilla.org/en-US/thunderbird/all.html and install it.

  • What is the procedure for the use of two monitors?

    What is the procedure for the use of two monitors?

  • HEEELP: Re-create the procedure for the Essbase.sec file in 11.1.2.0

    Hello
    What is the procedure for recreating the file Essbase.sec in 11.1.2.0 Essbase environment... In older versions, it has been used to remove Essbase.sec, start the Essbase server and it has been recreated a file void essbase.sec... But in 11.1.2.0 with Shared services... is the procedure? If it is deleted from the file essbase.sec... start Essbase Service recreates and will update SSP Outlook2003?


    Please someone help...

    Thank you...

    Hi Alex,

    Unfortunately, I have about 20 questions to ask in order to really be able to provide useful guidance, but at least I recommend checking out 'The Essbase security file management' section of the Essbase DBAG and eventually the Oracle Hyperion Enterprise Performance Management System Backup and Recovery Guide.

    11.1.2.1 SER60-online http://docs.oracle.com/cd/E17236_01/epm.1112/esb_dbag/frameset.htm?launch.html

    11.2.1.1-online http://docs.oracle.com/cd/E17236_01/epm.1112/epm_backup_recovery_11121/frameset.htm?launch.html BURG

    Thank you

    Todd Rebner

  • Version of 5.0.2.00.07(online à APEX) - error in the execution of a stored procedure through anonymous block

    DECLARE

    the stored procedure varchar2 (25);

    BEGIN

    -DBMS_OUTPUT. Put_line ("enter the name of the procedure :'||: procname");

    the stored procedure: =: procname;

    DBMS_OUTPUT. Put_line (' procedure :'|| stored procedure);

    stored procedure.

    END;

    : procname is a variable binding in the apex to switch the running value.

    apex-bind_var.png

    This is the error I get

    ORA-06550: line 7, column 2:

    PLS-00221: "STORED procedure" is not a procedure or is not defined

    ORA-06550: line 7, column 2:

    PL/SQL: Statement ignored

    5the stored procedure: =: procname;

    6 DBMS_OUTPUT. Put_line (' procedure :'|| stored procedure);

    7. the stored procedure.

    8 END;

    SmtWtL wrote:

    DECLARE

    the stored procedure varchar2 (25);

    BEGIN

    -DBMS_OUTPUT. Put_line ("enter the name of the procedure :'||: procname");

    the stored procedure: =: procname;

    DBMS_OUTPUT. Put_line (' procedure :'|| stored procedure);

    stored procedure.

    END;

    : procname is a variable binding in the apex to switch the running value.

    This is the error I get

    ORA-06550: line 7, column 2:

    PLS-00221: "STORED procedure" is not a procedure or is not defined

    ORA-06550: line 7, column 2:

    PL/SQL: Statement ignored

    5. the stored procedure: =: procname;

    6 DBMS_OUTPUT. Put_line (' procedure :'|| stored procedure);

    7. the stored procedure.

    8 END;

    What you're trying to achieve?

    Bind variables cannot be used for the dynamic execution of stored programs. Dynamic SQL using lexical rather than bind substitution must be used to run when the program name is not known until execution of the programs.

    declare
      sproc varchar2(25);
    begin
      sproc := :procname;
      dbms_output.put_line('procedure:'||sproc);
      execute immediate 'begin ' || sproc || '; end;'; -- DO NOT DO THIS!
    end;
    

    It is a fundamental design flaw and a security disaster. It's stops essential compilation controls is performed and is open to attack by SQL injection and other security vulnerabilities. There is no good reason to do this.

  • How to use a button to fire the stored procedure or anonymous block PLSQL

    I am converting an application forms at the APEX, and which was easy became almost unbelievably difficult. I have a page that represents a record with an element called "history_rec". It is an element of the checkbox. Clicking on it causes the column for this record to be filled with the letter 'H', indicating that this recording is now historical and not assets. I also have this page a button that says "Renew Record." This button redirects to the current page and sets the value of 5 elements of the page on the values of the record being replaced with the new record.

    (This, incidentally, is an insurance system of follow-up to the loan guarantees. The insurance must be renewed annually, and this system is used to ensure that it is.)

    I also want the button to trigger a process that updates the old record by filling in the history_rec column. To do this, I created a process called "make_history" that contains the following SQL code:

    "Ensure the update
    Set history_rec = "H".
    "where insureseq =: P22_INSURESEQ.

    I chose for the 'process' Point ' on demand: run this process when requested by AJAX. "

    Is it possible my button 'Renew the Record' and if so, how? If this is not the case, how should I proceed?

    Doug,

    I'm glad you've made any progress.

    What process throws the error, it is the last process?

    "Error Unable to fetch row ' with this code ORA" ORA-01403: no data found. "

    Is page 21 page that you develop?

    I want to make is that demand for return on page 21

    What you already have for the branches Page?

    Jeff

  • DBMS_METADATA. GET_DDL for all the procedures for a schema

    I'm trying to capture all the DDLS procedure for CUSTOM schema

    I use 11g on Linux.

    I have run this command...
    SELECT dbms_metadata. GET_DDL('PROCEDURE',,'CUSTOM') FROM DUAL;

    And this error occurs:
    ORA-31600: input value invalid NULL for the parameter VALUE in function SET_FILTER
    ORA-06512: at "SYS." Dbms_metadata", line 4018
    ORA-06512: at "SYS." Dbms_metadata", line 5843
    ORA-06512: at line 1


    Thanks in advance.

    user13716252 wrote:
    Now it works but I have only the first row in SQL PLUS...

    Select dbms_metadata. GET_DDL (u.object_type, u.object_name, 'SAPSR3')
    u dba_objects
    where type_objet = 'PROCEDURE '.
    and the owner = "SAPSR3";

    How to bring back the whole procedure?

    SQL > SET LONG 32000

  • Way of array to the procedure for questions

    Hi all

    I created an object type as a varray and passage to the procedure

    I get the error message can help any one

    Start
    POPULATE_TABLE_TEST ('AAA', 'AA', 'AA');
    end;
    POPULATE_TABLE_TEST ('AAA', 'AA', 'AA');
    *
    ERROR on line 2:
    ORA-06550: line 2, column 1:
    PLS-00306: wrong number or types of arguments in the call to 'POPULATE_TABLE_TEST '.
    ORA-06550: line 2, column 1:
    PL/SQL: Statement ignored

    Thanks in advance
    CREATE TABLE TABLE_TEST
    (ID_NO NUMBER(10) , 
    id_NAME VARCHAR2(10) , 
    ATTRIBUTE1 VARCHAR2(10), 
    ATTRIBUTE2 VARCHAR2(10)
    );
    
    select * from "TABLE_TEST"; 
    
    
    CREATE OR REPLACE TYPE T_TYPE IS OBJECT ( 
    id_NAME VARCHAR2(10), 
    ATTRIBUTE1 VARCHAR2(10), 
    ATTRIBUTE2 VARCHAR2(10) 
    ) ;
    
    Create or replace  type TB_T_TYPE as varray(200) of  T_TYPE ;
    
    
    CREATE OR REPLACE
    PROCEDURE POPULATE_TABLE_TEST (EXAMPLE IN TB_T_TYPE) AS 
    
    begin 
    
    FOR I IN 1..EXAMPLE.COUNT LOOP
    DBMS_OUTPUT.PUT_LINE(TREAT(EXAMPLE(I) AS T_TYPE).ID_NAME);
    DBMS_OUTPUT.PUT_LINE(TREAT(EXAMPLE(I) AS T_TYPE).ATTRIBUTE1);
    DBMS_OUtPUT.PUT_LINE(TREAT(EXAMPLE(I) AS T_TYPE).ATTRIBUTE2);
    /*insert into TABLE_TEST(id,name,attribute1,attribute2) 
    values (l_t_seq(i), 
    treat(example(i) as T_TYPE).NAME, 
    treat(example(i) as T_TYPE).ATTRIBUTE1, 
    treat(example(i) as T_TYPE).ATTRIBUTE2 
    );*/ 
    end loop;
    end; 

    This one works :))

    begin
        POPULATE_TABLE_TEST(TB_T_TYPE(T_TYPE('AAA','AA','AA')) );
    end;
    
  • help for anonymous block

    Hi friends
    I am developing anonymous blocks that displays the message on the screen, like "hello world" "is SYSDATE today" and "tomorrow is SYSDATE + 1". To make me try to develop anonymous block, but it shows me error... so friends can you help me with this...

    Set SERVEROUTPUT on
    declare
    p_text varchar2 DEFAULT "hello world";
    P_date date default sysdate;
    P_next_date date default sysdate + 1;
    Start
    DBMS_OUTPUT. PUT_LINE (|) P_text);
    DBMS_OUTPUT. Put_line (' today's :'||) P_date);
    DBMS_OUTPUT. Put_line ("tomorrow is :'|| p_next_date);
    end;
    /


    Thanks in advance
    Rommy

    Hi, Rommy,

    Always format your code. Dash to show the main sections (DECLARED, BÉGIN, etc..)
    Type these 6 characters
    {code}
    (small letters only, inside curly braces) before and after the formatted text, to keep the spacing when posting on this site.

    DECLARE
         p_text          VARCHAR2 (50)  DEFAULT 'hello world';
         P_date          DATE            DEFAULT SYSDATE;
         P_next_date     DATE            DEFAULT SYSDATE + 1;
    BEGIN
         DBMS_OUTPUT.PUT_LINE (P_text);
         DBMS_OUTPUT.PUT_LINE ('today is: ' || TO_CHAR (P_date, 'Dy DD-Mon-YYYY'));
         DBMS_OUTPUT.PUT_LINE ('Tommorrow is: ' || TO_CHAR (p_next_date, 'Dy DD-Mon-YYYY'));
    END;
    /
    

    When you declare a VARCHAR2 variable, you must specify the maximum length.

    The | operator is used between two string expressions; Looks like you forgot the first operand in one place.

    Using a DATE where we expect a VARCHAR2 (as an operand to |, for example) is not technically an error, but it's a bad habit. TO_CHAR to create a string in any format you want.

  • Cannot get the procedure for d3dperf_setoption (d3d9.dll) - Skype address does not work

    I face this big mistake:-failed to get address of procedure for d3dperf_setoption (d3d9.dll)

    ... when I start my pc, then show this msg my Skype software does not work. installation of the software is no longer. Please solve my problem. thanking you...

    Hello jassi8,

    Often we see errors as the result of a program from loading at startup.

    To solve these, we use the clean boot troubleshooting.

    The following describes this process:

    http://support.Microsoft.com/kb/310353

    http://support.Microsoft.com/kb/316434

    Best regards

    Matthew_Ha

  • See the version for Cisco Blocker

    Hello

    As I am not really tech savvy here, we currently have a problem where we need to check a serial number for blocker of Cisco. However, the customer says that they didn't show version and we provided instead the system state information. However, her, we can derive the correct serial No. Anyone who is familiar with how to interpret the State of the system to get the correct serial number for Cisbo Blocker? Or are there other options that the customer can give us to get the correct serial number?

    I enclose the status of the system provided by the customer.

    Thank you

    Cathy

    Spare part

    BV277F1 is a valid serial number for blocker of Cisco.

  • Urgent: How to remove all the cards for a crawler through SQL

    People,

    Hello! I am trying to remove the 2 million cards (must have been exceeded and makes the search index rebuild take days) in a single folder in the directory of knowledge on portal 6.1. To delete the folder ('apply later') working half yesterday and then all night with nothing connected to the PTSpy or the joblog, little or no CPU activity.

    Does anyone have a DB query that can zap cards for this crawler? I know how to select the cards for a particular ID on caterpillars, but don't understand how to remove properly such that all references to these maps in other tables are also deleted.

    Much appreciate!

    See you soon!

    Published by: Plumtree on January 21, 2009 07:28 (fixed an "oops")

    You are obviously looking for someone who did and tested before, which I did not... but when I delete a folder that the following occurs for each card:

    delete:
    PTFolderCards
    PTCards
    PTCardProperties
    PTCardSecurity
    PTCardStatistics
    PTMigration

    Update:
    PTInternalCardInfo (RefreshDate = null, ExpirationDate = null, RefreshRateUnits = null, RefreshRateNum = - 1, MissingDeleteUnits = null, MissingDeleteNum = null)

    PTCardStatus (indexing status set to 3)

  • PL/SQL exception handling and return values

    Hi all

    I use Oracle 10.2.0

    I have a problem in the return values of the procedures if there is no exception.

    For example:

    procedure a.
    (
    P_in number,
    p_out on varhar2
    )
    as
    p_valid varchar2 (10);
    number of p_no1;
    Select 1 in double p_no1;
    B (p_valid, p_no);
    exception when others then
    c (errmsg);
    end;
    put an end to;
    procedure B
    (
    p_in number,
    p_valid out varchar2
    )
    as
    fake number;
    Select 1 in double dummy;
    dummy cases = 1
    then
    p_valid = "OK".
    C (MSG);
    end;
    exception when others then
    p_valid = "OK".
    C (errmsg);
    end;

    end b;
    In the example if theres no exceptions or dummy = 1 in procedure B, then I need to return the value as 'OK' in the setting out of the parent procedure "A".

    I could not this value, returning null. How to get this...

    Please advice...

    TIA,

    ORCLDB wrote:
    Hi all

    I use Oracle 10.2.0

    I have a problem in the return values of the procedures if there is no exception.

    Ok

    The code you have posted is not valid code if you have forgotten some important things. However, we will make it simple...

    If you have a set OUT that will not be filled if an exception is thrown, unless it is set to NOCOPY.

    Example of...

    Here, we regularly parameter output and when an exception occurs in procedure B it REVIVAL of the exception to the procedure a...

    SQL> ed
    Wrote file afiedt.buf
    
      1  create or replace procedure B (p_in in number, p_valid out varchar2) as
      2    dummy number;
      3  begin
      4    select 1 into dummy from dual where p_in = 1;
      5    p_valid := 'OK';
      6  exception when others then
      7    p_valid := 'EXCEPTION';
      8    raise;
      9* end b;
    SQL> /
    
    Procedure created.
    
    SQL> create or replace procedure A (p_in in number) as
      2    v_valid varchar2(10);
      3  begin
      4    B(p_in, v_valid);
      5    dbms_output.put_line('Returned without exception: '||v_valid);
      6  exception when others then
      7    dbms_output.put_line('Returned with exception: '||v_valid);
      8    raise;
      9  end A;
     10  /
    
    Procedure created.
    
    SQL> exec a(1);
    Returned without exception: OK
    
    PL/SQL procedure successfully completed.
    
    SQL> exec a(2);
    Returned with exception:
    BEGIN a(2); END;
    
    *
    ERROR at line 1:
    ORA-01403: no data found
    ORA-06512: at "SCOTT.A", line 8
    ORA-06512: at line 1
    

    Obviously, when the procedure B raised an exception it went directly to the procedure exceptions A manager that indicates that an exception has happened and the value returned in the OUT parameter was NULL.

    Now, if procedure B just handles the exception rather than erect in...

    SQL> ed
    Wrote file afiedt.buf
    
      1  create or replace procedure B (p_in in number, p_valid out varchar2) as
      2    dummy number;
      3  begin
      4    select 1 into dummy from dual where p_in = 1;
      5    p_valid := 'OK';
      6  exception when others then
      7    p_valid := 'EXCEPTION';
      8* end b;
    SQL> /
    
    Procedure created.
    
    SQL> exec a(1);
    Returned without exception: OK
    
    PL/SQL procedure successfully completed.
    
    SQL> exec a(2);
    Returned without exception: EXCEPTION
    
    PL/SQL procedure successfully completed.
    

    Here, procedure B fills the output parameter and just returns execution to the block to execute procedure A, so A procedure isn't aware of no exception, but the output parameter does not contain the value B populated with.

    But if you want the procedure B to throw the exception and pass out a value in the output parameter, you must set the out parameter as NOCOPY...

    SQL> ed
    Wrote file afiedt.buf
    
      1  create or replace procedure B (p_in in number, p_valid out NOCOPY varchar2) as
      2    dummy number;
      3  begin
      4    select 1 into dummy from dual where p_in = 1;
      5    p_valid := 'OK';
      6  exception when others then
      7    p_valid := 'EXCEPTION';
      8    raise;
      9* end b;
    SQL> /
    
    Procedure created.
    
    SQL> exec a(1);
    Returned without exception: OK
    
    PL/SQL procedure successfully completed.
    
    SQL> exec a(2);
    Returned with exception: EXCEPTION
    BEGIN a(2); END;
    
    *
    ERROR at line 1:
    ORA-01403: no data found
    ORA-06512: at "SCOTT.A", line 8
    ORA-06512: at line 1
    
    SQL>
    

    Now, as in the first example, procedure B defines the output parameter and throws the exception, causing execution to go directly to the procedure A exception handler, but this time, A procedure return parameter value out.

    To understand the execution of blocks and managing exceptions take a look at this article...

    [PL/SQL 101: exception handling | http://forums.oracle.com/forums/thread.jspa?threadID=697262&tstart=50]

    ;)

  • ADF 11 g: exception handling problem

    Hi all

    Using Jdeveloper 11.1.1.2.0. I have a form of the ADF. The user will also be the primary key value. When I try to save the data by giving the primary key value that already exist.
    I'm more of exceptions in the Popup: -.

    Error
    Messages for this component are listed below.

    Error
    + Too many objects match the [RESERVE primary key] oracle.jbo.Key. +
    Error
    LocationType in RootAM.LocationAM1.LocationTypeVO1 attribute is required.
    Error
    LocationType in LocationTypeEO attribute is required.


    In the newspaper, I'm following exceptions: -.
    Exception = oracle.jbo.TooManyObjectsException: Houston-25013: too many objects match the [RESERVE primary key] oracle.jbo.Key.
    Exception = oracle.jbo.TxnValException: 27023 Houston: impossible to validate all the lines in a transaction.
    Exception = oracle.jbo.TxnValException: 27023 Houston: impossible to validate all the lines in a transaction.

    My requirement is to show a friendly message to the user as 'record already exists with the given value to < primary key field > ". I tried this by creating a class that extends the DCErrorHandlerImpl as below error handling custom: -.

    ' Public Sub reportException (DCBindingContainer bc, Exception ex) {}
    BindingContext ctx = bc.getBindingContext ();
    String err_code = null;
    System.out.println ("Exception =" + ex);
    If (ex instanceof TxnValException) {}
    Handle Houston-27023
    err_code = ((TxnValException) ex) .getErrorCode ();
    If (Integer (err_code) .intValue (new) == 27023) {}
    this.getDisplayMessage (ctx, ex);
    System.out.println ("Houston-27023 handshake');
    }
    }
    If (ex instanceof oracle.jbo.TooManyObjectsException)
    {
    FacesContext context = FacesContext.getCurrentInstance ();
    context.addMessage (null, new FacesMessage (FacesMessage.SEVERITY_ERROR, "record already exist", null));
    }
    }



    Even with above approach I get "Record already exists" instead of "too many objects correspond to the oracle of primary key. But still I'm getting following error in popup messages: -.
    Error
    LocationType attribute in RootAM.LocationAM1.LocationTypeVO1 is necessary.
    Error
    LocationType in LocationTypeEO attribute is required.

    (1) how can I remove the above popup messages. (2) and is there a better approach to exception handling then this in ADF 11 g?

    Thanks in advance,
    Vikram

    Published by: Vikram K on May 28, 2010 19:08

    That's the problem with the unfounded primary keys sequence.
    One way you can avoid cela in setting mandatory flag as false for this attribute of the entity.

    You can also catch the TooManyObjectsException in the setAttribute method in EOImpl and keep the generic exception handler.

    SID

    Published by: manieshsailoz on May 28, 2010 11:11

Maybe you are looking for

  • Mac e-mail issues

    I use Mac book pro, today I support by mistake on REBUILD button in my mail box and all of a sudden my Inbox emails are missing, well want to help me to recharge my Inbox emails.

  • Satellite A200 - BIOS update fails on a blue screen

    Hello I spent from Vista to XP. All works not well I read on this forum on the wire of Vetko, that members "pinteno" has managed to update its BIOS for XP. Please inform what files it uses and how it update its BIOS. I have the BIOS to version 1.40 o

  • Compatibility iPod Classic/El Capitan

    Hi guys! I'm about to upgrade my Mac OS X to the new El Capitan (it's a Mac 2012 environment). However I'm wondering if I can use my iPod Classic 80 GB (bought in 2008, do not know the sorry generation!) with him, smoothly and without problem as I do

  • Windows cannot check the updates. Vista Home Premium.

    I get the message "windows cannot check for updates error Code 80080005 code. Can someone tell me how to solve this problem?  Thanks in advance

  • My XP does not open. All I get is a black screen "Biostar".

    Could not get open in safe mode.   I did once, the first time.  Then, I select Safe mode, but chose something about "the last successful opening.    Now, the F8 key does nothing.   Stops at the black screen "Biostar".    Any suggestions?