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 7986771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:56:55+00:00 2026-06-04T11:56:55+00:00

I’m using PL/SQL, and I would like to check if a record exists in

  • 0

I’m using PL/SQL, and I would like to check if a record exists in a table, I’ve tried using when exists or if not exists, but I end up with exception.

Select name from nameTable where name = nameFromArgument;

When the procedures starts, and I put in a wrong name, which is not in the database I’m getting an error, can’t even handle it

I’ve tried something like this:

PL/SQL check if query returns empty

edit:

sorry, the select I’ve put before was just an example, the whole code [ sorry for names of variables… ] is here:

CREATE OR REPLACE
PROCEDURE SELLSTOCKS
( IloscAkcji IN NUMBER
, NazwaAkcji IN VARCHAR2
, IdRachunkuMaklerskiego IN NUMBER
)  AS
Bledna_ilosc EXCEPTION;
Bledna_nazwa EXCEPTION;
amount NUMBER;
stocksCash number;
idRachunku number;
stocksOnDealerSide number;
temp number;
tempus akcje_uzytkownika.nazwa % type;
BEGIN

--Select nazwa into tempus from akcje_uzytkownika where nazwa = nazwaakcji;
--dbms_output.put_line(tempus);

  dbms_output.put_line('pre');
 select nazwa into tempus from akcje_uzytkownika where nazwa = nazwaakcji;
 dbms_output.put_line('pre2');
 if tempus!=null then
    if ( iloscakcji> amount) THEN
  raise Bledna_ilosc;
  else
  select ilosc, cena_sztuki into amount, stockscash from akcje_uzytkownika where nazwa= NazwaAkcji and id_rachunku_maklerskiego= IdRachunkuMaklerskiego;
 dbms_output.put_line(amount);
 dbms_output.put_line(stockscash);
  amount :=amount - iloscakcji;
  dbms_output.put_line(amount);
  update akcje_uzytkownika set ilosc= amount  where nazwa=NazwaAkcji and  id_rachunku_maklerskiego= idrachunkumaklerskiego;
  stockscash:= iloscAkcji * stocksCash;
  dbms_output.put_line(stockscash);
  select id_rachunku into idrachunku from rachunek_maklerski where id_rachunku_maklerskiego= idrachunkumaklerskiego; 
  temp:=SALDOUPDATE(stockscash, idrachunku);
  select ilosc into stocksOnDealerSide from akcje where nazwa = nazwaAkcji;
  stocksOnDealerSide := stocksondealerside+ iloscakcji;
  dbms_output.put_line(stocksOnDealerSide);
  update akcje set ilosc = stocksondealerside where nazwa = nazwaAkcji;
  end if;
  else
  dbms_output.put_line('post');
  end if;
EXCEPTION

  when Bledna_ilosc then
  dbms_output.put_line('Bledna ilosc');
  when Bledna_nazwa then
  dbms_output.put_line('Bledna nazwa');

END SELLSTOCKS;

I’m using oracle sql developer 1.5.5

BEGIN

--Select nazwa into tempus from akcje_uzytkownika where nazwa = nazwaakcji;
--dbms_output.put_line(tempus);

  dbms_output.put_line('pre');
  select nazwa into tempus from akcje_uzytkownika where nazwa = nazwaakcji;
  dbms_output.put_line('pre2');
  exception when no_data_found then
  raise no_data_found;

-- is this the right place?

  select ilosc, cena_sztuki into amount, stockscash from akcje_uzytkownika where nazwa= NazwaAkcji and id_rachunku_maklerskiego= IdRachunkuMaklerskiego;
  dbms_output.put_line(amount);
  dbms_output.put_line(stockscash);
  amount :=amount - iloscakcji;
  dbms_output.put_line(amount);
  if ( iloscakcji> amount) THEN
  raise Bledna_ilosc;
  else
  update akcje_uzytkownika set ilosc= amount  where nazwa=NazwaAkcji and  id_rachunku_maklerskiego= idrachunkumaklerskiego;
  stockscash:= iloscAkcji * stocksCash;
  dbms_output.put_line(stockscash);
  select id_rachunku into idrachunku from rachunek_maklerski where id_rachunku_maklerskiego= idrachunkumaklerskiego; 
  temp:=SALDOUPDATE(stockscash, idrachunku);

……..

  • 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-04T11:56:56+00:00Added an answer on June 4, 2026 at 11:56 am

    You have four main things that are wrong (that I can see).

    Firstly, tempus!=null will never work. As null is the absence of information you can’t use the (in)equality operator when checking for nulls. Non-existence != non-existence. The correct syntax is to use is null, or in your case tempus is not null.

    Secondly, if ( iloscakcji> amount) THEN will never evaluate to true as you don’t initialise the value amount. A number cannot be greater than null as it doesn’t exist. You have to initialise the variable amount. Maybe you meant the next select statement to be above this?

    Thirdly, all of your select ... into ... statements are into single variables – not user defined table-types. This means that if 0 rows are returned by your query a no_data_found exception will be raised. If more than one row is returned a too_many_rows exception will be raised.

    If you’re only expecting at most one row then you don’t need to worry too much about too_many_rows. This should really be enforced by a unique constraint on your table if possible. For example I would expect that nazwa should be unique on akcje_uzytkownika.

    no_data_found is slightly different and is, I expect, what you meant to by tempus != null. Assuming that amount has been initialised to a value this can be re-written as:

    begin
    
        -- do some stuff    
        begin
    
           select nazwa into tempus from akcje_uzytkownika where nazwa = nazwaakcji;
    
        -- If there-s no data catch the exception.
        exception when no_data_found then
           if ( iloscakcji > amount) then
              raise Bledna_ilosc;
           end if;
    
        end;        
        -- do some more stuff
    
    end;
    

    Lastly, and it’s not really a mistake but, your code is fairly unreadable. I would consider using a lot more whitespace so that you can see what’s going on.

    P.S. By Oracle version I meant 11gr2 or 10g etc but it doesn’t make any difference in this case.

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

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the

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.