powered by simpleCommunicator - 2.0.59     © 2025 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / IBM DB2, WebSphere, IMS, U2 [игнор отключен] [закрыт для гостей] / Использование EXISTS в процедуре
4 сообщений из 4, страница 1 из 1
Использование EXISTS в процедуре
    #36479491
Павел Гужанов
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
пытаюсь создать процедуру
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
CREATE PROCEDURE TEMP.UPD_ONEADDR
  ()
  SPECIFIC TEMP.PD_ONEADDR
  MODIFIES SQL DATA 
  NOT DETERMINISTIC
  LANGUAGE SQL
  ------------------------------------------------------------------------
-- SQL Procedure                                                        
------------------------------------------------------------------------
P1: BEGIN
 FOR addr as select insurance_number, B_address from temp.address_
 /* адрес рождения */
 	 if exists (select oneaddress from form.address where id_person=(select id_person from form.natural where insurance_number=addr.insurance_number and end_date is null) and type='B') then
 	 	if select oneaddress from form.address where id_person=(select id_person from form.natural where insurance_number=addr.insurance_number and end_date is null) and type='B'=null then
	  	   update form.address set oneaddress=addr.b_address, start_date=(select start_date from form.natural where insurance_number=addr.insurance_number and end_date is null) 
		   		  where id_person=(select ID_person from form.natural where insurance_number=addr.insurance_number and end_date is null);
	 	end if;
	 else 
	 insert into form.address (ID_person, oneaddress, type, start_date) values ((select ID_person from form.natural 
	 		where insurance_number=addr.insurance_number and end_date is null), addr.b_address, 'B', (select stare_date from form.natural 
	 		where insurance_number=addr.insurance_number and end_date is null));
 	 end if;
 END FOR;
END P1
  ;

При попытке выполнить скрипт получаю ошибку "Неправильный элемент "exists".
Разве нельзя использовать EXISTS в конструкции IF?
Если нельзя, то подскажите, как быть в таком случае, если можно, то что я делаю не так?
...
Рейтинг: 0 / 0
Использование EXISTS в процедуре
    #36480025
Павел Гужанов
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Разобрался :о)). Надо синтаксис изучать...

Спасибо всем, кто собирался помочь :о))
...
Рейтинг: 0 / 0
Использование EXISTS в процедуре
    #36481129
BuryCommoner
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Павел Гужанов
Код: plaintext
1.
2.
3.
	 insert into form.address (ID_person, oneaddress, type, start_date) values ((select ID_person from form.natural 
	 		where insurance_number=addr.insurance_number and end_date is null), addr.b_address, 'B', (select stare_date from form.natural 
	 		where insurance_number=addr.insurance_number and end_date is null));

можно написать попроще:
Код: plaintext
1.
2.
3.
4.
INSERT INTO form.address (id_person, oneaddress, type, start_date)
SELECT id_person, addr.b_address, 'B', stare_date
FROM form.natural
WHERE insurance_number = addr.insurance_number AND end_date IS NULL;

---------------------------------------------------------
IS NULL OR NOT IS NULL
...
Рейтинг: 0 / 0
Использование EXISTS в процедуре
    #36481157
Victor Metelitsa
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
А ещё обязательно про MERGE почитайте.
...
Рейтинг: 0 / 0
4 сообщений из 4, страница 1 из 1
Форумы / IBM DB2, WebSphere, IMS, U2 [игнор отключен] [закрыт для гостей] / Использование EXISTS в процедуре
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]