How to tune the SQL & solve UNIQUE Contraint issue using without duplicates
CREATE TABLE REL_ENT_REF
ROLL_ENT VARCHAR2(4 BYTE) NOT NULL,
ROLL_SUB_ENT VARCHAR2(3 BYTE) NOT NULL,
ROLL_ENT_DESCR VARCHAR2(50 BYTE),
ENT VARCHAR2(4 BYTE) NOT NULL,
SUB_ENT VARCHAR2(3 BYTE) NOT NULL,
ENT_DESCR VARCHAR2(50 BYTE)
CREATE UNIQUE INDEX REL_ENT_REF_IDX_PK ON REL_ENT_REF
(ROLL_ENT, ROLL_SUB_ENT, ENT, SUB_ENT);
ALTER TABLE REL_ENT_REF ADD (
CONSTRAINT REL_ENT_REF_IDX_PK
PRIMARY KEY
(ROLL_ENT, ROLL_SUB_ENT, ENT, SUB_ENT);
TOTAL NUMBER OF RECORDS FOR TABLE REL_ENT_REF : 123542
CREATE TABLE REL_COA_REF
ACCT VARCHAR2(9 BYTE) NOT NULL,
ACCT_LVL VARCHAR2(2 BYTE) NOT NULL,
ACCT_ID VARCHAR2(9 BYTE) NOT NULL,
REL_TYPE VARCHAR2(10 BYTE) NOT NULL,
ACCT_TYPE VARCHAR2(2 BYTE) NOT NULL,
ACCT_DESCR VARCHAR2(43 BYTE),
POST_ACCT VARCHAR2(9 BYTE) NOT NULL,
POST_ACCT_TYPE VARCHAR2(2 BYTE),
POST_ACCT_DESCR VARCHAR2(43 BYTE),
SIGN_REVRSL NUMBER
CREATE INDEX REL_COA_REF_IDX_01 ON REL_COA_REF
(ACCT_ID, REL_TYPE, POST_ACCT);
CREATE UNIQUE INDEX REL_COA_REF_IDX_PK ON REL_COA_REF
(ACCT_ID, ACCT, REL_TYPE, POST_ACCT);
TOTAL NUMBER OF RECORDS FOR TABLE REL_COA_REF : 4721918
CREATE TABLE REL_CTR_HIER_REF
ENT VARCHAR2(4 BYTE) NOT NULL,
SUB_ENT VARCHAR2(3 BYTE) NOT NULL,
HIER_TBL_NUM VARCHAR2(3 BYTE) NOT NULL,
HIER_ROLL VARCHAR2(14 BYTE) NOT NULL,
HIER_CODE VARCHAR2(14 BYTE) NOT NULL,
SUM_FLAG VARCHAR2(14 BYTE) NOT NULL,
CTR_OR_HIER VARCHAR2(14 BYTE) NOT NULL,
CTR_DETAIL VARCHAR2(14 BYTE) NOT NULL,
CTR_DESCR VARCHAR2(50 BYTE)
CREATE INDEX REL_CTR_HIER_REF_IDX_01 ON REL_CTR_HIER_REF
(HIER_TBL_NUM, HIER_ROLL, SUM_FLAG);
CREATE UNIQUE INDEX REL_CTR_HIER_REF_IDX_PK ON REL_CTR_HIER_REF
(ENT, SUB_ENT, HIER_TBL_NUM, HIER_ROLL, SUM_FLAG,
CTR_DETAIL, CTR_OR_HIER, HIER_CODE);
CREATE INDEX REL_CTR_HIER_REF_IDX_02 ON REL_CTR_HIER_REF
(ENT, SUB_ENT, HIER_TBL_NUM, CTR_OR_HIER, SUM_FLAG,
CTR_DETAIL);
TOTAL NUMBER OF RECORDS FOR TABLE REL_CTR_HIER_REF : 24151811
CREATE TABLE REL_TXN_ACT_CM
ENT VARCHAR2(4 BYTE),
SUB_ENT VARCHAR2(3 BYTE),
POST_ACCT VARCHAR2(9 BYTE),
CTR VARCHAR2(7 BYTE),
POST_DATE DATE,
EFF_DATE DATE,
TXN_CODE VARCHAR2(2 BYTE),
TXN_TYPE VARCHAR2(1 BYTE),
TXN_AMOUNT NUMBER(17,2),
TXN_DESCR VARCHAR2(46 BYTE),
TXN_SOURCE VARCHAR2(1 BYTE)
CREATE INDEX REL_TXN_ACT_CM_IDX_01 ON REL_TXN_ACT_CM
(ENT, SUB_ENT, POST_ACCT, POST_DATE, EFF_DATE,
TXN_AMOUNT);
CREATE INDEX REL_TXN_ACT_CM_IDX_PK ON REL_TXN_ACT_CM
(ENT, SUB_ENT, CTR, POST_ACCT, POST_DATE,
EFF_DATE, TXN_AMOUNT);
TOTAL NUMBER OF RECORDS FOR TABLE REL_TXN_ACT_CM : 111042301
CREATE TABLE REL_CLPR_TBOX_GL_TXN
ORGANIZATION VARCHAR2(10 BYTE) NOT NULL,
ACCOUNT VARCHAR2(10 BYTE) NOT NULL,
APPLICATION VARCHAR2(10 BYTE) NOT NULL,
AMOUNT NUMBER(17,2) NOT NULL
CREATE UNIQUE INDEX REL_CLPR_TBOX_GL_TXN_IDX ON REL_CLPR_TBOX_GL_TXN
(ORGANIZATION, ACCOUNT, APPLICATION);
DELETE FROM REL_CLPR_TBOX_GL_TXN;
INSERT INTO REL_CLPR_TBOX_GL_TXN
ORGANIZATION,
ACCOUNT,
APPLICATION,
AMOUNT
SELECT --+ INDEX(T REL_TXN_ACT_CM_IDX_PK)
SUBSTR(REL_CTR_HIER_REF.HIER_CODE, 1, 5) || '.....',
TXN.POST_ACCT,
'GL-' || SUBSTR(TXN.TXN_DESCR, 1, 3),
SUM
CASE
WHEN TXN.TXN_CODE IN ('01', '21') THEN 1
WHEN TXN.TXN_CODE IN ('02', '22') THEN -1
ELSE 0
END
CASE
WHEN REL_COA_REF.ACCT_TYPE IN ('01', '25', '30', '40', '90', '95') THEN 1
WHEN REL_COA_REF.ACCT_TYPE IN ('05', '10', '20', '35') THEN -1
ELSE 0
END
REL_COA_REF.SIGN_REVRSL
TXN.TXN_AMOUNT
FROM
REL_TXN_ACT_CM REL_TXN
INNER JOIN
REL_CTR_HIER_REF
ON
REL_TXN.ENT = REL_CTR_HIER_REF.ENT AND
REL_TXN.SUB_ENT = REL_CTR_HIER_REF.SUB_ENT AND
REL_TXN.CTR = REL_CTR_HIER_REF.CTR_DETAIL
INNER JOIN
REL_COA_REF
ON REL_TXN.POST_ACCT = REL_COA_REF.POST_ACCT
INNER JOIN
REL_ENT_REF
ON
REL_CTR_HIER_REF.ENT = REL_ENT_REF.ENT AND
REL_CTR_HIER_REF.SUB_ENT = REL_ENT_REF.SUB_ENT
WHERE
REL_TXN.EFF_DATE BETWEEN L_MONTH AND LAST_DAY(L_MONTH) AND
REL_CTR_HIER_REF.HIER_TBL_NUM = '001' AND
REL_CTR_HIER_REF.SUM_FLAG = 'D' AND
REL_CTR_HIER_REF.CTR_OR_HIER = REL_CTR_HIER_REF.CTR_DETAIL AND
REL_CTR_HIER_REF.HIER_CODE BETWEEN 'AAA' AND 'ZZZ' AND
REL_COA_REF.REL_TYPE = ' ' AND
REL_COA_REF.ACCT_ID = 'ALPTER' AND
REL_COA_REF.ACCT_LVL = '9' AND
REL_ENT_REF.ROLL_ENT = '999' AND
REL_ENT_REF.ROLL_SUB_ENT = '111'
GROUP BY
SUBSTR(REL_CTR_HIER_REF.HIER_CODE, 1, 5),
REL_TXN.POST_ACCT,
SUBSTR(REL_TXN.TXN_DESCR, 1, 3)
HAVING
SUM
CASE
WHEN REL_TXN.TXN_CODE IN ('01', '21') THEN 1
WHEN REL_TXN.TXN_CODE IN ('02', '22') THEN -1
ELSE 0
END
CASE
WHEN REL_COA_REF.ACCT_TYPE IN ('01', '25', '30', '40', '90', '95') THEN 1
WHEN REL_COA_REF.ACCT_TYPE IN ('05', '10', '20', '35') THEN -1
ELSE 0
END
REL_COA_REF.SIGN_REVRSL
REL_TXN.TXN_AMOUNT
) <> 0;
[\CODE]
While try to run the query(only select statement), it is taking around 3+ hours & while try to insert the same query in the table, getting error called ORA-00001: unique constraint (INSIGHT.CLPR_TBOX_GL_TXN_IDX) violated.
[\CODE]
How to tune & resolve this UNIQUE Contraint issue using without duplicates?
Should the SELECT statement be returning duplicate rows? If you know that there are duplicate rows in the underlying tables, you could add a DISTINCT to the select. Which forces Oracle to do an extra sort which will slow down the insert. If you don't expect duplicate rows, you would need to figure out what join criteria is missing from your query and add that criteria.
Justin
Similar Messages
-
How to tune the sql below? can you help on this?
SELECT wonum, MIN (changedate) opendate
FROM wostatus
GROUP BY wonum
Thanks in advance
Thanks,
BalaHi,
You should not focus on COST.
When tuning you need to put several different aspects into consideration.
If you have an execution plan, then post it as well ( remember to use the tag when posting examples! ), just like:
- database version
- information regarding indexes
- table statistics
See:
[How to post a SQL statement tuning request|HOW TO: Post a SQL statement tuning request - template posting
[When your query takes too long...|When your query takes too long ... -
Below is the table structure & index's for the table and Total record count for the table is: 40450708
here, I am selecting distinct of ELIM_NBR from table using below query and it contains only: 1641 records
SELECT DISTINCT ELIM_NBR FROM ELIM_RULE_REF_TBL;while we run the above sql, its taking too long (more than 5 min), could you please help me - how to tune the query to get the distinct of ELIM_NBR from the table...
-- Create table
create table ELIM_RULE_REF_TBL
ENT VARCHAR2(4) not null,
SUB_ENT VARCHAR2(3) not null,
SRC_ACCT VARCHAR2(9) not null,
EFF_FROM_DATE DATE not null,
EFF_TO_DATE DATE not null,
TARG_ENT VARCHAR2(4) not null,
TARG_SUB_ENT VARCHAR2(3) not null,
ELIM_DESCR VARCHAR2(115),
ELIM_NBR VARCHAR2(5),
ELIM_RESID_ACCT VARCHAR2(9),
ENT_LVL NUMBER
tablespace INS_DATA
pctfree 10
initrans 1
maxtrans 255
storage
initial 128M
next 50M
minextents 1
maxextents unlimited
pctincrease 0
-- Create/Recreate indexes
create index ELIMREF_IDX_01 on ELIM_RULE_REF_TBL (TARG_ENT,TARG_SUB_ENT,SRC_ACCT,ELIM_RESID_ACCT,EFF_FROM_DATE,EFF_TO_DATE)
tablespace INS_IDX
pctfree 10
initrans 2
maxtrans 255
storage
initial 50M
next 50M
minextents 1
maxextents unlimited
pctincrease 0
create index ELIMREF_IDX_02 on ELIM_RULE_REF_TBL (TARG_ENT,TARG_SUB_ENT,ELIM_NBR,ENT,SUB_ENT)
tablespace INS_IDX
pctfree 10
initrans 2
maxtrans 255
storage
initial 50M
next 50M
minextents 1
maxextents unlimited
pctincrease 0
create unique index ELIMREF_IDX_PK on ELIM_RULE_REF_TBL (ENT,SUB_ENT,SRC_ACCT,EFF_FROM_DATE,EFF_TO_DATE,TARG_ENT,TARG_SUB_ENT)
tablespace INS_IDX
pctfree 10
initrans 2
maxtrans 255
storage
initial 50M
next 50M
minextents 1
maxextents unlimited
pctincrease 0
);If it is so crucial for you to get this particular query processed as fast as possible there are a couple of things you can evaluate:
* Follow this thread When your query takes too long ... to generate a proper explain plan output and run tkprof on a sql trace of this statement. Post the results here. This provides information where potentially most of time is spent to process the query.
* Create an (additional) index that consists just of the ELIM_NBR, provided that you only query this column and restrict only on that column in the WHERE clause. This builds a smaller index than the currently used index ELIMREF_IDX_02 which should speed up the full index scan.
* Since a sort unique operation is required you could think of increasing your sort memory usage. You haven't mentioned which database version you're running, but if you're already on 9i and have PGA_AGGREGATE_TARGET defined you could switch your session to "WORKAREA_SIZE_POLICY = manual" and setting SORT_AREA_SIZE to a large value, like 100000000 to allow a maximum of 100M for in-memory sorting, depending on your hardware, environment and concurrent usage of the system.
* If you have the suitable license and hardware you could try to increase the speed of the index fast full scan by using the parallel query option:
SELECT /*+ PARALLEL_INDEX(ELIM_RULE_REF_TBL, ELIMREF_IDX_02) */ DISTINCT ELIM_NBR
FROM ELIM_RULE_REF_TBL
WHERE SUBSTR(ELIM_NBR, 2, 1) != '9';Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle:
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/ -
How to Tune the Transactions/ Z - reports /Progr..of High response time
Dear friends,
in <b>ST03</b> work load anlysis menu.... there are some z-reports, transactions, and some programmes are noticed contineously that they are taking the <b>max. response time</b> (and mostly >90%of time is DB Time ).
how to tune the above situation ??
Thank u.Siva,
You can start with some thing like:
ST04 -> Detail Analysis -> SQL Request (look at top disk reads and buffer get SQL statements)
For the top SQL statements identified you'd want to look at the explain plan to determine if the SQL statements is:
1) inefficient
2) are your DB stats up to date on the tables (note up to date stats does not always means they are the best)
3) if there are better indexes available, if not would a more suitable index help?
4) if there are many slow disk reads, is there an I/O issue?
etc...
While you're in ST04 make sure your buffers are sized adequately.
Also make sure your Oracle parameters are set according to this OSS note.
Note 830576 - Parameter recommendations for Oracle 10g -
How to put the SQL-statement returned value into the field (as a default)
Hi,
I am using Developer/2000 (Forms Designer) under windows 98.
Please tell me how to put the SQL-statement value (as a default value) into the field before enter-query mode. Noted that I have tried the following ways but still some problems:-
1) Place the SQL-statement into PRE_QUERY trigger in the form/block level.
There is a message box which ask 'Do you want to save the changes?'.
2) Place the SQL-statement before execute enter_query. There is still a
message box which ask 'Do you want to save the changes?'.
Any hints? Thanks. Urgent.solved it!
1) Suppress DEFAULT save message
if form_failure then
raise form_trigger_failure;
end if;
2) Place the default value before enter-query.
Ref: Title='Default value in query field in ENTER_QUERY mode' in designer forum by CVZ
form level trigger
============
WHEN-NEW-ITEM-INSTANCE
=======================
if :system.mode = 'ENTER-QUERY' then
:block.item := 'default waarde';
end if;
3) Suppress the changes whenever leaving the default field.
if :block.item is null then
-- assign statement
end if; -
How to tune the follwoing procedure?
create or replace procedure sample(verror_msg in out varchar2,
vbrn_num in tb_branches.brn_num%type) is
ltext1 varchar2(500);
ltext2 varchar2(500);
ltable_name varchar2(50);
lcolumn_name varchar2(50);
ldata_type varchar2(50);
lold_rcn_num number;
lnew_rcn_num number;
lvalue varchar2(50);
lunit_type char(1);
lsql_stmt1 varchar2(500);
lstring varchar2(500);
lcol varchar2(10);
lstart_time VARCHAR2(100);
lend_time VARCHAR2(100);
lcommit VARCHAR2(10) := 'COMMIT;';
lfile_handle1 utl_file.file_type;
lfile_handle2 utl_file.file_type;
lfile_handle3 utl_file.file_type;
lfile_handle4 utl_file.file_type;
lfile_name1 VARCHAR2(50) := 'RCN_UPDATE_STMTS_' || vbrn_num || '.SQL';
lfile_name2 VARCHAR2(50) := 'RCNSUCCESS_' || vbrn_num || '.TXT';
lfile_name3 VARCHAR2(50) := 'RCNFAIL_' || vbrn_num || '.TXT';
lfile_name4 VARCHAR2(50) := 'RCNERROR_' || vbrn_num || '.TXT';
ldirectory_name VARCHAR2(100);
ldirectory_path VARCHAR2(100);
lspool_on VARCHAR2(100);
lspool_off VARCHAR2(100);
TYPE ref_cur IS REF CURSOR;
cur_tab_cols ref_cur;
cursor c1 is
SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE
FROM USER_TAB_COLS
WHERE TABLE_NAME NOT LIKE 'TB_CONV%'
and TABLE_NAME LIKE 'TB_%'
AND COLUMN_NAME LIKE '%RCN%'
UNION
SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE
FROM USER_TAB_COLS
WHERE TABLE_NAME in ('TB_UNITCODES', 'TB_HIST_UNITCODES')
AND COLUMN_NAME = 'UNIT_CODE'
order by table_name;
BEGIN
verror_msg := nvl(verror_msg, 0);
begin
SELECT DISTINCT directory_path, directory_name
INTO ldirectory_path, ldirectory_name
FROM tb_conv_path
WHERE brn_num = vbrn_num;
EXCEPTION
WHEN NO_DATA_FOUND THEN
SP_CO_RAISEERROR('00SY00402', 'F', 'T');
WHEN others THEN
SP_CO_RAISEERROR('00SY00401X', 'F', 'T');
END;
lfile_handle1 := utl_file.fopen(ldirectory_name, lfile_name1, 'W', 32767);
lfile_handle2 := utl_file.fopen(ldirectory_name, lfile_name2, 'W', 32767);
lfile_handle3 := utl_file.fopen(ldirectory_name, lfile_name3, 'W', 32767);
lfile_handle4 := utl_file.fopen(ldirectory_name, lfile_name4, 'W', 32767);
SELECT 'SPOOL ' || ldirectory_path || '/LOG_' || lfile_name1
INTO lspool_on
FROM dual;
utl_file.put_line(lfile_handle1, lspool_on);
utl_file.new_line(lfile_handle1, 1);
select 'EXEC SP_CONV_START_TIMELOG(' || '''' || 'LOG_' || lfile_name1 || '''' || ',' ||
vbrn_num || ');'
into lstart_time
from dual;
UTL_FILE.PUT_LINE(lfile_handle1, lstart_time);
UTL_FILE.NEW_LINE(lfile_handle1, 1);
open C1;
loop
Fetch C1
into ltable_name, lcolumn_name, ldata_type;
Exit When C1%notFound;
lsql_stmt1 := 'select column_name from user_tab_columns where table_name =' || '''' ||
ltable_name || '''' ||
' AND column_name in (''BRN_NUM'',''BRANCH'',''BRANCH_NUMBER'')';
begin
execute immediate lsql_stmt1
into lcol;
exception
when no_data_found then
lcol := null;
end;
if lcol is not null then
if ltable_name in ('TB_UNITCODES', 'TB_HIST_UNITCODES') then
ltext2 := 'select distinct ' || lcolumn_name || ' from ' ||
ltable_name ||
' a, (select distinct new_rcn_num col from tb_conv_rcn_mapping where brn_num = ' ||
vbrn_num || ') b where a.' || lcolumn_name ||
' = b.col(+) and b.col is null and a.' || lcolumn_name ||
' is not null and ' || lcol || ' = ' || vbrn_num ||
' and a.unit_type=''9''';
else
ltext2 := 'select distinct ' || lcolumn_name || ' from ' ||
ltable_name ||
' a, (select distinct new_rcn_num col from tb_conv_rcn_mapping where brn_num = ' ||
vbrn_num || ') b where a.' || lcolumn_name ||
' = b.col(+) and b.col is null and a.' || lcolumn_name ||
' is not null and ' || lcol || ' = ' || vbrn_num;
end if;
OPEN cur_tab_cols FOR ltext2;
loop
fetch cur_tab_cols
into lvalue;
exit when cur_tab_cols%notfound;
begin
IF VBRN_NUM IN (21, 6, 7, 8) THEN Commented during NAP HK SIT cycle1
SELECT DISTINCT NEW_RCN_NUM, OLD_RCN_NUM
INTO LNEW_RCN_NUM, LOLD_RCN_NUM
FROM TB_CONV_RCN_MAPPING
WHERE OLD_RCN_NUM = LVALUE
AND BRN_NUM = VBRN_NUM;
/* ELSE
SELECT DISTINCT NEW_RCN_NUM, OLD_RCN_NUM
INTO LNEW_RCN_NUM, LOLD_RCN_NUM
FROM TB_CONV_RCN_MAPPING
WHERE OLD_RCN_NUM = LVALUE
AND NEW_RCN_NUM NOT LIKE '40%'
AND NEW_RCN_NUM NOT LIKE '41%'
AND NEW_RCN_NUM NOT LIKE '42%'
AND NEW_RCN_NUM NOT LIKE '65%'
AND BRN_NUM = VBRN_NUM;
END IF; */ -- Commented during NAP HK SIT cycle1
if ldata_type = 'NUMBER' then
if ltable_name in ('TB_UNITCODES', 'TB_HIST_UNITCODES') and
lcolumn_name = 'UNIT_CODE' then
begin
select distinct unit_type
into lunit_type
from TB_UNITCODES
where lcol = vbrn_num
and unit_code = lvalue
and unit_type = '9';
exception
when no_data_found then
lunit_type := null;
end;
if lunit_type is not null then
ltext1 := 'update ' || ltable_name || ' set ' ||
lcolumn_name || ' = ' || lnew_rcn_num ||
' where ' || lcolumn_name || ' = ' ||
lold_rcn_num || ' and ' || lcol || ' = ' ||
vbrn_num || ' and unit_type = ' || '''9''' || ';';
utl_file.put_line(lfile_handle1, ltext1);
utl_file.new_line(lfile_handle1, 0);
utl_file.put_line(lfile_handle1, lcommit);
utl_file.put_line(lfile_handle2,
ltable_name || ' - ' || lcolumn_name ||
' - ' || lold_rcn_num || ' - ' ||
lnew_rcn_num || ' - ' || vbrn_num);
utl_file.new_line(lfile_handle2, 0);
end if;
else
ltext1 := 'update ' || ltable_name || ' set ' || lcolumn_name ||
' = ' || lnew_rcn_num || ' where ' || lcolumn_name ||
' = ' || lold_rcn_num || ' and ' || lcol || ' = ' ||
vbrn_num || ';';
utl_file.put_line(lfile_handle1, ltext1);
utl_file.new_line(lfile_handle1, 0);
utl_file.put_line(lfile_handle1, lcommit);
utl_file.new_line(lfile_handle1, 0);
utl_file.put_line(lfile_handle2,
ltable_name || ' - ' || lcolumn_name ||
' - ' || lold_rcn_num || ' - ' ||
lnew_rcn_num || ' - ' || vbrn_num);
utl_file.new_line(lfile_handle2, 0);
end if;
else
if ltable_name in ('TB_UNITCODES', 'TB_HIST_UNITCODES') and
lcolumn_name = 'UNIT_CODE' then
begin
lstring := 'select distinct unit_type from ' || ltable_name ||
' where ' || lcol || ' = ' || vbrn_num ||
' and ' || lcolumn_name || ' = ' || '''' ||
lvalue || '''' || ' and unit_type = ' || '''9''';
execute immediate lstring
into lunit_type;
exception
when no_data_found then
lunit_type := null;
end;
if lunit_type is not null then
ltext1 := 'update ' || ltable_name || ' set ' ||
lcolumn_name || ' = ' || '''' || lnew_rcn_num || '''' ||
' where ' || lcolumn_name || ' = ' || '''' ||
lold_rcn_num || '''' || ' and ' || lcol || ' = ' ||
vbrn_num || ' and unit_type = ' || '''9''' || ';';
utl_file.put_line(lfile_handle1, ltext1);
utl_file.new_line(lfile_handle1, 0);
utl_file.put_line(lfile_handle1, lcommit);
utl_file.new_line(lfile_handle1, 0);
utl_file.put_line(lfile_handle2,
ltable_name || ' - ' || lcolumn_name ||
' - ' || lold_rcn_num || ' - ' ||
lnew_rcn_num || ' - ' || vbrn_num);
utl_file.new_line(lfile_handle2, 0);
end if;
else
ltext1 := 'update ' || ltable_name || ' set ' || lcolumn_name ||
' = ' || '''' || lnew_rcn_num || '''' || ' where ' ||
lcolumn_name || ' = ' || '''' || lold_rcn_num || '''' ||
' and ' || lcol || ' = ' || vbrn_num || ';';
utl_file.put_line(lfile_handle1, ltext1);
utl_file.new_line(lfile_handle1, 0);
utl_file.put_line(lfile_handle1, lcommit);
utl_file.new_line(lfile_handle1, 0);
utl_file.put_line(lfile_handle2,
ltable_name || ' - ' || lcolumn_name ||
' - ' || lold_rcn_num || ' - ' ||
lnew_rcn_num || ' - ' || vbrn_num);
utl_file.new_line(lfile_handle2, 0);
end if;
end if;
exception
When NO_DATA_FOUND THEN
utl_file.put_line(lfile_handle3,
ltable_name || ' - ' || lcolumn_name || ' - ' ||
lvalue || ' - ' || 'NO MAPPING FOUND' ||
' - ' || vbrn_num);
utl_file.new_line(lfile_handle3, 0);
when others then
utl_file.put_line(lfile_handle4,
ltable_name || ' - ' || lcolumn_name || ' - ' ||
lvalue || ' - ' || SQLERRM || ' - ' ||
vbrn_num);
utl_file.new_line(lfile_handle4, 0);
end;
end loop;
ELSE
ltext2 := 'select distinct ' || lcolumn_name || ' from ' ||
ltable_name ||
' a, (select distinct new_rcn_num col from tb_conv_rcn_mapping where brn_num = ' ||
vbrn_num || ') b where a.' || lcolumn_name ||
' = b.col(+) and b.col is null and a.' || lcolumn_name ||
' is not null';
OPEN cur_tab_cols FOR ltext2;
loop
fetch cur_tab_cols
into lvalue;
exit when cur_tab_cols%notfound;
begin
IF VBRN_NUM IN (21, 6, 7, 8) THEN Commented during NAP HK SIT cycle1
SELECT DISTINCT NEW_RCN_NUM, OLD_RCN_NUM
INTO LNEW_RCN_NUM, LOLD_RCN_NUM
FROM TB_CONV_RCN_MAPPING
WHERE OLD_RCN_NUM = LVALUE
AND BRN_NUM = VBRN_NUM;
/* ELSE
SELECT DISTINCT NEW_RCN_NUM, OLD_RCN_NUM
INTO LNEW_RCN_NUM, LOLD_RCN_NUM
FROM TB_CONV_RCN_MAPPING
WHERE OLD_RCN_NUM = LVALUE
AND NEW_RCN_NUM NOT LIKE '40%'
AND NEW_RCN_NUM NOT LIKE '41%'
AND NEW_RCN_NUM NOT LIKE '42%'
AND NEW_RCN_NUM NOT LIKE '65%'
AND BRN_NUM = VBRN_NUM;
END IF; */ -- Commented during NAP HK SIT cycle1
if ldata_type = 'NUMBER' then
ltext1 := 'update ' || ltable_name || ' set ' || lcolumn_name ||
' = ' || lnew_rcn_num || ' where ' || lcolumn_name ||
' = ' || lold_rcn_num || ';';
utl_file.put_line(lfile_handle1, ltext1);
utl_file.new_line(lfile_handle1, 0);
utl_file.put_line(lfile_handle1, lcommit);
utl_file.new_line(lfile_handle1, 0);
utl_file.put_line(lfile_handle2,
ltable_name || ' - ' || lcolumn_name || ' - ' ||
lold_rcn_num || ' - ' || lnew_rcn_num ||
' - ' || vbrn_num);
utl_file.new_line(lfile_handle2, 0);
else
ltext1 := 'update ' || ltable_name || ' set ' || lcolumn_name ||
' = ' || '''' || lnew_rcn_num || '''' || ' where ' ||
lcolumn_name || ' = ' || '''' || lold_rcn_num || '''' || ';';
utl_file.put_line(lfile_handle1, ltext1);
utl_file.new_line(lfile_handle1, 0);
utl_file.put_line(lfile_handle1, lcommit);
utl_file.new_line(lfile_handle1, 0);
utl_file.put_line(lfile_handle2,
ltable_name || ' - ' || lcolumn_name || ' - ' ||
lold_rcn_num || ' - ' || lnew_rcn_num ||
' - ' || vbrn_num);
utl_file.new_line(lfile_handle2, 0);
end if;
exception
When NO_DATA_FOUND THEN
utl_file.put_line(lfile_handle3,
ltable_name || ' - ' || lcolumn_name || ' - ' ||
lvalue || ' - ' || 'NO MAPPING FOUND' ||
' - ' || vbrn_num);
utl_file.new_line(lfile_handle3, 0);
when others then
utl_file.put_line(lfile_handle4,
ltable_name || ' - ' || lcolumn_name || ' - ' ||
lvalue || ' - ' || SQLERRM || ' - ' ||
vbrn_num);
utl_file.new_line(lfile_handle4, 0);
end;
end loop;
end if;
end loop;
close c1;
utl_file.new_line(lfile_handle1, 1);
select 'EXEC SP_CONV_END_TIMELOG(' || '''' || 'LOG_' || lfile_name1 || '''' || ',' ||
vbrn_num || ');'
into lend_time
from dual;
UTL_FILE.PUT_LINE(lfile_handle1, lend_time);
UTL_FILE.NEW_LINE(lfile_handle1, 1);
SELECT 'SPOOL OFF;' INTO lspool_off FROM dual;
utl_file.put_line(lfile_handle1, lspool_off);
utl_file.new_line(lfile_handle1, 1);
utl_file.fclose(lfile_handle1);
utl_file.fclose(lfile_handle2);
utl_file.fclose(lfile_handle3);
utl_file.fclose(lfile_handle4);
exception
when others then
verror_msg := sqlcode || ' ~ ' || sqlerrm;
utl_file.put_line(lfile_handle4,
ltable_name || ' - ' || lcolumn_name || ' - ' ||
lvalue || ' - ' || SQLERRM || ' - ' || vbrn_num);
utl_file.new_line(lfile_handle4, 0);
utl_file.new_line(lfile_handle4, 0);
utl_file.fclose(lfile_handle1);
utl_file.fclose(lfile_handle2);
utl_file.fclose(lfile_handle3);
utl_file.fclose(lfile_handle4);
end sample;duplicate:
how to tune the follwoing procedure? -
How to get the sql query result?
Hi,
Currently I am using LV2012 to connect a Oracle database server. After the installations/settings for Oracle Express and Oracle ODBC driver done.
I am sucessfully to use the SQL command to query the data through my window command prompt.
Now the problem is, how I do the same task in Labview by using the database connectivity toolkits?
I have build a VI for query as attached, but i have no idea what pallete to use to get the query result.
Please help me ~~
Solved!
Go to Solution.
Attachments:
Query.vi 9 KBHere is a piece of code I use to test SQL commands, you can use the part that retrieves sql results.
It is also possible to get the column headers back, but that is for next lesson!
Attachments:
RunSQLCommand.vi 30 KB -
How to tune the query...?
Hi all,
I am having a table with millions of records and the query is taking hours
time. How to tune the query apart from doing the following things.
1. Creating or Deleting indexes.
2. Using Bind variables.
3. Using Hints.
4. Updating the Statitics regurarly.
Actually, i have asked this question in interview how to tune the query.
I told him the above 4 things. Then he told, these are not working, then
how you will tune this query.
Thanks in advance,
Paluser546710 wrote:
Actually, i have asked this question in interview how to tune the query.
I told him the above 4 things. Then he told, these are not working, then
how you will tune this query.It actually depends on the scenario/problem given.
You may want to read this first.
When your query takes too long ...
When your query takes too long ...
HOW TO: Post a SQL statement tuning request - template posting
HOW TO: Post a SQL statement tuning request - template posting -
How to find the SQL Server Instances running across the given activer directory domain?
How to find the SQL Server Instances running across the given activer directory domain?
I have though of OSQL -L , Microsoft Assessment and Planning ( MAP ) tool and SQLPing3 (SQLSecurity) might help me.
I would appreciate if there any other way of finding the SQL Servers / Instances running across the given active directory domain.
Sivaprasad S
http://sivasql.blogspot.com
Please click the Mark as Answer button if a post solves your problem!Dear ,
Very simple u find all instances through the customized sp which is get all details about inventory. Like i put the sp bellow. This is without any tool.
USE [master]
GO
/****** Object: StoredProcedure [dbo].[DBStatus] Script Date: 08-01-2015 19:46:11 By Damodar Patle Sr. DBA Mumbai India ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[DBStatus]
AS
SELECT
SERVERPROPERTY('servername') AS ServerName,
ConnectionProperty('local_net_address') AS 'local_net_address',
ConnectionProperty('local_tcp_port') AS 'local_tcp_port',
CONVERT(VARCHAR(25), @@VERSION) as VERSIONSQL,
SERVERPROPERTY('ErrorLogFileName') AS ErrorLogFilePath,
database_id,
CONVERT(VARCHAR(25), DB.name) AS DBName,
CONVERT(VARCHAR(10), DATABASEPROPERTYEX(name, 'status')) AS [Status],
CONVERT(VARCHAR(10), DATABASEPROPERTYEX(name, 'Recovery')) AS [Recovery_Model],
create_date as DBCreate_Date, --physical_device_name,
(SELECT COUNT(1) FROM sys.master_files WHERE DB_NAME(database_id) = DB.name AND type_desc = 'rows') AS DataFiles,
(SELECT SUM((size*8)/1024) FROM sys.master_files WHERE DB_NAME(database_id) = DB.name AND type_desc = 'rows') AS [Data MB],
(SELECT COUNT(1) FROM sys.master_files WHERE DB_NAME(database_id) = DB.name AND type_desc = 'log') AS LogFiles,
(SELECT SUM((size*8)/1024) FROM sys.master_files WHERE DB_NAME(database_id) = DB.name AND type_desc = 'log') AS [Log MB],
(SELECT physical_name FROM sys.master_files WHERE DB_NAME(database_id) = DB.name AND type_desc = 'rows') AS MDF_File_Location,
(SELECT physical_name FROM sys.master_files WHERE DB_NAME(database_id) = DB.name AND type_desc = 'log') AS LDF_File_Location,
user_access_desc
FROM sys.databases DB
ORDER BY dbName, [Log MB] DESC, NAME -
How to view the sql query?
hi,
how to view the sql query formed from the xml structure in the receiver jdbc?You can view SAP Note at
http://service.sap.com/notes
But you require SMP login ID for this which you should get from your company. The content of the notes are as follows:
Reason and Prerequisites
You are looking for additional parameter settings. There are two possible reasons why a feature is available via the "additional parameters" table in the "advanced mode" section of the configuration, but not as documented parameter in the configuration UI itself:
Category 1: The parameter has been introduced for a patch or a SP upgrade where no UI upgrade and/or documentation upgrade was possible. In this case, the parameter will be moved to the UI and the documentation as soon as possible. The parameter in the "additional parameters" table will be deprecated after this move, but still be working. The parameter belongs to the supported adapter functionality and can be used in all, also productive, scenarios.
Category 2. The parameter has been introduced for testing purposes, proof-of-concept scenarios, as workaround or as pre-released functionality. In this case, the parameter may or may not be moved to the UI and documentation, and the functionality may be changed, replaced or removed. For this parameter category there is no guaranteed support and usage in productive scenarios is not supported.
When you want to use a parameter documented here, please be aware to which category it belongs!
Solution
The following list shows all available parameters of category 1 or 2. Please note:
Parameter names are always case-sensitive! Parameter values may be case-sensitive, this is documented for each parameter.
Parameter names and values as documented below must be used always without quotaton marks ("), if not explicitly stated otherwise.
The default value of a parameter is always chosen that it does not change the standard functionality
JDBC Receiver Adapter Parameters
1. Parameter name: "logSQLStatement"
Parameter type: boolean
Parameter value: true for any string value, false only for empty string
Parameter value default: false (empty String)
Available with: SP9
Category: 2
Description:
When implementing a scenario with the JDBC receiver adapter, it may be helpful to see which SQL statement is generated by the JDBC adapter from the XI message content for error analysis. Before SP9, this can only be found in the trace of the JDBC adapter if trace level DEBUG is activated. With SP9, the generated SQL statement will be shown in the details page (audit protocol) of the message monitor for each message directly.
This should be used only during the test phase and not in productive scenarios.
Regards,
Prateek -
How to get the SQL Signon that Agent Jobs "Run As" or "Executed as User"
How to get the SQL Signon that Agent Jobs "Run As" or "Executed as User"?
I have an install SQL scripts that creates a Linked Server. I want to put some security on the Linked Server and only grant the Agent Job Signon (the "Run As" or "Executed as User") access to the linked server. I need to retrieve the
Agent Job Signon (something like "NT SERVICE\SQLAgent$FIDEV360BI02").
I could query certain jobs and SUBSTRING the Message column - using some form of the query below, which would return "Executed as user: NT SERVICE\SQLAgent$SSDEVBI02. The step succeeded." But that is pretty imprecise.
use msdb
SELECT [JobName] = JOB.name,
[Step] = HIST.step_id,
[StepName] = HIST.step_name,
[Message] = HIST.message,
[Status] = CASE WHEN HIST.run_status = 0 THEN 'Failed'
WHEN HIST.run_status = 1 THEN 'Succeeded'
WHEN HIST.run_status = 2 THEN 'Retry'
WHEN HIST.run_status = 3 THEN 'Canceled'
END,
[RunDate] = HIST.run_date,
[RunTime] = HIST.run_time,
[Duration] = HIST.run_duration,
[Retries] = HIST.retries_attempted
FROM sysjobs JOB
INNER JOIN sysjobhistory HIST ON HIST.job_id = JOB.job_id
-- CHANGE THIS
-- WHERE JOB.name like '%GroupMaster%' or Job.name like '%etlv%'
ORDER BY HIST.run_date, HIST.run_timeby default all sql jobs are executed as sql server agent account, unless otherwise a proxy is setup.
you can get the proxy information as Olaf mentioned, if the proxy_id is null for the step, it implies that the job step was executed as sql server service account and in such case it will be null
so, if it is null, it ran as sql server agent account.
so, one work around is get the sql server agent service account and if the proxy is null, that means it ran as sql server agent account, so, use isnull function. the disadvantage would be if the sql server agent account was switched, you might not get the
accurate information as the new account will show up though the job really ran as old account, to get this information, you need to get this from the logmessage column as you mentioned above.
try this code...
/*from sql 2008r2 sp1, you get the service accounts using tsql,otherwise you have to query the registry keys*/
declare @sqlserveragentaccount varchar(2000)
select @sqlserveragentaccount= service_account
from sys.dm_server_services
where servicename like '%sql%server%agent%'
select message,isnull(name,@sqlserveragentaccount) as AccountName
from sysjobhistory a inner join sysjobsteps b
on a.step_id=b.step_id and a.job_id=b.job_id
left outer join sysproxies c on c.proxy_id=b.proxy_id
Hope it Helps!! -
How to identify the SQLs which are using the tables and new columns
Hi
I m using oracle 10G Database in windows. Developers have added some columns in some of the database tables and were asking to check whether there is some impact on performance or not. I have not done this performance tuning before. Kindly help me how to proceed further.
How to obtain the sqls which are touching the tables and the new columns? It would be really great if you can help me with this.
ThanksYou can try to use DBA_DEPENDENCIES to get PL/SQL objects using tables: http://download.oracle.com/docs/cd/B19306_01/server.102/b14237/statviews_1041.htm#i1576452.
However if SQL code is not stored in database in a trigger, a procedure, a function, a package or a view, it is impossible to retrieve all SQL code referencing some table from database dictionary: for this you would have to analyze application source code. -
How to write the sql statement of my finder function in cmp?
hi,
I create a cmp ejb from table INFOCOLUMN,and I create a my finder function ,which sql statement is :
select * from INFOCOLUMN WHERE employee_id=id
employee_id is a column of the table,and id is the finder function parameter.
The error is : invalid column name
So,how to write the sql statement.
Thanks .Mole-
Bind variables are of the form $1, $2, etc., so your query stmt should look like:
select * from INFOCOLUMN WHERE employee_id=$1
-Jon -
Urgent : How to do the SQL trace analysis
Hi Floks,
How to do the SQL Trace analysis and any another tools is there to test abap programming then this tools runtime analysis,extended Programming Checking,Code inspector .How to utilize that tools .please forward me
thanks
sureshHI,
<b>SQL Trace Use:</b>
The SQL Trace function is an on-demand log of selected SQL statements that are issued against the database through the Open SQL Engine. The SQL Trace can be switched on or off dynamically. The log format is database independent. Besides the SQL statement text, each log record contains information about the point in time when the statement was executed, its duration, its input parameters and results (where applicable) as well as context information.
<b>
Features</b>
The SQL Trace is especially useful for:
Development
SQL Trace can help JDO, enterprise beans, servlet and JSP developers to learn which kind of database accesses their code produces.
1. Performance analysis
Typically, performance issues are caused by inefficient database accesses. In this case SQL Trace can be used to show the issued SQL statements and their duration, thus helping to identify inefficient SQL statements.
<b>Activities</b>
Typically, you should use the SQL Trace when you need to check the behavior of a particular application. This is the following scenario:
Look at the below links, you will get the idea
http://help.sap.com/saphelp_erp2005/helpdata/en/d1/801f89454211d189710000e8322d00/content.htm
Re: Runtime Analysis vs SQL Trace
http://www.sapbrain.com/TOOLS/SQLTRACE/SQL_TRACE.html -
How to run the SQL Script in SQL Prompt?
Hi ExpertGroup,
I have written one SQL Script name called "MySQLSCript.SQL". I want to know how to run the SQL Script in SQL Prompt?.
Generally, I run SQL Script in PL/SQL Developer tool. But In this case, some SET command is not working/supporting in PL/SQL Developer Tool.
Let me know, How to Run in SQl Prompt.
Thanks & Regards,
Senthil K Kumar.This is my SQL Script....
SET COLSEP '|'
SET LINESIZE 32767
SET PAGESIZE 50000
/* SET LINESIZE 3000
SET PAGESIZE 50000
SET DEFINE OFF */
SET ECHO OFF
SET FEEDBACK OFF
--SET HEADING OFF
SET TRIMSPOOL ON
SET NEWPAGE NONE
SET UNDERLINE OFF
SPOOL &&EnterPath;
SELECT * FROM &&TableName;
SPOOL OFF
SET FEEDBACK ON
--SET DEFINE ON
PROMPT Done.
I am able to run this script in SQL Prompt....
Its executing fine...
But, If I am executing again it maynot asking for new set of data....
alternativily its taking old values only.....
how can i exeute with new set of data in the sql prompt.....
Maybe you are looking for
-
I want to place an animated gif into an application. I want it to start of not animated then I click a button and it starts. I click another button and the animation stops? Where do I start? I have placed the gif into a JLabel and it starts animating
-
Separate buttons on animated .gif
I have a couple animated .gif files on my website. I use them as scrolling advertisements. I would like to offer link buttons specific to the info on the current frame, however, when i create the button is shows up on all frames. Is there anyway to h
-
Multiple message deletion functionality disappears
My iPhones 5S with iOS 8.1 loses multiple message deletion functionality. I tap a message in communication thread, chose more options, mark messages to be deleted and push waste bin. When used a few times the waste bin is replaced with camera options
-
I would love to know exactly how many contacts I currently have on my Z10. I have multiple contacts synched from various sources and would love to know if there is a way to find out how many contacts are on my Z10 under each server (Work, Gmail, Face
-
Rendering Error: Out of memory
Hi Im having problems wit this error message : "Out of memory" when Im trying to render a sequence in fcp 7.0.2. Ive got a new Imac 27 i7, 8GB ram, system setting are 100% on application memory and still cache. 50min sequence in proress1080 format, w