Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2003
    Posts
    24

    Question Unanswered: From SQL2000 to Oracle 8i

    This is an update command in SQL 2000. It works perfectly.

    UPDATE NPublic
    SET Class = NStates.Class,
    Format = NStates.Format,
    Parent = NStates.Parent,
    Child = NStates.Child,
    Name = NStates.Name,
    Description = NStates.Description
    FROM NPublic, NStates
    WHERE NStates.Id = NPublic.Id AND NStates.State=@id_source

    How can I do it with Oracle?

    Thanks.

  2. #2
    Join Date
    Jan 2003
    Posts
    24
    I found this code. I think it is Ok.

    DECLARE
    CURSOR trip_cursor IS
    SELECT
    bt_id_pk,
    bt_duration
    FROM
    business_trips
    WHERE
    bt_id_pk = 23
    FOR UPDATE OF bt_id_pk, bt_duration;
    BEGIN
    FOR trip_record IN trip_cursor LOOP
    UPDATE business_trips
    SET bt_duration = 5
    WHERE CURRENT OF trip_cursor;
    END LOOP;
    COMMIT;
    END;

  3. #3
    Join Date
    Jan 2003
    Posts
    24
    I found this code. I think it is Ok.

    DECLARE
    CURSOR trip_cursor IS
    SELECT
    bt_id_pk,
    bt_duration
    FROM
    business_trips
    WHERE
    bt_id_pk = 23
    FOR UPDATE OF bt_id_pk, bt_duration;
    BEGIN
    FOR trip_record IN trip_cursor LOOP
    UPDATE business_trips
    SET bt_duration = 5
    WHERE CURRENT OF trip_cursor;
    END LOOP;
    COMMIT;
    END;

  4. #4
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    Originally posted by nmoreno
    I found this code. I think it is Ok.

    DECLARE
    CURSOR trip_cursor IS
    SELECT
    bt_id_pk,
    bt_duration
    FROM
    business_trips
    WHERE
    bt_id_pk = 23
    FOR UPDATE OF bt_id_pk, bt_duration;
    BEGIN
    FOR trip_record IN trip_cursor LOOP
    UPDATE business_trips
    SET bt_duration = 5
    WHERE CURRENT OF trip_cursor;
    END LOOP;
    COMMIT;
    END;
    You don't need to use cursors and loops to do this, just a different UPDATE syntax:

    UPDATE NPublic
    SET (Class,Format,Parent,Child,Name,Description) =
    ( SELECT NStates.Class,
    NStates.Format,
    NStates.Parent,
    NStates.Child,
    NStates.Name,
    NStates.Description
    FROM NStates
    WHERE NStates.Id = NPublic.Id AND NStates.State=:id_source
    );

  5. #5
    Join Date
    Jan 2003
    Posts
    24
    Ok, thank you very much!!!!!!!!!!!!!!!

Posting Permissions

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