Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / Oracle [игнор отключен] [закрыт для гостей] / Проход по XML existsNode / 2 сообщений из 2, страница 1 из 1
20.08.2018, 18:25
    #39690644
greenbook
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Проход по XML existsNode
Прошу помощи у более опытных коллег.
Есть XML:
Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
<?xml version="1.0" encoding="utf-8"?>
<career_reserve SPXML-FORM="x-local://wtv/wtv_career_reserve.xmd">
	<code>0101010101</code>
	<start_date>2018-08-20T12:34:03+00:00</start_date>
	<status>active</status>
	<person_id>0x5AB2D213744A433D
		<sd>
			<fullname>01 Тест ОК 1</fullname>
			<position_name>01 тест ОК</position_name>
			<position_id>0x5AB2D1CD77C72368</position_id>
			<org_name>34</org_name>
		</sd>
	</person_id>
	<position_type>adaptation</position_type>
	<position_name>01 тест ОК</position_name>
	<tutors>
		<tutor>
			
		</tutor>
		
	</tutors>
	<forbid_tasks_edit>0</forbid_tasks_edit>
	<tasks>
		<task>
			<id>puaicv</id>
			<name>Оформить трудовые отношения</name>
			<type>task</type>
			<status>plan</status>
			<plan_date>2018-08-20T00:00:00+00:00</plan_date>
			<typical_development_program_id>0x5705A33B37</typical_development_program_id>
			<desc> СБ.</desc>
			<object_type>course</object_type>
			<type_document>portal_doc</type_document>
			<link_document>http://</link_document>
			<forbid_task_portal_edit>0</forbid_task_portal_edit>
		</task>
		<task>
			<id>gket8e</id>
			<name>Познакомиться с историей развития</name>
			<type>task</type>
			<status>active</status>
			<typical_development_program_id>0x5B4DF705AB37</typical_development_program_id>
			<tutor_id>0x573DEF1106B3654F</tutor_id>
			<desc>Изучить:</desc>
			<object_type>course</object_type>
			<type_document>portal_doc</type_document>
			<link_document>http://</link_document>
			<forbid_task_portal_edit>0</forbid_task_portal_edit>
		</task>
		<task>
			<id>96ar</id>
			<name>Введение в Х5 Retail Group</name>
			<type>learning</type>
			<status>failed</status>
			<typical_development_program_id>0x5B4DF3F705A33B37</typical_development_program_id>
			<object_type>course</object_type>
			<object_id>0x52732E2F6</object_id>
			<active_learning_id>0x586253BC0</active_learning_id>
			<type_document>portal_doc</type_document>
			<link_document>http://</link_document>
			<forbid_task_portal_edit>0</forbid_task_portal_edit>
		</task>
		<task>
			<id>dh8q</id>
			<name>Курс по Информационной</name>
			<type>learning</type>
			<status>failed</status>
			<typical_development_program_id>0x33B37</typical_development_program_id>
			<tutor_id>73DE6B3654F</tutor_id>
			<object_type>course</object_type>
			<object_id>0x51B3F77BC3</object_id>
			<active_learning_id>07A8626493</active_learning_id>
			<type_document>portal_doc</type_document>
			<link_document>http://</link_document>
			<forbid_task_portal_edit>0</forbid_task_portal_edit>
		</task>
		<task>
			<id>a44</id>
			<name>Получить доступ к SAP</name>
			<type>task</type>
			<status>plan</status>
			<typical_development_program_id>0xB33B37</typical_development_program_id>
			<desc>Инициировать </desc>
			<object_type>course</object_type>
			<type_document>portal_doc</type_document>
			<link_document>http://</link_document>
			<forbid_task_portal_edit>0</forbid_task_portal_edit>
		</task>
		<task>
			<id>qsq5hs</id>
			<name>Назначить</name>
			<type>task</type>
			<status>plan</status>
			<typical_development_program_id>0x5B4B37</typical_development_program_id>
			<object_type>course</object_type>
			<type_document>portal_doc</type_document>
			<link_document>http://</link_document>
			<forbid_task_portal_edit>0</forbid_task_portal_edit>
		</task>
	</tasks>
	<doc_info>
	
	</doc_info>
	<access>
		<access_level>0</access_level>
	</access>
</career_reserve>


Нужно проверить все task на то, что там есть tutor_id и при этом должно быть status = plan или active, т.е. мне нужно людей уведомлять, если при status = plan / active, должен быть tutor_id.

Я делаю такой запрос, но при этом результат неверный, потому что если есть хоть один tutor_id, то для existsNode выдает true
Код: plsql
1.
2.
3.
4.
5.
6.
7.
SELECT cr."id"
FROM "career_reserve" cr,
  "cc_5adaptation_plans" plans
WHERE TO_CHAR ( plans."finish_internship", 'YYYY.MM.DD') > TO_CHAR ( sysdate, 'YYYY.MM.DD' )
AND cr."data".EXISTSNODE( '/career_reserve/custom_elems/custom_elem[name = "plan_internship" and value = "6590633558444804468"]' ) = 1
AND cr."data".EXISTSNODE( '/career_reserve/tasks/task/tutor_id') = 0
AND cr."data".EXISTSNODE( '/career_reserve/tasks/task[status="plan" or status="active"]') = 1;



А если так, то не известно сколько таких задач будет, у каждого индивидуально.
Код: plsql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
SELECT cr."id"
FROM "career_reserve" cr,
  "cc_5adaptation_plans" plans
