- 1
- 2
- 3
- 4
- 5
- 6
SELECT *
FROM `table`
WHERE `parent_id` = NULL
OR `parent_id` IN (
SELECT `id` FROM `table` WHERE `parent_id` = NULL
)
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−865.7
SELECT *
FROM `table`
WHERE `parent_id` = NULL
OR `parent_id` IN (
SELECT `id` FROM `table` WHERE `parent_id` = NULL
)
Страная оптимизация запроса
−859.5
CREATE TABLE GOVNOTABLE(
GOVNOTABLEID VARCHAR2(60) NOT NULL DEFAULT ''
/*
Еще всякого говна
*/
)
Это Oracle 7.
Так построены все таблицы складской системы, разработанной каким-то нашим НИИ.
Меня поражает, что в одной строчке можно сделать столько говна:
1. Все ID в системе имеют вид XYZ000NNN, где XYZ - префикс подразделения, 0000NNNN - численный идентификатор, переведенный в строку и добитый нулями. (Сто раз такое говно видел, до сих пор поражаюсь)
2. VARCHAR2(60) - идентификатор никогда не может быть больше 12 символов, на хрена 60?
3. NOT NULL DEFAULT '' - вот это мое любимое! Присмотритесь.
Если кто не догадался: это Oracle, Oracle отличается тем, что '' = NULL.
Т.е. этот цинизм расшифровывается как NOT NULL DEFAULT NULL!!!
Еще в догонку:
Индексация базы ОООЧЕНЬ порадовала.
Индексы это хорошо, они все ускоряют, поэтому проиндексировано КАЖДОЕ ПОЛЕ В БАЗЕ!
−30.1
select t1.PosTag, t1.KlTOt, t1.NameKipID, t1.TypMarkaName, t1.Lim, t1.EdIzm,
t1.OD_NUMMNF, t1.PeriodP, t1.PeriodK,
D3, D5,
case
--поверка
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.DataOchP)) =1 then 'Пм'
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.dd3_1p)) =1 then 'Пм'
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.dd3_2p)) =1 then 'Пм'
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.dd3_3p)) =1 then 'Пм'
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.dd3_4p)) =1 then 'Пм'
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.dd3_5p)) =1 then 'Пм'
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.dd6_1p)) =1 then 'Пм'
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.dd6_2p)) =1 then 'Пм'
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.ddp)) =1 then 'Пм'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.DataOchP)) =1 then 'П'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.dd3_1p)) =1 then 'П'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.dd3_2p)) =1 then 'П'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.dd3_3p)) =1 then 'П'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.dd3_4p)) =1 then 'П'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.dd3_5p)) =1 then 'П'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.dd6_1p)) =1 then 'П'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.dd6_2p)) =1 then 'П'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.ddp)) =1 then 'П'
--калибровка
when Convert(varchar,t1.ArealK) = '1' and Convert(varchar,MONTH(t1.DataOchK)) =1 then 'Км'
when Convert(varchar,t1.ArealK) = '1' and Convert(varchar,MONTH(t1.dd3_1k)) =1 then 'Км'
when Convert(varchar,t1.ArealK) = '1' and Convert(varchar,MONTH(t1.dd3_2k)) =1 then 'Км'
when Convert(varchar,t1.ArealK) = '1' and Convert(varchar,MONTH(t1.dd3_3k)) =1 then 'Км'
when Convert(varchar,t1.ArealK) = '1' and Convert(varchar,MONTH(t1.dd3_4k)) =1 then 'Км'
when Convert(varchar,t1.ArealK) = '1' and Convert(varchar,MONTH(t1.dd3_5k)) =1 then 'Км'
when Convert(varchar,t1.ArealK) = '1' and Convert(varchar,MONTH(t1.dd6_1k)) =1 then 'Км'
when Convert(varchar,t1.ArealK) = '1' and Convert(varchar,MONTH(t1.dd6_2k)) =1 then 'Км'
when Convert(varchar,t1.ArealK) = '1' and Convert(varchar,MONTH(t1.ddk)) =1 then 'Км'
when Convert(varchar,t1.ArealK) <> '1' and Convert(varchar,MONTH(t1.DataOchK)) =1 then 'К'
when Convert(varchar,t1.ArealK) <> '1' and Convert(varchar,MONTH(t1.dd3_1k)) =1 then 'К'
when Convert(varchar,t1.ArealK) <> '1' and Convert(varchar,MONTH(t1.dd3_2k)) =1 then 'К'
when Convert(varchar,t1.ArealK) <> '1' and Convert(varchar,MONTH(t1.dd3_3k)) =1 then 'К'
when Convert(varchar,t1.ArealK) <> '1' and Convert(varchar,MONTH(t1.dd3_4k)) =1 then 'К'
when Convert(varchar,t1.ArealK) <> '1' and Convert(varchar,MONTH(t1.dd3_5k)) =1 then 'К'
when Convert(varchar,t1.ArealK) <> '1' and Convert(varchar,MONTH(t1.dd6_1k)) =1 then 'К'
when Convert(varchar,t1.ArealK) <> '1' and Convert(varchar,MONTH(t1.dd6_2k)) =1 then 'К'
when Convert(varchar,t1.ArealK) <> '1' and Convert(varchar,MONTH(t1.ddk)) =1 then 'К' end a1,
case
--поверка
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.DataOchP)) =2 then 'Пм'
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.dd3_1p)) =2 then 'Пм'
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.dd3_2p)) =2 then 'Пм'
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.dd3_3p)) =2 then 'Пм'
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.dd3_4p)) =2 then 'Пм'
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.dd3_5p)) =2 then 'Пм'
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.dd6_1p)) =2 then 'Пм'
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.dd6_2p)) =2 then 'Пм'
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.ddp)) =2 then 'Пм'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.DataOchP)) =2 then 'П'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.dd3_1p)) =2 then 'П'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.dd3_2p)) =2 then 'П'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.dd3_3p)) =2 then 'П'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.dd3_4p)) =2 then 'П'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.dd3_5p)) =2 then 'П'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.dd6_1p)) =2 then 'П'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.dd6_2p)) =2 then 'П'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.ddp)) =2 then 'П'
--калибровка
when Convert(varchar,t1.ArealK) = '1' and Convert(varchar,MONTH(t1.DataOchK)) =2 then 'Км'
when Convert(varchar,t1.ArealK) = '1' and Convert(varchar,MONTH(t1.dd3_1k)) =2 then 'Км'
when Convert(varchar,t1.ArealK) = '1' and Convert(varchar,MONTH(t1.dd3_2k)) =2 then 'Км'
when Convert(varchar,t1.ArealK) = '1' and Convert(varchar,MONTH(t1.dd3_3k)) =2 then 'Км'
when Convert(varchar,t1.ArealK) = '1' and Convert(varchar,MONTH(t1.dd3_4k)) =2 then 'Км'
when Convert(varchar,t1.ArealK) = '1' and Convert(varchar,MONTH(t1.dd3_5k)) =2 then 'Км'
when Convert(varchar,t1.ArealK) = '1' and Convert(varchar,MONTH(t1.dd6_1k)) =2 then 'Км'
when Convert(varchar,t1.ArealK) = '1' and Convert(varchar,MONTH(t1.dd6_2k)) =2 then 'Км'
when Convert(varchar,t1.ArealK) = '1' and Convert(varchar,MONTH(t1.ddk)) =2 then 'Км'
when Convert(varchar,t1.ArealK) <> '1' and Convert(varchar,MONTH(t1.DataOchK)) =2 then 'К'
when Convert(varchar,t1.ArealK) <> '1' and Convert(varchar,MONTH(t1.dd3_1k)) =2 then 'К'
when Convert(varchar,t1.ArealK) <> '1' and Convert(varchar,MONTH(t1.dd3_2k)) =2 then 'К'
when Convert(varchar,t1.ArealK) <> '1' and Convert(varchar,MONTH(t1.dd3_3k)) =2 then 'К'
when Convert(varchar,t1.ArealK) <> '1' and Convert(varchar,MONTH(t1.dd3_4k)) =2 then 'К'
when Convert(varchar,t1.ArealK) <> '1' and Convert(varchar,MONTH(t1.dd3_5k)) =2 then 'К'
when Convert(varchar,t1.ArealK) <> '1' and Convert(varchar,MONTH(t1.dd6_1k)) =2 then 'К'
when Convert(varchar,t1.ArealK) <> '1' and Convert(varchar,MONTH(t1.dd6_2k)) =2 then 'К'
when Convert(varchar,t1.ArealK) <> '1' and Convert(varchar,MONTH(t1.ddk)) =2 then 'К' end a2,
case
--поверка
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.DataOchP)) =3 then 'Пм'
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.dd3_1p)) =3 then 'Пм'
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.dd3_2p)) =3 then 'Пм'
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.dd3_3p)) =3 then 'Пм'
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.dd3_4p)) =3 then 'Пм'
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.dd3_5p)) =3 then 'Пм'
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.dd6_1p)) =3 then 'Пм'
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.dd6_2p)) =3 then 'Пм'
when Convert(varchar,t1.ArealP) = '1' and Convert(varchar,MONTH(t1.ddp)) =3 then 'Пм'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.DataOchP)) =3 then 'П'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.dd3_1p)) =3 then 'П'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.dd3_2p)) =3 then 'П'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.dd3_3p)) =3 then 'П'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.dd3_4p)) =3 then 'П'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.dd3_5p)) =3 then 'П'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.dd6_1p)) =3 then 'П'
when Convert(varchar,t1.ArealP) <> '1' and Convert(varchar,MONTH(t1.dd6_2p)) =3 then 'П'
Взято со знаменитого топика на sql.ru: http://sql.ru/forum/actualthread.aspx?tid=591607
Писано ручками некоего безумца. Тому, кто занял его место впоследствии, было дано задание оптимизировать это под угрозой увольнения.
P.S. Функционал сайта, как выяснилось, не держит больше 100 строк говнокода, поэтому с полным текстом лучше ознакомиться по данной выше ссылке.
−1105
$refsql = @mysql_query("SELECT id,username FROM qref WHERE type='Bonus' ORDER BY last LIMIT 1");
обратите внимание на часть "ORDER BY last LIMIT 1"
−990.8
close actoj deallocate actoj
drop table ##babrujsk -- razrushajem derevnju ##babrujsk
1500 строка непонятной процедуры формирования счёта
−421.3
CREATE TABLE `shop` (
`id` text NOT NULL,
`name` text NOT NULL,
`ball` text NOT NULL,
`post` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
id - номер пользователя
name - имя пользователя
ball - количество баллов
post - количество сообщений
Успешно наговнокодено nod'ом...
−282.3
query = "select coach_id, "
" concat(coach_surname,' ',coach_name,' ',coach_pname, ' (', (select name from price_coach_types where id_coach_type = coaches.coach_type), ')'), "
"ifnull((select price_single_child from price_coaches where coach_id = coaches.coach_id and price_start_date = " + actual_price+ "),0),"
"ifnull((select price_single_adult from price_coaches where coach_id = coaches.coach_id and price_start_date = " + actual_price+ "),0),"
"ifnull((select price_group_child from price_coaches where coach_id = coaches.coach_id and price_start_date = " + actual_price+ "),0),"
"ifnull((select price_group_adult from price_coaches where coach_id = coaches.coach_id and price_start_date = " + actual_price+ "),0)"
" from coaches order by binary coach_surname, coach_type";
Автор любитель копипастить свой код :)
−352.3
SELECT DISTINCT BE.ID as ID,BE.NAME as NAME,BE.CODE as CODE,BE.IBLOCK_ID as
IBLOCK_ID,BE.IBLOCK_SECTION_ID as IBLOCK_SECTION_ID,B.DETAIL_PAGE_URL as
DETAIL_PAGE_URL,BE.DETAIL_TEXT as DETAIL_TEXT,BE.DETAIL_TEXT_TYPE as
DETAIL_TEXT_TYPE,BE.DETAIL_PICTURE as DETAIL_PICTURE,BE.PREVIEW_TEXT as
PREVIEW_TEXT,BE.PREVIEW_TEXT_TYPE as PREVIEW_TEXT_TYPE,BE.PREVIEW_PICTURE as
PREVIEW_PICTURE,L.DIR as LANG_DIR,BE.XML_ID as EXTERNAL_ID,B.IBLOCK_TYPE_ID as
IBLOCK_TYPE_ID,B.CODE as IBLOCK_CODE,B.XML_ID as IBLOCK_EXTERNAL_ID FROM
b_iblock B INNER JOIN b_lang L ON B.LID=L.LID INNER JOIN b_iblock_element BE
ON BE.IBLOCK_ID = B.ID INNER JOIN b_iblock_section_element BSE ON
BSE.IBLOCK_ELEMENT_ID = BE.ID INNER JOIN b_iblock_section BSubS ON
BSE.IBLOCK_SECTION_ID = BSubS.ID INNER JOIN b_iblock_section BS ON
(BSubS.IBLOCK_ID=BS.IBLOCK_ID AND BSubS.LEFT_MARGIN>=BS.LEFT_MARGIN AND
BSubS.RIGHT_MARGIN<=BS.RIGHT_MARGIN) INNER JOIN b_iblock_property FP1 ON
FP1.IBLOCK_ID=B.ID AND FP1.CODE='code2' INNER JOIN b_iblock_element_property
FPV1 ON FP1.ID=FPV1.IBLOCK_PROPERTY_ID AND FPV1.IBLOCK_ELEMENT_ID=BE.ID INNER
JOIN b_iblock_property FP2 ON FP2.IBLOCK_ID=B.ID AND FP2.CODE='code3' INNER
JOIN b_iblock_element_property FPV2 ON FP2.ID=FPV2.IBLOCK_PROPERTY_ID AND
FPV2.IBLOCK_ELEMENT_ID=BE.ID INNER JOIN b_iblock_property FP3 ON
FP3.IBLOCK_ID=B.ID AND FP3.CODE='code4' INNER JOIN b_iblock_element_property
FPV3 ON FP3.ID=FPV3.IBLOCK_PROPERTY_ID AND FPV3.IBLOCK_ELEMENT_ID=BE.ID INNER
JOIN b_iblock_property FP4 ON FP4.IBLOCK_ID=B.ID AND FP4.CODE='code5' INNER
JOIN b_iblock_element_property FPV4 ON FP4.ID=FPV4.IBLOCK_PROPERTY_ID AND
FPV4.IBLOCK_ELEMENT_ID=BE.ID INNER JOIN b_iblock_property FP5 ON
FP5.IBLOCK_ID=B.ID AND FP5.CODE='code7' INNER JOIN b_iblock_element_property
FPV5 ON FP5.ID=FPV5.IBLOCK_PROPERTY_ID AND FPV5.IBLOCK_ELEMENT_ID=BE.ID INNER
JOIN b_iblock_property FP6 ON FP6.IBLOCK_ID=B.ID AND FP6.CODE='code9' INNER
JOIN b_iblock_element_property FPV6 ON FP6.ID=FPV6.IBLOCK_PROPERTY_ID AND
FPV6.IBLOCK_ELEMENT_ID=BE.ID INNER JOIN b_iblock_property FP7 ON
FP7.IBLOCK_ID=B.ID AND FP7.CODE='code12' INNER JOIN b_iblock_element_property
FPV7 ON FP7.ID=FPV7.IBLOCK_PROPERTY_ID AND FPV7.IBLOCK_ELEMENT_ID=BE.ID INNER
JOIN b_iblock_property FP8 ON FP8.IBLOCK_ID=B.ID AND FP8.CODE='code15' INNER
JOIN b_iblock_element_property FPV8 ON FP8.ID=FPV8.IBLOCK_PROPERTY_ID AND
FPV8.IBLOCK_ELEMENT_ID=BE.ID INNER JOIN b_iblock_property FP9 ON
FP9.IBLOCK_ID=B.ID AND FP9.CODE='code16' INNER JOIN b_iblock_element_property
FPV9 ON FP9.ID=FPV9.IBLOCK_PROPERTY_ID AND FPV9.IBLOCK_ELEMENT_ID=BE.ID INNER
JOIN b_iblock_property FP10 ON FP10.IBLOCK_ID=B.ID AND FP10.CODE='code18'
INNER JOIN b_iblock_element_property FPV10 ON FP10.ID=FPV10.IBLOCK_PROPERTY_ID
AND FPV10.IBLOCK_ELEMENT_ID=BE.ID INNER JOIN b_iblock_property FP11 ON
FP11.IBLOCK_ID=B.ID AND FP11.CODE='code23' INNER JOIN
b_iblock_element_property FPV11 ON FP11.ID=FPV11.IBLOCK_PROPERTY_ID AND
FPV11.IBLOCK_ELEMENT_ID=BE.ID INNER JOIN b_iblock_property FP12 ON
FP12.IBLOCK_ID=B.ID AND FP12.CODE='code26' INNER JOIN
b_iblock_element_property FPV12 ON FP12.ID=FPV12.IBLOCK_PROPERTY_ID AND
FPV12.IBLOCK_ELEMENT_ID=BE.ID INNER JOIN b_iblock_property FP13 ON
FP13.IBLOCK_ID=B.ID AND FP13.CODE='code27' INNER JOIN
b_iblock_element_property FPV13 ON FP13.ID=FPV13.IBLOCK_PROPERTY_ID AND
FPV13.IBLOCK_ELEMENT_ID=BE.ID INNER JOIN b_iblock_property FP14 ON
FP14.IBLOCK_ID=B.ID AND FP14.CODE='code32' INNER JOIN
b_iblock_element_property FPV14 ON FP14.ID=FPV14.IBLOCK_PROPERTY_ID AND
FPV14.IBLOCK_ELEMENT_ID=BE.ID INNER JOIN b_iblock_property FP15 ON
FP15.IBLOCK_ID=B.ID AND FP15.CODE='code34' INNER JOIN
b_iblock_element_property FPV15 ON FP15.ID=FPV15.IBLOCK_PROPERTY_ID AND
FPV15.IBLOCK_ELEMENT_ID=BE.ID WHERE 1=1 AND B.ID IN (0,42) AND (
(BE.WF_STATUS_ID=1 AND BE.WF_PARENT_ELEMENT_ID IS NULL) ) AND ((((
(upper(BE.NAME) like upper('%acer7730G%') and BE.NAME is not null) )))) AND
(((( (upper(FPV1.VALUE) like upper('%Intel%') and FPV1.VALUE is not null) AND
(upper(FPV1.VALUE) like upper('%Core2Duo%') and FPV1.VALUE is not null) AND
(upper(FPV1.VALUE) like upper('%T5850%') and FPV1.VALUE is not null) AND
(upper(FPV1.VALUE) like upper('%2.16GHz%') and FPV1.VALUE is not null) ))))
AND (((( (upper(FPV2.VALUE) like upper('%4096Mb%') and FPV2.VALUE is not null)
AND ( (upper(FPV2.VALUE) like upper('%4Gb%') and FPV2.VALUE is not null) ) AND
(upper(FPV2.VALUE) like upper('%DDRII%') and FPV2.VALUE is not null) )))) AND
(((( (upper(FPV3.VALUE) like upper('%2x320Gb%') and FPV3.VALUE is not null)
AND (upper(FPV3.VALUE) like upper('%5400rpm%') and FPV3.VALUE is not null) AND
(upper(FPV3.VALUE) like upper('%SATA%') and FPV3.VALUE is not null) )))) AND
(((( (upper(FPV4.VALUE) like upper('%17%') and FPV4.VALUE is not null) ))))
AND (((( (upper(FPV5.VALUE) like upper('%??%') and FPV5.VALUE is not null)
)))) AND (((( (upper(FPV6.VALUE) like upper('%64Mb%') and FPV6.VALUE is not
null) AND ( (upper(FPV6.VALUE) like upper('%??%') and FPV6.VALUE is not null)
AND (upper(FPV6.VALUE) like upper('%958Mb%') and FPV6.VALUE is not null) )))))
AND (((( (upper(FPV7.VALUE) like upper('%??%') and FPV7.VALUE is not null)
)))) AND (((( (upper(FPV8.VALUE) like upper('%Bluetooth%') and FPV8.VALUE is
not null) AND (upper(FPV8.VALUE) like upper('%V2.0%') and FPV8.VALUE is not
null) AND (upper(FPV8.VALUE) like upper('%EDR%') and FPV8.VALUE is not null)
)))) AND (((( (upper(FPV9.VALUE) like upper('%4%') and FPV9.VALUE is not null)
)))) AND (((( (upper(FPV10.VALUE) like upper('%??%') and FPV10.VALUE is not
null) )))) AND (((( (upper(FPV11.VALUE) like upper('%??%') and FPV11.VALUE is
not null) )))) AND (((( (upper(FPV12.VALUE) like upper('%??%') and FPV12.VALUE
is not null) )))) AND (((( (upper(FPV13.VALUE) like upper('%WebCam%') and
FPV13.VALUE is not null) AND (upper(FPV13.VALUE) like upper('%1,3Mpx%') and
FPV13.VALUE is not null) )))) AND (((( (upper(FPV14.VALUE) like
upper('%?????%') and FPV14.VALUE is not null) )))) AND ((((
(upper(FPV15.VALUE) like upper('%12%') and FPV15.VALUE is not null) AND
(upper(FPV15.VALUE) like upper('%???????%') and FPV15.VALUE is not null) ))))
AND ((((BE.IBLOCK_ID = '42')))) AND (((BE.ACTIVE_TO >= now() OR BE.ACTIVE_TO
IS NULL) AND (BE.ACTIVE_FROM <= now() OR BE.ACTIVE_FROM IS NULL))) AND
((((BE.ACTIVE='Y')))) AND ((BS.ID = 224)) ORDER BY BE.SORT asc , BE.ID desc
LIMIT 0, 30
Битрикс (http://dev.1c-bitrix.ru/community/forums/forum6/topic14898/)
−370.9
CREATE OR REPLACE FUNCTION hex_inc(in_str character, n integer)
RETURNS character AS
$BODY$
DECLARE x varchar;
BEGIN
x=in_str;
if (substring(in_str from n for n+1)='0') or (substring(in_str from n for n+1)='1') or (substring(in_str from n for n+1)='2')
or (substring(in_str from n for n+1)='3') or (substring(in_str from n for n+1)='4') or (substring(in_str from n for n+1)='5')
or (substring(in_str from n for n+1)='6') or (substring(in_str from n for n+1)='7') or (substring(in_str from n for n+1)='8')
or (substring(in_str from n for n+1)='A') or (substring(in_str from n for n+1)='B') or (substring(in_str from n for n+1)='C')
or (substring(in_str from n for n+1)='D') or (substring(in_str from n for n+1)='E') THEN
x=raplace_char(n,x,chr((ascii(substring(in_str from n for n+1))+1))); -- inc() только для string
ELSIF (substring(in_str from n for n+1)='9') THEN
x=raplace_char(n,x,'A'); -- ну т.к. это уже 10
ELSIF (substring(in_str from n for n+1)='F') THEN
x=raplace_char(n,x,'0'); -- ну т.к. это +1 разряд :)
x=hex_inc(x,n-1);
END IF;
RETURN x;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;
CREATE OR REPLACE FUNCTION raplace_char(n integer, in_str character, in_char character)
RETURNS character AS
$BODY$
Begin
IF ( n = char_length(in_str) ) THEN
RETURN substring(in_str from 1 for n-1) || in_char;
ELSIF (n = 1) THEN
RETURN in_char || substring(in_str from 2 for char_length(in_str)-1) ;
ELSE
RETURN substring(in_str from 1 for n-1) || in_char || substring(in_str from n+1 for char_length(in_str)-n);
END IF;
END;
$BODY$
LANGUAGE 'plpgsql' STABLE
COST 100;
Язык PL/PgSQL
Функция должна делать inc числу, записанному в строке в шестнадцатеричном виде
−1105.8
IF LTRIM(RTRIM(LEN(ISNULL(@MandantTags,'')))) > 0
BEGIN
SET @TagsSQL = 'INSERT INTO #MandantTmp (...
END