Skip to content

Instantly share code, notes, and snippets.

View sytkov's full-sized avatar

Dmitry Sytkov sytkov

View GitHub Profile
@sytkov
sytkov / oracle.sql
Last active August 29, 2015 13:56
Oracle. Comparing string with NULL
declare
v_string varchar2(4000) := '';
begin
if v_string = '' then
raise_application_error(-20000, 'It''s not working!');
else
raise_application_error(-20000, 'Hey, this is empty string!');
end if;
end;
/
@sytkov
sytkov / oracle.sql
Last active December 28, 2015 07:09
Gather table stats
declare
v_owner varchar2(4000) := '?';
type t_varchar2_tab is table of varchar2(4000);
v_tables t_varchar2_tab := t_varchar2_tab(
'?',
'?'
);
begin
for i in 1..v_tables.count loop
dbms_stats.gather_table_stats(
@sytkov
sytkov / run_sql.sql
Last active December 24, 2015 13:59
dbms_xplan.display_cursor call example
select *
from table(
dbms_xplan.display_cursor(
( SELECT max(sql_id) keep (dense_rank first order by last_active_time desc)
FROM V$SQL
WHERE lower(sql_text) LIKE 'select /*+ gather_plan_statistics %'),
'',
'ALLSTATS ADVANCED LAST +PEEKED_BINDS'
)
);
@sytkov
sytkov / run_plsql.sql
Last active December 19, 2015 01:19
Work with DBMS_SQL package
set serveroutput on;
DECLARE
v_cursor_id number;
v_last_scale_division_idx number;
v_column_int number;
v_column_str varchar2(4000);
v_fetched_cnt number;
BEGIN
select max(column_id)
into v_last_scale_division_idx
@sytkov
sytkov / run_sql.sql
Last active December 19, 2015 00:19
declare
v_error_message varchar2(4000);
function is_empty_field(p_field_name in varchar2, p_field_value in varchar2, p_error_message out varchar2)
return boolean is
begin
IF p_field_value is not null then
p_error_message := 'заполнено поле "'||p_field_name||'"';
return true;
end if;
@sytkov
sytkov / query.sql
Created June 26, 2013 06:07
Oracle. Current session longops
SELECT s.username,
sl.sid,
sq.executions,
sl.last_update_time,
sl.sql_id,
sl.sql_hash_value,
opname,
target,
elapsed_seconds,
time_remaining,
@sytkov
sytkov / query.sql
Created June 26, 2013 06:05
Current query from session
select s.sql_id, t.sql_text
from V$SESSION s, v$sqltext_with_newlines t
where
s.status = 'ACTIVE'
and s.username = :p_schema
and s.machine = :p_machine
and t.address =s.sql_address
and t.hash_value = s.sql_hash_value
and s.sid = :p_sid
and s.type <>'BACKGROUND'
@sytkov
sytkov / smb.conf
Created November 9, 2012 12:22
/etc/samba/smb.conf
semanage fcontext -a -t samba_share_t /root/downloads
chcon -R -t samba_share_t /root/downloads
@sytkov
sytkov / gist:4031302
Created November 7, 2012 12:26
/etc/init.d/oracle
#!/bin/sh
# description: Starts and stops the Oracle database and listeners
# processname: oracle
# chkconfig: 2345 20 80
export ORACLE_BASE=/opt/oracle/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1
export ORACLE_SID=vo2
export PATH=$ORACLE_HOME/bin:$PATH
@sytkov
sytkov / gist:4031270
Created November 7, 2012 12:24
/etc/init.d/tomcat7
#!/bin/sh
#
# Description: /opt/tomcat7 Start Stop Restart
# processname: tomcat7
# chkconfig: 2345 20 80
export JDK_HOME=/usr/java/jdk1.6.0_37
export JRE_HOME=/usr/java/jdk1.6.0_37/jre
CATALINA_HOME=/opt/tomcat7
CATALINA_OPTS="-Xms512M -Xmx1024M"