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

  • SEARCH
  • Home
  • 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 7088949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:51:48+00:00 2026-05-28T07:51:48+00:00

I am a beginner to SQL, so bear with me. I’m trying to create

  • 0

I am a beginner to SQL, so bear with me.

I’m trying to create a trigger in SQL. This code is giving me trouble:

select brw.borage, bt.agelower, bt.ageupper 
into borage, minage, maxage
from borrower brw
  inner join loan ln on ln.borid = brw.borid
  inner join bookcopy bc on ln.bcid = bc.bcid
  inner join booktitle bt on bt.isbn = bc.isbn
where ln.bcid = :new.bcid
and ln.borid = :new.borid;
-- and ln.dateout = :new.dateout;

The primary key in the loan table is composed of “bcID”, “borID” and “dateOut”.
When I comment out the last line, I get the newly added line(s) to the table.
With the last line uncommented though, it won’t work!

I just get this error (with the line uncommented):

Row 34: ORA-01403: no data found
ORA-01403: no data found

meaning oracle did not find any rows that match the query criteria.

NOTE: When I uncomment the line, I also remove the semicolon above it.

  • 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-05-28T07:51:48+00:00Added an answer on May 28, 2026 at 7:51 am

    OK. First off, a row-level trigger on table A should not query table A. In general, doing so is going to generate an “ORA-04091: table is mutating” error. Since your trigger is defined on LOAN, the query should not reference the LOAN table. It should only reference the data for the current row in the :NEW record.

    That being the case, you probably want something like this (note that I’m guessing about the cardinality of the relationships between the tables here)

    select brw.borage
      into borage
      from borrower brw
     where brw.borid = :new.borid;
    
    select bt.agelower, bt.ageupper 
      into minage, maxage
      from bookcopy bc on :new.bcid = bc.bcid
           inner join booktitle bt on bt.isbn = bc.isbn;
    

    You could combine the two queries but I don’t see an easy way to do that without making the result more complex than you probably want.

    Additionally, you really want to avoid having local variables that share the name of a column in your database (like borage). That tends to generate rather puzzling scope resolution bugs. For example, using the SCOTT.EMP table

    There are no employees with an EMPNO of -17

    SQL> select count(*)
      2    from emp
      3   where empno = -17;
    
      COUNT(*)
    ----------
             0
    

    But when I write a simple PL/SQL block that tries to count the number of employees with an EMPNO of -17, the result I get is 14. Can you spot the bug?

    SQL> ed
    Wrote file afiedt.buf
    
      1  declare
      2    empno integer := -17;
      3    cnt   integer;
      4  begin
      5    select count(*)
      6      into cnt
      7      from emp e
      8     where e.empno = empno;
      9    dbms_output.put_line( cnt );
     10* end;
    SQL> /
    14
    
    PL/SQL procedure successfully completed.
    

    The problem is that when I wrote e.empno = empno, I clearly intended the left-hand side of the expression to reference the EMPNO column in the EMP table and the right-hand side of the expression to reference the local variable EMPNO. Unfortunately for me, however, Oracle resolves the unqualified EMPNO first to a column in the table and only then to the local variable of the same name. If you’re using named PL/SQL blocks, you can work around that by using the name of the block as the alias for the local variable but virtually no one ever does that.

    Instead, in order to avoid these sorts of problems, most developers will use some sort of distinctive prefix for variable names. For example, I use P_ as the prefix for parameter names, L_ as the prefix for local variables, and G_ as the prefix for package global variables. That’s a relatively common convention but other conventions exist. The important thing is just to have some way of ensuring that you never have a local variable and a column name that use the same name.

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

Sidebar

Related Questions

This is a beginner question, I have to create some SQL Reports with business
SQL Server Beginner question: I'm trying to introduce a computed column in SQL Server
I am a beginner in SQL Functions. What is the best way to create
I'm a beginner in sql and I am doing this through a php document.
im a total beginner in web programming. Im trying to create a simple website
I am a beginner and have a basic question. I recently added this code
am a beginner in C#. am trying to create a website i have a
I am a beginner SQL user (not formally trained; OJT only) and need some
I'm a beginner with SQL and am working on one of my first databases.
A beginner question, bear with me: I'm just wondering under what circumstances one should

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.