WHERE (TO_CHAR ( plans."finish_internship", 'YYYY.MM.DD' )                                                                          > TO_CHAR ( sysdate, 'YYYY.MM.DD' )
AND cr."data".EXISTSNODE( '/career_reserve/custom_elems/custom_elem[name = "plan_internship" and value = "6590633558444804468"]' ) = 1
AND cr."data".EXISTSNODE( '/career_reserve/tasks/task[1]/tutor_id') = 0
AND cr."data".EXISTSNODE( '/career_reserve/tasks/task[1][status="plan" or status="active"]') = 1)
OR (TO_CHAR ( plans."finish_internship", 'YYYY.MM.DD' ) > TO_CHAR ( sysdate, 'YYYY.MM.DD' )
AND cr."data".EXISTSNODE( '/career_reserve/custom_elems/custom_elem[name = "plan_internship" and value = "6590633558444804468"]' ) = 1
AND cr."data".EXISTSNODE( '/career_reserve/tasks/task[2]/tutor_id') = 0
AND cr."data".EXISTSNODE( '/career_reserve/tasks/task[2][status="plan" or status="active"]') = 1)
.
.
.
;



Как сделать итерацию по этим таскам с проверкой status и tutor_id и получать ответ, только в том случае, если при определенном статусе нет наставника в любом таске одного XML.
...
Рейтинг: 0 / 0
20.08.2018, 18:49
    #39690659
andrey_anonymous
Участник
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Проход по XML existsNode
Код: plsql
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
with career_reserve(data) as (select '<?xml version="1.0" encoding="utf-8"?>
<career_reserve SPXML-FORM="x-local://wtv/wtv_career_reserve.xmd">
  <code>0101010101</code>
  <start_date>2018-08-20T12:34:03+00:00</start_date>
  <status>active</status>
  <person_id>0x5AB2D213744A433D
    <sd>
      <fullname>01 Тест ОК 1</fullname>
      <position_name>01 тест ОК</position_name>
      <position_id>0x5AB2D1CD77C72368</position_id>
      <org_name>34</org_name>
    </sd>
  </person_id>
  <position_type>adaptation</position_type>
  <position_name>01 тест ОК</position_name>
  <tutors>
    <tutor>
    </tutor>
  </tutors>
  <forbid_tasks_edit>0</forbid_tasks_edit>
  <tasks>
    <task>
      <id>puaicv</id>
      <name>Оформить трудовые отношения</name>
      <type>task</type>
      <status>plan</status>
      <plan_date>2018-08-20T00:00:00+00:00</plan_date>
      <typical_development_program_id>0x5705A33B37</typical_development_program_id>
      <desc> СБ.</desc>
      <object_type>course</object_type>
      <type_document>portal_doc</type_document>
      <link_document>http://</link_document>
      <forbid_task_portal_edit>0</forbid_task_portal_edit>
    </task>
    <task>
      <id>gket8e</id>
      <name>Познакомиться с историей развития</name>
      <type>task</type>
      <status>active</status>
      <typical_development_program_id>0x5B4DF705AB37</typical_development_program_id>
      <tutor_id>0x573DEF1106B3654F</tutor_id>
      <desc>Изучить:</desc>
      <object_type>course</object_type>
      <type_document>portal_doc</type_document>
      <link_document>http://</link_document>
      <forbid_task_portal_edit>0</forbid_task_portal_edit>
    </task>
    <task>
      <id>96ar</id>
      <name>Введение в Х5 Retail Group</name>
      <type>learning</type>
      <status>failed</status>
      <typical_development_program_id>0x5B4DF3F705A33B37</typical_development_program_id>
      <object_type>course</object_type>
      <object_id>0x52732E2F6</object_id>
      <active_learning_id>0x586253BC0</active_learning_id>
      <type_document>portal_doc</type_document>
      <link_document>http://</link_document>
      <forbid_task_portal_edit>0</forbid_task_portal_edit>
    </task>
    <task>
      <id>dh8q</id>
      <name>Курс по Информационной</name>
      <type>learning</type>
      <status>failed</status>
      <typical_development_program_id>0x33B37</typical_development_program_id>
      <tutor_id>73DE6B3654F</tutor_id>
      <object_type>course</object_type>
      <object_id>0x51B3F77BC3</object_id>
      <active_learning_id>07A8626493</active_learning_id>
      <type_document>portal_doc</type_document>
      <link_document>http://</link_document>
      <forbid_task_portal_edit>0</forbid_task_portal_edit>
    </task>
    <task>
      <id>a44</id>
      <name>Получить доступ к SAP</name>
      <type>task</type>
      <status>plan</status>
      <typical_development_program_id>0xB33B37</typical_development_program_id>
      <desc>Инициировать </desc>
      <object_type>course</object_type>
      <type_document>portal_doc</type_document>
      <link_document>http://</link_document>
      <forbid_task_portal_edit>0</forbid_task_portal_edit>
    </task>
    <task>
      <id>qsq5hs</id>
      <name>Назначить</name>
      <type>task</type>
      <status>plan</status>
      <typical_development_program_id>0x5B4B37</typical_development_program_id>
      <object_type>course</object_type>
      <type_document>portal_doc</type_document>
      <link_document>http://</link_document>
      <forbid_task_portal_edit>0</forbid_task_portal_edit>
    </task>
  </tasks>
  <doc_info>
  </doc_info>
  <access>
    <access_level>0</access_level>
  </access>
</career_reserve>' from dual
)
--------------------- cut ------------------------------
select x.*
  from career_reserve cr
     , xmltable('/career_reserve/tasks/task[status="plan" or status="active"]'
                passing xmltype(cr.data)
                columns id path 'id'
                      , tutor_id path 'tutor_id'
       ) x
where tutor_id is null
;
ID        TUTOR_ID
--------- ---------
puaicv    
a44       
qsq5hs    

SQL> 
...
Рейтинг: 0 / 0
Форумы / Oracle [игнор отключен] [закрыт для гостей] / Проход по XML existsNode / 2 сообщений из 2, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


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