Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8930629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:55:56+00:00 2026-06-15T08:55:56+00:00

I have a students table in my Oracle database which has a field called

  • 0

I have a students table in my Oracle database which has a field called RECORD_NUMBER. This field is 8 characters long and I want to create a trigger to pad the left part out with 0s as it’s inserted. This is what I have so far:

create or replace
TRIGGER STUDENTS_RECORD_NUMBER_TRG 
BEFORE INSERT OR UPDATE OF RECORD_NUMBER ON TBL_STUDENTS 
FOR EACH ROW
BEGIN
  WHILE length(:new.RECORD_NUMBER) < 9
    LOOP
      :new.RECORD_NUMBER := LPAD(:new.RECORD_NUMBER,8,'0');
    END LOOP;
  NULL;
END;

However, when I try to insert a row the database connection locks up and I have to restart Oracle to use it again. Is it possible that this trigger is causing an infinite loop?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:55:58+00:00Added an answer on June 15, 2026 at 8:55 am

    If record_number is a varchar2(8), then length(:new.record_number) will always be less than 9 and your loop will iterate endlessly. But you don’t need a loop here, just call LPAD

    create or replace TRIGGER STUDENTS_RECORD_NUMBER_TRG 
      BEFORE INSERT OR UPDATE OF RECORD_NUMBER 
      ON TBL_STUDENTS 
      FOR EACH ROW
    BEGIN
      :new.RECORD_NUMBER := LPAD(:new.RECORD_NUMBER,8,'0');
    END;
    

    This assumes, of course, that it really makes sense to pad the data that is physically stored in the database rather than doing something like applying the LPAD in a view layer. Generally, I would expect that you’d be better served putting this sort of presentation logic in a view since views are great for implementing presentation logic. But this trigger should do what you’ve asked.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a table named students which have student details id,mark,name i want to
I have a table students with field ward_id and I have to create a
I have a text field in SQLite database, which I want the user to
i have a table Students which contains the following colums: Id,FirstName,LastName,Adress . The colum
I have a table that looks like this for about ~30 students: StudentID Course*
I have a database table named 'student' in which there is one column named
Hope my subject line was descriptive enough. Basically, I have a table called Students,
I'm trying to display all such rows of a table STUDENTS which have a
Say I have a table called students, containing a list of all the students.
Help a sqlite n00b out, please. I have two tables CREATE TABLE students (

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.