Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2004
    Posts
    86

    Unanswered: Simple SQL question

    How would I exit from a sql script when performing the following check

    select count(user) into usercheck from all_users where name='DBO';

    if usercheck=0 then
    exit from the script;
    else
    ........

    end if;

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    The SQL language does NOT contain the "IF" construct.
    You'll need to use a different language; such as PL/SQL.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Feb 2004
    Posts
    86
    Yeah, that's what I'm using.....

  4. #4
    Join Date
    May 2004
    Location
    BA [ARG]
    Posts
    137
    Why don't you just use something like this?

    Code:
    begin
      select user from all_users where name='DBO';
      --your code here
      ....
    exception
      when NO_DATA_FOUND then null;
    end;

  5. #5
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool


    Actually what you need is something like this:
    Code:
    DECLARE USERCHECK NUMBER:=0;
    BEGIN
      SELECT COUNT(USER) INTO USERCHECK
        FROM ALL_USERS WHERE USERNAME='DBO';
      -- Your code here --
    EXCEPTIONS
      WHEN NO_DATA_FOUND THEN
          RAISE_APPLICATION_ERROR(-20001,'No user DBO found.');
    END;
    /
    -- Or more code here --

    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  6. #6
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    If I'm not wrong, you'll never trap the NO_DATA_FOUND with this code because COUNT will return 0 if user DBO doesn't exist.

  7. #7
    Join Date
    Sep 2004
    Location
    London, UK
    Posts
    565
    I'm not sure what you mean by an "sql script". Is this a SQL*Plus script or a PL/SQL procedure? How is it an SQL question?

  8. #8
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Cool

    Quote Originally Posted by Littlefoot
    If I'm not wrong, you'll never trap the NO_DATA_FOUND with this code because COUNT will return 0 if user DBO doesn't exist.
    Ooops, true -- bummer.
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •