Sunteți pe pagina 1din 14

ORACLE:

***********
Alter Session In ORACLE:
========================
To change the system message to english.
alter session set NLS_LANGUAGE='ENGLISH';
The syntax for creating a primary key in an ALTER TABLE statement is:
ALTER TABLE table_name
add CONSTRAINT constraint_name PRIMARY KEY (column1, column2, ... column_n)
ALTER TABLE table_name drop CONSTRAINT constraint_name;
convert function (to_date):
=================
to_date('20120318' || ' 00:00:00', 'YYYYMMDD hh24:mi:ss' )
output:
18-03-2012 0:00:00
Describing a Procedure:
=================
1) desc <procedure name > -- gives u only the in/out parameters used by procedur
e.
2) Select text from user_source where name '<procedure name>'
TO check all DB-LINKS
=================
Q:
select * from DBA_DB_LINKS
ALL_SYNONYM Table:
--------------------------------Name
Null?
------------------------ -------OWNER
NOT NULL
SYNONYM_NAME
NOT NULL
TABLE_OWNER
TABLE_NAME
NOT NULL
DB_LINK

Type
------------VARCHAR2(30)
VARCHAR2(30)
VARCHAR2(30)
VARCHAR2(30)
VARCHAR2(128)

CREATE SYNONYM FOR DB-LINK


===========================
Q:
CREATE SYNONYM emp_table
FOR oe.employees@remote.us.oracle.com;
Q:
CREATE PUBLIC SYNONYM emp_table
FOR hr.employees@remote.us.oracle.com;
Q:
USER_SYNONYMS:
ALL_OBJECTS describes all objects accessible to the current user.
Related Views

DBA_OBJECTS describes all objects in the database.


USER_OBJECTS describes all objects owned by the current user. This view does not
display the OWNER column.
splitting into 8 parallels
=================
Q:
UPDATE TMP_DISTINCT_IDS
SET TMP_PARALLEL_ID = DECODE(MOD(ROWNUM,8), 0, 8, MOD(ROWNUM,8));
Eliminating duplicate records from a table in ORACLE
=======================================
Q:
create table <new table> as
select * FROM <table with duplicates> WHERE ROWID IN(SELECT MAX(ROWID) FROM <t
able with duplicates> GROUP BY <unique col>);
Selecting among 1 among the two records that have different values for a field
========================================================
Q:
SELECT A.* INTO #DIST_F_ACT
FROM #DIST_F_ACTIVITY_SK A
where A.LAST_UPD =
(
SELECT MAX(B.LAST_UPD)
FROM
#DIST_F_ACTIVITY_SK B
WHERE B.EVT_ACT_ROW_ID = A.EVT
_ACT_ROW_ID)
eg:
EVT_ACT_ROW_ID
1
1
2

LAST_UPD
20090704
20090709
20090704

Note: Here , when EVT_ACT_ROW_ID=1 then ,record having LAST_UPD = 20090709 will
be choosen.
--Portugese character problem
================================================================================
=============
If you create a table without the alter session. The default will be 'BYTE'
CREATE TABLE CDM.TEST_SEMANTICS (
RCHAR
VARCHAR2(15) NULL
)
GO
insert into CDM.TEST_SEMANTICS(RCHAR) values ('co')
This one will be ok because there are some spare space.
insert into CDM.TEST_SEMANTICS(RCHAR) values ('cooooooooooooo')
This one not because we are trying to insert the max number of chars for that fi
eld and the will consume a extra char.
This happens because to store the character it is required 2 bytes.
By doing the alter session with the option

alter session set nls_length_semantics='CHAR';


The char is enough to store the character.
CREATE TABLE CDM.TEST_SEMANTICS_CHAR (
RCHAR
VARCHAR2(15) NULL
)
GO
insert into CDM.TEST_SEMANTICS_CHAR(RCHAR) values ('cooooooooooooo')

select * from CDM.TEST_SEMANTICS_CHAR


=========
SPOOLING:
=========
set colsep X
a place holder.
set pagesize 0
set trimspool on
set headsep off
ur headings.
set linesize X

-- separate columns with any delimeter were X is


-- only one header row
-- remove trailing blanks
-- this may or may not be useful...depends on yo
-- X should be the sum of the column widths

--create the file were u want , put the path accordingly.


spool Z:\8-Remedy\INC000005159017-F_CLIENT_OPPORTUNITY\test.csv
select distinct ROW_ID from CDC_TMP_S_OPTY; --output gets copied to the file in
the metioned path.
spool off;
================================================================================
==============
UNIX:
******
TO Prevent Hang up:
===============
nohup run_2_L2SP_PAR.ksh >> $log
TO Access Database Through UNIX Server:
===============================
isql -Ujobs_diarios -S `DSS1`
$PASSWORD
use IWS_DATA_STAGING
go
List by sorting and Tailing
==================
ls -lrt <part or full name>* | tail -25
How to pass in a environment variable to isql session in the ksh.

=============================================
First set the variable:
export RAY_JARVIS="SybaseEmployee"
Next call isql with the standard parameters:
isql -Uuser -Ppassword -Sservername <<++
-- issue the select command with external variables in where clause
select * from sybase where employee = "$RAY_JARVIS"
go
++
And thats all you need to do.
Reginald Davis , Former Sybase Employee
MultiLine Comment:
===============
(here Document)
----------------------: <<'END'
comments' here
and here
END
SYBASE:
***********
Otherwise, use ALTER DATABASE or
sp_extendsegment to increase size of the segment.
Last time a procedure was executed:
===========================
MDA tables capture information each time a store procedure is run. So if you wri
te a job to poll into a reposiory table monSysStatement where ProcedureID != 0 a
nd object_name(ProcedureID,dbid) with a getdate() appended at the end should do
the trick
TO check which Table a PROXY is pointing to
=================================
select object_type, object_cinfo, char_value
from
sysattributes
where object_type = 'OD' and
object_cinfo = 'ORC_IWS_RECONCILIATION_TABLE'
To insert into sysservers
=========================
insert into sysservers (srvid,srvname,srvclass,srvinfo,srvreadonly)
values ( 1,'DSS2','asejdbc','vfptdwhdev02:4025/ARBOR','N' )
--go to iws_iq sysservers once and check fo ryour server.
TO AVOID DISCONNECT SITUATIONS WHERE PROCEDURE IS UNAWARE
=========================================================
select @SERVER_STATUS = -1
select @SERVER_STATUS = UP
from IQ_PROXY..SERVER_UP
if ( @SERVER_STATUS <> 1956 )
begin
print "ERROR : NO REPLY FROM IWS_IQ...."
return -2

end
RANDOM RECORDS FROM ASE TABLE
===============================
E.g:
select top 10 id, name, r
=
.id=a.id)
from sysobjects a
where name like 'sys%'
order by r

