- 1
- 2
- 3
SELECT COUNT(*) INTO v_inserted_data FROM f2s.column_map
WHERE old_id='TYPE='||i.pk_0 AND migration_id='fin95_aral'
AND fndr_table='R_ALLOWABLE' AND UPPER(NVL(fndr_constraint,'null'))=UPPER('NULL');
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
−153
SELECT COUNT(*) INTO v_inserted_data FROM f2s.column_map
WHERE old_id='TYPE='||i.pk_0 AND migration_id='fin95_aral'
AND fndr_table='R_ALLOWABLE' AND UPPER(NVL(fndr_constraint,'null'))=UPPER('NULL');
Oracle 10.2 PL/SQL. продакшн код.
Условие поиска NULL убило...
−113
CURSOR v_cursor IS
SELECT
...
NVL(DECODE(record_status,'CURRENT',1,0),'1') r_grain_ro_1_ins_64,
...
Это в продакшн коде.
Oracle 10.2, PL/SQL
−107
SELECT SUBSTR(exp, 1, 20) "expression", (CASE WHEN SUBSTR(exp, 6, 1) = '+' THEN (CASE WHEN SUBSTR(exp, 3, 1) = '+' THEN TO_NUMBER(SUBSTR(exp, 1, 2))
+ TO_NUMBER(SUBSTR(exp, 4, 2)) ELSE CASE WHEN SUBSTR(exp, 3, 1) = '-' THEN TO_NUMBER(SUBSTR(exp, 1, 2)) - TO_NUMBER(SUBSTR(exp, 4, 2)) ELSE CASE
WHEN SUBSTR(exp, 3, 1) = '*' THEN TO_NUMBER(SUBSTR(exp, 1, 2)) * TO_NUMBER(SUBSTR(exp, 4, 2)) ELSE CASE WHEN SUBSTR(exp, 3, 1) = '/' THEN
TO_NUMBER(SUBSTR(exp, 1, 2)) / TO_NUMBER(SUBSTR(exp, 4, 2)) END END END END) + TO_NUMBER(SUBSTR(exp, 7, 2)) ELSE CASE WHEN SUBSTR(exp, 6, 1) = '-'
THEN (CASE WHEN SUBSTR(exp, 3, 1) = '+' THEN TO_NUMBER(SUBSTR(exp, 1, 2)) + TO_NUMBER(SUBSTR(exp, 4, 2)) ELSE CASE WHEN SUBSTR(exp, 3, 1) = '-' THEN
TO_NUMBER(SUBSTR(exp, 1, 2)) - TO_NUMBER(SUBSTR(exp, 4, 2)) ELSE CASE WHEN SUBSTR(exp, 3, 1) = '*' THEN TO_NUMBER(SUBSTR(exp, 1, 2)) *
TO_NUMBER(SUBSTR(exp, 4, 2)) ELSE CASE WHEN SUBSTR(exp, 3, 1) = '/' THEN TO_NUMBER(SUBSTR(exp, 1, 2)) / TO_NUMBER(SUBSTR(exp, 4, 2)) END END END END)
- TO_NUMBER(SUBSTR(exp, 7, 2)) ELSE CASE WHEN SUBSTR(exp, 6, 1) = '*' THEN (CASE WHEN SUBSTR(exp, 3, 1) = '+' THEN TO_NUMBER(SUBSTR(exp, 1, 2)) +
TO_NUMBER(SUBSTR(exp, 4, 2)) ELSE CASE WHEN SUBSTR(exp, 3, 1) = '-' THEN TO_NUMBER(SUBSTR(exp, 1, 2)) - TO_NUMBER(SUBSTR(exp, 4, 2)) ELSE CASE WHEN
SUBSTR(exp, 3, 1) = '*' THEN TO_NUMBER(SUBSTR(exp, 1, 2)) * TO_NUMBER(SUBSTR(exp, 4, 2)) ELSE CASE WHEN SUBSTR(exp, 3, 1) = '/' THEN TO_NUMBER(SUBSTR(exp, 1, 2)) /
TO_NUMBER(SUBSTR(exp, 4, 2)) END END END END) * TO_NUMBER(SUBSTR(exp, 7, 2)) ELSE CASE WHEN SUBSTR(exp, 6, 1) = '/' THEN (CASE WHEN SUBSTR(exp, 3, 1) = '+' THEN
TO_NUMBER(SUBSTR(exp, 1, 2)) + TO_NUMBER(SUBSTR(exp, 4, 2)) ELSE CASE WHEN SUBSTR(exp, 3, 1) = '-' THEN TO_NUMBER(SUBSTR(exp, 1, 2)) - TO_NUMBER(SUBSTR(exp, 4, 2))
ELSE CASE WHEN SUBSTR(exp, 3, 1) = '*' THEN TO_NUMBER(SUBSTR(exp, 1, 2)) * TO_NUMBER(SUBSTR(exp, 4, 2)) ELSE CASE WHEN SUBSTR(exp, 3, 1) = '/' THEN
TO_NUMBER(SUBSTR(exp, 1, 2)) / TO_NUMBER(SUBSTR(exp, 4, 2)) END END END END) / TO_NUMBER(SUBSTR(exp, 7, 2)) END END END END) "result" FROM lab3_2;
Сидел я на прошлой лабе и делал значит задания по Oracle и вот последнее задание было таким:
"Дана таблица с единственной колонкой (строкового типа) с выражениями вида:’xx*xx*xx’ где xx – символы цифр 0..9, * - один из символов математических операций: *+-/ Например, таким выражениями являются ‘01*23+34’ ‘32+13-12’ и т.д. Требуется создать таблицу и заполнить ее строками содержащими такие выражения (не менее 5 строк), составить оператор SELECT который используя данные из этой таблицы выведет строки вида ‘<исходное выражение>=<вычисленный результат>’. Задание выполнить без учета приоритетности операций."
Вооружившись Notepad++ я составил вот такое вот запросище, которое работает между прочим :) Для повторения эксперимента нужно создать таблицу lab3_2 с полем exp строкового типа, ну и внести в нее пару каких-нибудь выражений.
−853
SELECT a.*,r.rating_count,r.rating_sum,cc.params AS catparams,cc.title AS cattle,cc.alias AS category_alias FROM gn_content AS a INNER JOIN gn_categories AS cc ON cc.id = a.catid LEFT JOIN gn_content_rating AS r ON r.content_id = a.id WHERE a.state = 1 AND cc.published = 1
AND ( a.publish_up = '2011-10-07 21:02:32' OR a.publish_up <= '2011-10-07 18:02:38' )
AND ( a.publish_down = '2011-10-07 21:02:32' OR a.publish_down >= '2011-10-07 18:02:38' )
AND (cc.id = 105 OR cc.id = 106 OR cc.id = 107 OR cc.id = 108 OR cc.id = 109 OR cc.id = 110 OR cc.id = 111 OR cc.id = 106 OR cc.id = 107 OR cc.id = 108 OR cc.id = 109 OR cc.id = 110 OR cc.id = 111)
ORDER BY a.created DESC
Это код модуля adinews2 для joomla
Используются всегда только 2 даты: начало, конец
−857
# Query_time: 1 Lock_time: 0 Rows_sent: 50807 Rows_examined: 160282
SELECT `node`.id, (
TO_DAYS( NOW( ) ) - TO_DAYS( `node`.datecreate )
) AS countDay, (
`rating_node`.up - `rating_node`.down
) AS countRating, COUNT( `comments`.cid ) AS countComments, `node`.view AS countViews
FROM node
LEFT JOIN `rating_node` ON `rating_node`.node_id = `node`.id
LEFT JOIN `comments` ON `comments`.nid = `node`.id
GROUP BY `node`.id;
фрилансеры...
−853
Create Proc char32add1(
@char32 nvarchar(1) =Null,
@rez nvarchar(1) output,
@rez1 int=-1 output
)
As
Begin
if (@char32 is Null) return -1
Select @rez1=0
if (@char32 = "0") Begin Select @rez="1"
return 0 End
if (@char32 = "1") Begin Select @rez="2"
return 0 End
if (@char32 = "2") Begin Select @rez="3"
return 0 End
if (@char32 = "3") Begin Select @rez="4"
return 0 End
if (@char32 = "4") Begin Select @rez="5" return 0 End
if (@char32 = "5") Begin Select @rez="6" return 0 End
if (@char32 = "6") Begin Select @rez="7" return 0 End
if (@char32 = "7") Begin Select @rez="8" return 0 End
if (@char32 = "8") Begin Select @rez="9" return 0 End
if (@char32 = "9") Begin Select @rez="A" return 0 End
if (@char32 = "a" or @char32 = "A" ) Begin Select @rez="B" return 0 End
if (@char32 = "b" or @char32 = "B" ) Begin Select @rez="C" return 0 End
if (@char32 = "c" or @char32 = "C" ) Begin Select @rez="D" return 0 End
if (@char32 = "d" or @char32 = "D" ) Begin Select @rez="E" return 0 End
if (@char32 = "e" or @char32 = "E" ) Begin Select @rez="F" return 0 End
if (@char32 = "f" or @char32 = "F" ) Begin Select @rez="G" return 0 End
if (@char32 = "g" or @char32 = "G" ) Begin Select @rez="H" return 0 End
if (@char32 = "h" or @char32 = "H" ) Begin Select @rez="I" return 0 End
if (@char32 = "i" or @char32 = "I" ) Begin Select @rez="J" return 0 End
if (@char32 = "j" or @char32 = "J" ) Begin Select @rez="K" return 0 End
if (@char32 = "k" or @char32 = "K" ) Begin Select @rez="L" return 0 End
if (@char32 = "l" or @char32 = "L" ) Begin Select @rez="M" return 0 End
if (@char32 = "m" or @char32 = "M" ) Begin Select @rez="N" return 0 End
if (@char32 = "n" or @char32 = "N" ) Begin Select @rez="O" return 0 End
if (@char32 = "o" or @char32 = "O" ) Begin Select @rez="P" return 0 End
if (@char32 = "p" or @char32 = "P" ) Begin Select @rez="Q" return 0 End
if (@char32 = "q" or @char32 = "Q" ) Begin Select @rez="R" return 0 End
if (@char32 = "r" or @char32 = "R" ) Begin Select @rez="S" return 0 End
if (@char32 = "s"or @char32 = "S" ) Begin Select @rez="T" return 0 End
if (@char32 = "t" or @char32 = "T" ) Begin Select @rez="U" return 0 End
if (@char32 = "u" or @char32 = "U" ) Begin Select @rez="V" return 0 End
Select @rez1=1
if (@char32 = "v" or @char32 = "V" ) Begin Select @rez="0" return 1 End
End
−862
SELECT POL_PREMIUM
INTO i_csp
FROM policy
WHERE
policy_key = i_polkey AND
pol_status_cde = 1;
SELECT POL_CLIENT_CDE
INTO i_clientno
FROM policy
WHERE policy_key = i_polkey
AND pol_status_cde = 1;
SELECT POL_PLAN_CDE
INTO i_plan
FROM policy
WHERE policy_key = i_polkey
AND pol_status_cde = 1;
SELECT 110
INTO i_SecAllrks
FROM DUAL;
Запятые и знаки инициализации переменных придумали для трусов =) Имхо. Не вкурила зачем так делать.
−530
SELECT ID,
INTO var
FROM tbl_ref
WHERE
TO_DATE (TO_CHAR (sysdate, 'MM-DD-YYYY'), 'MM-DD-YYYY') BETWEEN VAL_EFF_FROM_DATE AND VAL_EFF_TO_DATE
Индусы любят строки! А особенно конвертить даты в строки и обратно!
−112
CREATE TRIGGER after_update_limit AFTER UPDATE ON limits
FOR EACH ROW
BEGIN
SET @annual_normative = NULL;
SET @ud_use = NULL;
SET @ud_disposal = NULL;
SET @placed_deposited = NULL;
SET @placed_disposal = NULL;
SET @custom1_disposal = NULL;
SET @custom1_deposited = NULL;
SET @custom1_use = NULL;
SET @custom1_neutralization = NULL;
SET @custom2_disposal = NULL;
SET @custom2_deposited = NULL;
SET @custom2_use = NULL;
SET @custom2_neutralization = NULL;
SET @custom3_disposal = NULL;
SET @custom3_deposited = NULL;
SET @custom3_use = NULL;
SET @custom3_neutralization = NULL;
SET @custom4_disposal = NULL;
SET @custom4_deposited = NULL;
SET @custom4_use = NULL;
SET @custom4_neutralization = NULL;
SET @custom5_disposal = NULL;
SET @custom5_deposited = NULL;
SET @custom5_use = NULL;
SET @custom5_neutralization = NULL;
SELECT
SUM(annual_normative), SUM(ud_use), SUM(ud_disposal), SUM(placed_deposited), SUM(placed_disposal),
SUM(custom1_disposal), SUM(custom1_deposited), SUM(custom1_use), SUM(custom1_neutralization),
SUM(custom2_disposal), SUM(custom2_deposited), SUM(custom2_use), SUM(custom2_neutralization),
SUM(custom3_disposal), SUM(custom3_deposited), SUM(custom3_use), SUM(custom3_neutralization),
SUM(custom4_disposal), SUM(custom4_deposited), SUM(custom4_use), SUM(custom4_neutralization),
SUM(custom5_disposal), SUM(custom5_deposited), SUM(custom5_use), SUM(custom5_neutralization)
INTO
@annual_normative, @ud_use, @ud_disposal, @placed_deposited, @placed_disposal,
@custom1_disposal, @custom1_deposited, @custom1_use, @custom1_neutralization,
@custom2_disposal, @custom2_deposited, @custom2_use, @custom2_neutralization,
@custom3_disposal, @custom3_deposited, @custom3_use, @custom3_neutralization,
@custom4_disposal, @custom4_deposited, @custom4_use, @custom4_neutralization,
@custom5_disposal, @custom5_deposited, @custom5_use, @custom5_neutralization
FROM limits
WHERE id_enterprise = NEW.id_enterprise;
UPDATE limits_total
SET
annual_normative = @annual_normative, ud_use = @ud_use, ud_disposal = @ud_disposal, placed_deposited = @placed_deposited, placed_disposal = @placed_disposal,
custom1_disposal = @custom1_disposal, custom1_deposited = @custom1_deposited, custom1_use = @custom1_use, custom1_neutralization = @custom1_neutralization,
custom2_disposal = @custom2_disposal, custom2_deposited = @custom2_deposited, custom2_use = @custom2_use, custom2_neutralization = @custom2_neutralization,
custom3_disposal = @custom3_disposal, custom3_deposited = @custom3_deposited, custom3_use = @custom3_use, custom3_neutralization = @custom3_neutralization,
custom4_disposal = @custom4_disposal, custom4_deposited = @custom4_deposited, custom4_use = @custom4_use, custom4_neutralization = @custom4_neutralization,
custom5_disposal = @custom5_disposal, custom5_deposited = @custom5_deposited, custom5_use = @custom5_use, custom5_neutralization = @custom5_neutralization
WHERE id_enterprise = NEW.id_enterprise
LIMIT 1;
END;
Сперва можно посмеяться, а затем подскажите, пжл, как тоже самое написать по человечески ???
−110
$sql_info = "SELECT * FROM accessories";
$query_info = mysql_query($sql_info);
while($row_info=mysql_fetch_array($query_info)) {
$found_something=1;
}
Проверка наличия записей в БД