- 1
- 2
if(mysql_query('DROP TABLE table_name'))
echo "таблица существовала ;(";
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
0
if(mysql_query('DROP TABLE table_name'))
echo "таблица существовала ;(";
Проверка таблицы на существование.
Взято самизнаетеоткуда
ЗЫ SQL+PHP
0
select *
from INV_CARD
where to_char (dt_reg, 'MM') < TO_CHAR(SYSDATE, 'MM')
AND (DT_OUT IS NULL OR to_char (dt_OUT, 'MM') = TO_CHAR(SYSDATE, 'MM'))
AND ID_FA_TYPE NOT IN (SELECT ID_FA_TYPE FROM FA_TYPE WHERE CODE = '17')
AND ID_FA_STATUS IN (SELECT ID_FA_STATUS FROM FA.V_FA_STATUS WHERE IS_ACCOUNTING = 1)
AND STATUS = 1
AND GLN.ACC_OPER.GET_ACC1_ACC2(ID_AMORT_ACC) LIKE '01%'
(PL/SQL)
очень понравилось сравнение дат, ну и использование констант тоже зачет
0
--
--Ada SPEC file
--Universe
--
-- Description:
--
--
--
--
--
--
--
package Universe is
type UniversalObject is tagged record
id:integer;
end record;
type Position is record
x:integer;
y:integer;
end record;
type VisibleObject is new UniversalObject with record
mass: integer;
Name:String (0..60);
Speed: float; --скорость:)
OrbitalPosition: Position;
end record;
type Ship Is new VisibleObject with record
Size:integer;
end record;
type Asteroid is new VisibleObject WITH NULL RECORD;
procedure USELECT (Object: in UniversalObject'Class); --Новая инструкция выбора:)
end Universe;
Тут не смешно, но мне кажется, стоит оптимизировать.
И еще: Добавьте языков в список. Не все ковнокодеры - вебмастера.
0
"select crash.Фамилия from crash where Нарушение=(select select bill.Нарушение from bill where Штраф=(select max(Штраф) from bill));";
0
FUNCTION gender_modification (string VARCHAR2, gender VARCHAR2) RETURN VARCHAR2
IS
str VARCHAR2(500) := string;
BEGIN
IF gender = 'ж' THEN
str := REPLACE(str,'одиннадцать','о$$ди$$ннадцать');
str := REPLACE(str,'один','одна');
str := REPLACE(str,'два','две');
str := REPLACE(str,'о$$ди$$ннадцать','одиннадцать');
END IF;
IF gender = 'с' THEN
str := REPLACE(str,'одиннадцать','о$$ди$$ннадцать');
str := REPLACE(str,'один','одно');
str := REPLACE(str,'о$$ди$$ннадцать','одиннадцать');
END IF;
RETURN str;
END;
Преобразование "суммы прописью" в заданный род (женский или средний).
0
if (nvl(pSubject_ID, 0) = 0) then
...
Вот так матёрые банковские программеры пишут "is null" на PL/SQL
0
WHILE LEFT(@newstr,1)=' '
BEGIN
SET @newstr=SUBSTRING(@newstr,2,LEN(@newstr))
END
Альтернативная реализация LTRIM
0
delete id, name, surname, family from persons;
ага, а типа остальные поля не трогать...
0
select x1.g_id,
(select switch(
str='0','новое строительство',
str='1','подготовка территории',
str='2','реконструкция',
str='3','снос' )
from t1
where g_id=x1.p_id
and f_id in(1,71,81)
and id=1),
(select switch(
str='0','административное здание',
str='1','детский сад',
str='2','дорога',
str='3','жилое здание',
str='4','инженерные сети',
str='5','коммуникации',
str='6','поликлиника',
str='7','путепровод',
str='8','ЦТП',
str='9','школа') from t1
where g_id=x1.p_id
and f_id in(1,71,81)
and id=2),
(select 'Субъект '+
(select str from subj
where type1=1
and id1=int(x3.str))+
switch(
x4.str='0',', город ',
x4.str='1',', деревня ',
x4.str='2',', ПГТ ',
x4.str='3',', поселок ',
x4.str='4',', село ')+
(select str from subj
where type1=3
and id1=int(x5.str))+iif(x6.str,
(select ', '+str from subj
where type1=2
and id1=int(x6.str)),'')+iif(x7.str,
(select ', '+str from subj
where type1=5
and id1=int(x7.str)),'')+iif(x8.str,',микр.'+x8.str,'')+iif(x9.str,', квартал '+x9.str,'')+iif(x10.str,', жил.группа '+x10.str,'')+
(select Format(', '+str) from t1
where f_id in(1,71,81)
and id=12
and g_id=x1.p_id)+iif(x11.str,', вл.'+x11.str,'')+iif(x12.str,', д.'+x12.str,'')+iif(x13.str,', кор.'+x13.str,'')+iif(x14.str,', стр.'+x14.str,'')
from t1 as x3,t1 as x4,t1 as x5,t1 as x6,t1 as x7,t1 as x8,t1 as x9,t1 as x10,t1 as x11,t1 as x12,t1 as x13,t1 as x14
where x3.f_id in(1,71,81)
and x3.id=4
and x3.g_id=x1.p_id
and x4.f_id=x3.f_id
and x4.id=7
and x4.g_id=x3.g_id
and x5.f_id=x3.f_id
and x5.id=8 and x5.g_id=x3.g_id
and x6.f_id=x3.f_id
and x6.id=5
and x6.g_id=x3.g_id
and x7.f_id=x3.f_id
and x7.id=6
and x7.g_id=x3.g_id
and x8.f_id=x3.f_id
and x8.id=9
and x8.g_id=x3.g_id
and x9.f_id=x3.f_id
and x9.id=10
and x9.g_id=x3.g_id
and x10.f_id=x3.f_id
and x10.id=11
and x10.g_id=x3.g_id
and x11.f_id=x3.f_id
and x11.id=13
and x11.g_id=x3.g_id
and x12.f_id=x3.f_id
and x12.id=14
and x12.g_id=x3.g_id
and x13.f_id=x3.f_id
and x13.id=15
and x13.g_id=x3.g_id
and x14.f_id=x3.f_id
and x14.id=16
and x14.g_id=x3.g_id),
(select code1 from fkko,t1
where id1=int(t1.str)
and g_id=x1.g_id
and f_id=x1.f_id
Запрос по теме "Помогите ускорить базу".
Взято здесь: http://sql.ru/forum/actualthread.aspx?bid=4&tid=656930
0
ALTER PROCEDURE [dbo].[SomeProc]
(
@TableName Varchar(500),
@Condition Varchar(1000)
)
--================================================================
-- Stored procedure: SomeProc
-- Description: Returns rows depending on a dynamic condition
--
-- Inputs:
--
-- Returns:
-- Recordset 1: UserID, Name
--
--================================================================
AS
BEGIN
DECLARE @StrQuery varchar(1000)
If charindex('[Tablename]',@tablename) > 0
begin
print 'new'
SET @StrQuery = 'Select * From ' + @TableName + ' Where ' + @Condition
print @tablename
print @condition
print @strquery
end
else
SET @StrQuery = 'Select * From ' + @TableName + ' Where ' + @Condition + ' And [Tablename] = 1'
Exec(@StrQuery)
END
Получили базу, полная таких вот процедур.