(select rand() from sysobjects b where b

To Check Table Size & Database Size


============================
To know the size of the Table.
------------------------------------------- valid for ASE
sp_spaceused <tablename>
-- Valid for IQ
sp_iqtablesize 'prd.D_PROPOSITION'
To know the size of the ASE database
------------------------------------------------------sp_helpdb
For syslogs:
-----------------sp_helpsegment 'logsegment'
To know the size of the IQ database
---------------------------------------------------sp_iqstatus
sp_iqdbsize,
********************************************************************************
********************************************************************************
***************************************
execution:IQ
To create only the body structure.
select * into F_SERVICE_REQUEST_BAK
FROM prd.F_SERVICE_REQUEST
where 1 = 2
execution: ASE
To extract the relevant data from fact table.
select * into inter
from IWS_2.dbo.F_SERVICE_REQUEST
where TF_APPLY_TIMESTAMP > dateadd(dd,-1,getdate())
execution: IQ
To insert data from ONLINE to IQ.
insert into F_SERVICE_REQUEST_BAK location 'DSS2_PPRD.IWS' packetsize 32768 {sel
ect * from dbo.inter }
OR
insert into ENG_CDR_IN_IMEI_REC location 'ENG_CDR_IQ.ENG_CDR_IQ' packetsize 3276
8{ select * from ENG_CDR_IN_IMEI_REC }

ODSDEV-CONNECTION-STRING:

'vfptodsdev01SS2005.SIEBEL_ODS'

********************************************************************************
********************************************************************************
***************************************
How to find procedures:
**************************
if exists(select 1 from sysprocedure where proc_name = 'ENG_CDR_IN_IMEI_REC' and
user_name(creator) = 'prd')
begin
print 'Dropping procedure prd.ENG_CDR_IN_IMEI_REC...'
drop procedure prd.ENG_CDR_IN_IMEI_REC
end
go
********************************************************************************
********************************************************************************
***************************************
GRANT
======
Q:
GRANT
{ ALL [ PRIVILEGES ]
| ALTER
| DELETE
| INSERT
| REFERENCES [ ( column-name [, ...] ) ]
| SELECT [ ( column-name [, ...] ) ]
| UPDATE [ ( column-name,... ) ]
... ON [ owner.]table-name TO userid [, ...] [ WITH GRANT OPTION ]
Q:
grant execute on <stored_proc> to <(role)or(group)or(userid)>
Check whether a table exists or not
*****************************************
Q:
if exists (select * from sysobjects where id = Object_id('tablename') and type i
n ('U','S'))
EXTRACTING PROCEDURES
======================
Q:
select proc_defn
from sysprocedure
where proc_name= 'ENG_CDR_IN_IMEI'
********************************************************************************
***************************************************
Renaming Procedures:
Q:
sp_rename <old name without db.schema prefix> , <new name without db.schema pref
ix>
or
Q:
alter table [table_name] RENAME [old_column_name] TO [new_column_name]

or
Q:Column Rename
sp_rename "A_SCOV2_USAGE_REVENUE.DW_SERV_ID", DW_ORIG_SERV_ID
or
Q:Table rename
sp_rename A_SCOV2_USAGE_REVENUE , A_SCO_USAGE_REVENUE
********************************************************************************
***************************************************
ALTER COMMAND:
alter table <table name>
eg: (cost was int before)
alter table testbkp

modify <coulmn><datatype>,<coulmn><datatype>
modify COST float

In IQ:
Drop the column and then add, MODIFY does not work
alter table prd.COMMISSIONS_BILLING_DATA delete MOUNT_CREDIT
alter table prd.COMMISSIONS_BILLING_DATA add MOUNT_CREDIT integer
********************************************************************************
***************************************************
IF statement in IQ -> It's different
=============
a)
if @EXTRACOUNT <> 0 then
print 'Inside If';
end if;
b)
if (

@FISCAL_NUM = "111111111"
or
@FISCAL_NUM = "222222222"
@FISCAL_NUM = "888888888"
@FISCAL_NUM = "999999999" )

c)
begin
if exists(select getdate() ) then
print 'YES'
end if
end
d)
begin
if exists(select getdate() )
begin
print 'YES'
print
'yes2'
end
end
FINDING THE user.

or
or

======================================
Q:
select uid,name
from sysusers
where uid in (122,121)
group by uid
Find all objects in a Schema
=====================
Q:
SELECT TYPE,
name,crdate
FROM SYSOBJECTS
WHERE UID IN ( select uid from sysusers
GROUP BY TYPE,name,crdate
ORDER BY TYPE

where name = 'KHANS')

FINDING THE PROCEDURES THAT USE A TABLE.


======================================
Q:
select name
from sysobjects
where id in (
SELECT A.id
FROM syscomments A
WHERE A.text LIKE '%_INTERCONN..CDR_ICT7_CONTROL%'
)
and type = 'P'
OUTPUT:
Find View Structure
==============
select viewtext
from sysviews
where viewname = 'F_CALL_DETAIL_RECORD_TO_SUM'
Querinq
tem Table USER_SYNONYMS
=====================================
Q:
SELECT synonym_name, table_owner, table_name
FROM USER_SYNONYMS
Create Proxy Table
==================
Aqua:
CREATE PROXY_TABLE dbo.ENG_CDR_IN_SERV
EXTERNAL TABLE
AT 'IWS_IQ..prd."ENG_CDR_IN_SERV"'
SqlAdvantage:
CREATE PROXY_TABLE V_TMP_CDR_PPB_T
EXTERNAL TABLE
AT 'IWS_IQ..khans.V_TMP_CDR_PPB_T'
--iq SYNTAX
CREATE EXISTING TABLE CUSTOMER_ID_EQUIP_MAP
AT 'DSS1.ARBOR.dbo.CUSTOMER_ID_EQUIP_MAP'
Creating Index
=======================
CREATE [UNIQUE] [CLUSTERED | NONCLUSTERED]

INDEX index_name ON table (column [,...n])


[WITH
[PAD_INDEX]
[[,] FILLFACTOR = fillfactor]
[[,] IGNORE_DUP_KEY]
[[,] DROP_EXISTING]
[[,] STATISTICS_NORECOMPUTE]
]
[ON filegroup]
=============================
Eliminating duplicate records from a table
=============================
********************************************************************************
********************************************************************************
**************************************
There are a number of different ways to achieve this, depending on what you are
trying to achieve. Usually, you are trying to remove duplication of a certain
key due to changes in business rules or recognition of a business rule that was
t applied when the database was originally built.
Probably the quickest method is to build a copy of the original table:
select
into
from
where

*
temp_table
base_table
1=0

Create a unique index on the columns that covers the duplicating rows with the
ignore_dup_key attribute. This may be more columns that the key for the table.
create unique index temp_idx
on temp_table(col1, col2, ..., colN)
with ignore_dup_key
Now, insert base_table into temp_table.
insert temp_table
select * from base_table
You probably want to ensure you have a very good backup of the base_table at
this point, coz your going to clear it out! You will also want to check to
ensure that the temp_table includes the rows you need. You also need to ensure
that there are no triggers on the base table (remember to keep a copy!) or RI
constraints. You probably do not want any of these to fire, or if they do, you
are aware of the implications.
********************************************************************************
********************************************************************************
**************************************
========
Convert:
========
select CONVERT(smalldatetime, '20090101', 105)
select convert(timestamp,convert(char(8),getdate(),112) )

--To check
Select cast('2008-09-16' as date) ,convert(date,'16/09/2008',103), date('2008-09
-16')
First day of the month from a given date
=============================
select convert(int,convert(varchar(8),dateadd(dd,-(day(@d)-1),@d),112))
@d-> getdate(),integer,varchar
--sqlserver coversion removing fraction seconds
select to_timestamp('Jan 4 2011 1:17:20:230PM','MON DD YYYY HH12:MI:SS:FF3 AM'
,'nls_date_language = American') from dual
use to_char() if the target column is a character column.
sp_helpdb <>
sp_helpdevice
sp_helpkey <>
sp_helpconstraints <>
********************************************************************************
********************************************************************************
**************************************
Change Password:
=============
sp_password "<OLD-PASSWORD>" , "<NEW-PASSWORD>",<USER-NAME>
sp_iqpassword
********************************************************************************
********************************************************************************
**************************************
Using constraints and alter table
========================
If the index on the table was created using a constraint, follow these steps to
re-create a clustered index:
Drop the constraint:
---------------------------alter table <huge_tab> drop constraint prim_key
Re-create the constraint, thereby re-creating the index:
-----------------------------------------------------------------------------alter table <huge_tab> add constraint prim_key
primary key clustered (key_col)
on <segment>
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||
Test from dev:
****************

ssh dwh_app@ptxsa315
AUTOSYS:
Autosys Server from Putty:
*******************************
ptalsun41
uid:pwd: dwh_app
/dwh_app/sched.env /dwh_app/bin/scripts/sched/sched.sh L0SP_UPD_PARAM_CDTRPT SYB
ASE_CONNECTION3 SYBASE_CONNECTION34 DMK N 1
SYBASE_CONNECTION3
Where the Tng table is
SYBASE_CONNECTION34
Where the procedure is
DMK or anything in that position specifies the key word to be attached to the Tn
g table name like Tng_XXXXX_DMK
N
Specifies Not parallel ( but for parallel jobs w
e leave N as it in )
1
The number at this position indicates the CPU to
which this process will be allocated [Values can range from 1-7]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Q:
I am trying to find a query that will return a list of all columns that are part
s of the primary key of a particular table.
output:
select
object_name(sysindexes.id),
sysindexes.indid,
sysindexes.keycnt,
syscolumns.colid,
index_col(object_name(sysindexes.id), sysindexes.indid,
syscolumns.colid)
from sysindexes, syscolumns
where sysindexes.id = syscolumns.id
and syscolumns.colid <= sysindexes.keycnt
and sysindexes.id = object_id('Table1')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BCP
===
Online tables-BCP is the only option
bcp IWS_DATA_STAGING..ORC_DLT_F_SERVICE_REQUEST out ORC_DLT_F_SERV_REQ.bcp -Ujob
s_diarios -SDSS2 -P$PASSWORD -n -A4096 > $SCHED_LOG_DIR/SRV_REQ/$SCHED_JOB_NAME.
$data
bcp ARBOR..DESCRIPTIONS out DESCRIPTION_EXTRACT.bcp -U KHANS -S DSS2 -P Vodafone
_1600 -c -t '|' -r '^' -A 32768
bcp ARBOR..DESCRIPTIONS in DESCRIPTION_EXTRACT.bcp -U khans -S DSS2 -P Vodafone2
009 -c -t '|' -r '^' -A 32768

IQ tables:
Temporary options is the best options to extract data.
Load command is best to load data.
If u get an error like this:
CTLIB Message: - L0/O0/S0/N0/0/0:
blk_init(): blk layer: CT library error: Cannot find an equivalent CS_TYPE for t
his TDS data type 822083584
blk_init failed.
change column datatype whose data type is date to datetime
Q:
OUTER JOINS
===========
SELECT *
FROM
TableA LEFT JOIN TableB ON Table.col=TableB.col LEFT JOIN
TableC ON TableB.col=TableC.col
SELECT StudentID
FROM lessons
LEFT OUTER JOIN students
ON (lessons.LessonID = students.LessonID AND students.studentID = #studentID#)
================================================================================
===============================================
solution for Cross Server Insert Location problem:
==================================================
When this problem (unable to do "insert into location" inside a prd
owned stored procedure run with another user) arises after a server
restart, you need to do the following:
1) login as prd / Dev@2006
2) create table #a (a int)
3) insert into #a location 'DSS2.IWS' {select 1}
4) logout
This should have been done by the DBAs, so you can always remind them in
the INC itself.
But in case they don't do it, that's the solution.
sp_remotesql
============
--Target Is Iq
exec sp_remotesql "IWS_IQ",@CDC_DELETE_STR, @COMMIT_STR, @CDC_INSERT_STR, @COMMI
T_STR, @D_DELETE_STR, @COMMIT_STR,@D_INSERT_STR,@COMMIT_STR
Syncing IQ data
===============
cd /dwh_app/devdata_transfer/SYNC_DEV/IQ/TABLE SYNC_IQ.sh IWS_IQ prd D_LOYAL_POI

NT_BAND TOTAL samathrs


Syncing data of a TABLE from IT's ONLINE REPLICA to IT's IQ REPLICA
===================================================================
--Search for procs with names like dbo.SYNC_IQ_CDC_D_SERVICE
--They basically Use Insert into location command.
So the insert into location can be directly used ti synce ,Only diffference is w
hen pulling data from ONLINE these SPs
use a time stamp so, gotta watch out for that and understand why that is being u
sed.
Eg: PT-017012 -u used it in DEV to sync D_SERVICE

IDENTITY INSERT ON/OFF


======================
set identity_insert IWS.dbo.D_BUSINESS_LINE on
TRACKING TEMPORARY TABLES
=========================
IF OBJECT_ID('tempdb..#OPTSERV') IS NOT NULL
PRINT '#some_temp_name exists.'
ELSE
PRINT '#some_temp_name does not exist.'
How to drop a session in IQ/KILL a session In IQ
================================================
sp_iqconnection and find out ConnHandle(a number)
After that execute
drop connection <ConnHandle>
Transaction Log:
================================================================
You can clear the transaction log by using the following command
Dump tran < db_name > to < file_name >
OR
Dump tran < db_name > with truncate_only
OR
Dump tran < db_name > with no_log
Please read the sybase documents for more details.
Note : Dump tran will not work, if your database option is set
to "truncate log on checkpoint".
if still log is not cleared then, either you can kill the process
or can abort the transaction log by using lct_admin command.
If you want to increase the size of the transaction log of a database, you can
increase it by using:

alter database < db_name > log on < logical_device_name > = '100M'
==================================================================
To list all running processes in windows:
>tasklist.exe
To kill any hanged process in windows:
>TASKKILL /F /IM notepad++.exe
--/F for forced
--/IM is image name , Eg- u can give note* to match all the program beginning wi
th that name.

S-ar putea să vă placă și