Solve: instr/substr
Please help solve this question i am stuck on
We have the following value that we can use:
Numeric: 0-34 and 80-100 only
or Non Numberic X S U D- D D+
Have to use INSTR and SUBSTR functions to test that the value is a valid
(for now only trying to create a function which can later be put into a procedure.)
SELECT TO_NUMBER('12 ') //e.g HERE 12 and a space for the values as above
FROM DUAL
the where clause looks at all three spaces to make sure values are correct (given number or non-numberic values only)
(Hence if the number is true then number comes back (meaning true)
or it says NO rows)
If value is non numeric, test it to allow non numberic also.
I am completely unsure about it but tried this
SELECT TO_NUMBER('34 ')
FROM DUAL
WHERE INSTR('0123456789',1,1)<=9 (looking at first number ?)
AND
INSTR('0123456789',2,2)<=9
AND
INSTR('0123456789',3,3)=0;
Something like this has to be done.....subst (instr, x,x,) i think mite help.
Why not use regular expressions? The below thread gives you an example and instructions on how to use.
alphanumeric validation
Similar Messages
-
i have a problem in writing a query.
It is a simple select having a "IN" clause, the values of which are created dynamically.
Now since the IN clause could exceed 1000 values at a time, im using it as shown below
select * from table where (col1 in () or in () or in()....);
but my problem is that Im unable to set limit for values inside the IN clause.The values in the IN clause are in format ' %' i.e they are quoted and have a varaible length which Im trying to retrieve either thru INSTR or through SUBSTR.
I get these dynamic values in a varaible.Then i have to select the values for the IN clause from this variable.
Kindly help...its urgentWhy bother with instr/substr and the limitation of the IN clause?
Try to generate a select statement out of your csv format (lots of examples out there). One way could be:
SQL> var str varchar2(100)
SQL> var cur refcursor
SQL> exec :str := 'scott,james'
PL/SQL procedure successfully completed.
SQL> begin
open :cur for
select empno, ename from emp
where ename in (
select upper (t.column_value.extract ('//text()'))
from table(cast(xmlsequence(xmltype ('<d><d>'|| replace (:str, ',', '</d><d>') || '</d></d>').extract ('d/d')) as sys.xmlsequencetype)) t);
end;
PL/SQL procedure successfully completed.
SQL> print cur
EMPNO ENAME
7788 SCOTT
7900 JAMES -
Query Help... INSTR/SUBSTR/SUBSTR_REGEXTRACT
basically, I am trying to convert timezone of my incoming record from UTC to local timezone of the record. Essentially, I am going to do this from a lookup table that contains all the UTC conversions to local timezone.
so, if I have 3 possible patterns of of records:
(GMT-05:00) Eastern Time (US & Canada)
(GMT+02:00) Harare, Pretoria
(GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London
and I want to get the numeric value (if available else 0)
so for the first record I would want -5
for the second recodr I want 2
for the third record I want 0
from my select query. how would I do that? ne ideas...with SQL query if possible..the DB is Oracle..
ne suggestions?Or
SQL> with t as (
select '(GMT-05:00) Eastern Time (US & Canada)' time_z from dual union
select '(GMT+02:00) Harare, Pretoria' from dual union
select '(GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London' from dual
select time_z, nvl(to_number(regexp_substr(time_z, '[+-]\d+')),0) diff
from t
TIME_Z DIFF
(GMT) Greenwich Mean Time : Dublin, Edinburgh, Lisbon, London 0
(GMT+02:00) Harare, Pretoria 2
(GMT-05:00) Eastern Time (US & Canada) -5
3 rows selected. -
Using multiple xdofx commands together. For eg: substr and instr
Hi,
I am working in developing an RTF where a situation is to use xdofx:sustr and xdofx:instr together.
I tried but its not working properly.
Is there any special commands to use in such a scenario.
Thanks,
Anandplz post what are you doing
works for me
as example
<?xdofx:substr(substr(COLOR,5),instr(substr(COLOR,5),’;’)+1)?>for
<ROWSET>
<ROW>
<COLOR>qwe qwe;rty</COLOR>
</ROW>
</ROWSET>gives
rty -
Replace substr, instr with Reg_exp, is this possible,
Hi Team,
I have Small requirement below, i have writen Query For this but was thinking Is there Any better way Of
doing it, esp With Use To reg_exp,
i have Some code As shown below
'23456_TR_ABC_CODE12_JPM-(1)100-(1)150'
From this code i Only want portion which Is Between 'TR_' And '_CODE12' i.e. ABC,
given Is my Query And its output
Select
substr( substr('23456_TR_ABC_CODE12_JPM-(1)100-(1)150',instr('23456_TR_ABC_CODE12_JPM-(1)100-(1)150','TR_',1,1)+3),
1,
instr(
substr('23456_TR_ABC_CODE12_JPM-(1)100-(1)150',instr('23456_TR_ABC_CODE12_JPM-(1)100-(1)150','TR_',1,1)+3),
'_',1,1
-1) "word"
From dual;
word
1 ABC
kindly let me know If there Is Any better way Of doing it,,,Jeneesh, in case there are several TR_ or _CODE12 in the line I'd advice to use non-greedy operators.
SQL> with t as
2 (select '23456_TR_ABC_CODE12_JPM_(1)_100_CODE12_ASJ' word from dual)
3 select regexp_replace(word, '.*TR_<font color="red">(.*)</font>_CODE12.*', '\1') word
4 from t;
WORD
<font color="red">ABC_CODE12_JPM_(1)_100</font>
SQL>
It is working with (+) sign.
SQL> with t as
2 (select '23456_TR_ABC_CODE12_JPM_(1)_100_CODE12_ASJ' word from dual)
3 select regexp_replace(word, '.*TR_<font color="blue">(.+?)</font>_CODE12.*', '\1') word
4 from t;
WORD
<font color="blue">ABC</font>
SQL>
But I don't understand why it is not working with (*) sign :((
SQL> with t as
2 (select '23456_TR_ABC_CODE12_JPM_(1)_100_CODE12_ASJ' word from dual)
3 select regexp_replace(word, '.*TR_<font color="green">(.*?)</font>_CODE12.*', '\1') word
4 from t;
WORD
<font color="green">ABC_CODE12_JPM_(1)_100</font>Maybe someone can explain?
Several more examples:
the first and the last of them are really strange, at least for me:
SQL> with t as
2 (select '23456_TR_ABC_CODE12_JPM_(1)_100_CODE12_ASJ' word from dual)
3 select regexp_replace(word, '^<font color="red">.*</font>TR_<font color="red">(.*?)</font>_CODE12.*$', '\1') word
4 from t;
WORD
<font color="red">ABC_CODE12_JPM_(1)_100</font>
SQL>
SQL> with t as
2 (select '23456_TR_ABC_CODE12_JPM_(1)_100_CODE12_ASJ' word from dual)
3 select regexp_replace(word, '^<font color="blue">.*?</font>TR_<font color="blue">(.*?)</font>_CODE12.*$', '\1') word
4 from t;
WORD
<font color="blue">ABC</font>
SQL>
SQL> with t as
2 (select '23456_TR_ABC_CODE12_JPM_(1)_100_CODE12_ASJ' word from dual)
3 select regexp_replace(word, '^<font color="red">.*?</font>TR_<font color="red">(.*)</font>_CODE12.*$', '\1') word
4 from t;
WORD
<font color="red">ABC</font>
SQL> -
Ex: Table : inputval
Column: inputvalue VARCHAR2(100)
DATA for above column are
TCC=0471/12345/0999/8548/4321,VT=15,PRIMDX=false,DUR=365,VISITS=0
values termination are '/'
Q: i need to after TCC value from the inputvalue column
i need 6 values output are below
1. 471
2. 12345
3. 0999
4. 8548
5. 4321
6. null
i written query but i am not able to get these output
i am giving sample query which i tried for one value
SELECT
case when inputvalue like '%TCC=%' then
substr(substr(inputvalue,to_number(instr(inputvalue,'TCC=')+4),
to_number(instr(inputvalue,',',instr(inputvalue,'TCC=')+4))
-to_number(instr(inputvalue,'TCC=')+4)),1,
instr(substr(inputvalue,to_number(instr(inputvalue,'TCC=')+4),
to_number(instr(inputvalue,',',instr(inputvalue,'TCC=')+4))
-to_number(instr(inputvalue,'TCC=')+4)),'/')-1) end tcc1,
case when inputvalue like '%TCC=%' then
substr(substr(inputvalue,to_number(instr(inputvalue,'TCC=')+4),
to_number(instr(inputvalue,',',instr(inputvalue,'TCC=')+4))
-to_number(instr(inputvalue,'TCC=')+4)),
instr(substr(inputvalue,to_number(instr(inputvalue,'TCC=')+4),
to_number(instr(inputvalue,',',instr(inputvalue,'TCC=')+4))
-to_number(instr(inputvalue,'TCC=')+4)),'/')+1,
instr(substr(inputvalue,to_number(instr(inputvalue,'TCC=')+4),
to_number(instr(inputvalue,',',instr(inputvalue,'TCC=')+4))
-to_number(instr(inputvalue,'TCC=')+4)),'/',2)-1) end tcc2
FROM inputval
please solve me as early as possible
Thanks,
krishHi,
REGEXP_SUBSTR ( s
, '[^,]+'
, 1
, n
)returns the nth item in a comma-delimited list s. (It retuirns NULL if there are not that many items.)
Cross-join with a counter table to get the values for n, and test if the nth item is the one that starts with 'TCC='.
Depending on you data, it might be easier to use REGEXP_SUBSTR or REGEXP_REPLACE to find the part of the string between 'TCC=' and the next comma. (I can't tell from the one row of sample data.)
Once you have the TCC-substring, use REGEXP_SUBSTR again to get the m-th item from the /-delimited list. (Use a different counter table.)
If you need more help, post some more test data and desired results, testing any special cases, such as:
two or more 'TCC=' items in one string
NULL entries ('TCC=1///4')
Misplaced label ('1/2/TCC=3/4/5')
malformed numbers ('TCC=1.0.0/4')
REGEXP_ function only work in Oracle 10 and up. -
Any Function which can solve my problem.
Hi all
I am working on Character based report from which i use to take print on my check using dot matrix printer.
my query is
1) when i want to type my amount in words there may be chances of overlapping my amount in words with other field because may be the value is too large.
for e.g here in front of rupee that much character be fix other may go to other line.
PAY............................................................
RUPEES....................................................... RS.2206
i have tried
SELECT SUBSTR('Two Thousand Two Hundred Six only',1,25) FROM DUAL
SELECT SUBSTR('Two Thousand Two Hundred Six only',25,100) FROM DUAL
but some time the value get changed then like 3206
then
if we will use same in report
SELECT SUBSTR('Three Thousand Two Hundred Six only',1,25) FROM DUAL
SELECT SUBSTR('Three Thousand Two Hundred Six only',25,100) FROM DUAL
PAY............................................................
RUPEES.Three Thousand Two Hundre. RS.2206
ed Six only.
run time in report.it should not come like this.
is there any function or solution for this.assuming your max length is 25, this sql will split the string at the last blank:
WITH t As (
SELECT 'Three Thousand Two Hundreed Six only.' text FROM dual UNION
SELECT 'Two Hundreed Six only.' FROM dual UNION
SELECT 'Three Thousand Three Hundreed Three only.' FROM dual
SELECT
SUBSTR(text, 1, INSTR(SUBSTR(text, 1, 25), ' ', -1) - 1) row1,
SUBSTR(text, INSTR(SUBSTR(text, 1, 25), ' ', -1) + 1) row2
FROM t;
ROW1
ROW2
Three Thousand Three
Hundreed Three only.
Three Thousand Two
Hundreed Six only.
Two Hundreed Six
only. -
Like is not working with substr...
Hello,
I am trying to do
FOR i IN (SELECT grp.group_id
FROM ems.groups grp, ems.groups_loc gl, ems.location loc
WHERE grp.group_id = gl.group_id
AND loc.loc_id = gl.loc_id
AND gl.loc_id = i_loc_id
AND (UPPER(group_desc) LIKE (UPPER(SUBSTR (location_desc, 3,INSTR(SUBSTR(location_desc,3,LENGTH(location_desc)),',')-1)) || ' IT')
OR UPPER(group_desc) LIKE (UPPER(SUBSTR (location_desc, 3,INSTR(SUBSTR(location_desc,3,LENGTH(location_desc)),',')-1)) || ' FACILITIES' ))
) LOOP
Here there is data with UPPER(SUBSTR (location_desc, 3,INSTR(SUBSTR(location_desc,3,LENGTH(location_desc)),',')-1)) || ' IT') as well as (UPPER(SUBSTR (location_desc, 3,INSTR(SUBSTR(location_desc,3,LENGTH(location_desc)),',')-1)) || ' FACILITIES' )),
But it seems to be 'LIKE' is not working.
Can please anybody help me with this problem.
Thanks.Sorry, for insufficient information.
here i have location desc as 39 Herndon, VA, 11 Jacksonville, FL, 48 Pittsburgh, PA. From these description i have to get Herndon, Jacksonville, Pittsburgh and then check group_desc = 'HERNDONIT' OR 'HERNDON FACILITIES'.
I am trying with,
(UPPER(group_desc) LIKE (UPPER(SUBSTR (location_desc, 3,INSTR(SUBSTR(location_desc,3,LENGTH(location_desc)),',')-1)) || ' IT'|| '%')
OR UPPER(group_desc) LIKE (UPPER(SUBSTR (location_desc, 3,INSTR(SUBSTR(location_desc,3,LENGTH(location_desc)),',')-1)) || ' FACILITIES' || '%' ))
But its not working correctly. Eventhough there is data i am not getting any row return.
Thanks,
Gayatri. -
Good morning...
I got a sub sequence of a string... n now I'm trying to use this sub string as a string... but the javac only tells me a warning like incompatible types...
inputLine.subSequence(tamanho-contador,tamanho-(contador-5))
I tryed to convert that charSequence (that java says me) and convert to a string.. but it brings me that java.lang.Object cannot be applied to java.lang.charSequence
How may I do to take that substring n use like another independent string?
I would like to put more three chars before convert it.
Like:
abc123def
I took c123d using subSequence n I want to put more three chars "jav" to finally my string stay like c123djav
How may I do to put more chars n convert it to a String? (In start I was suposed that the substring was a string... but it makes me an error....)
Thanks...Ok... I used that
String anT = inStr.substring(inStr.indexOf('c'), inStr.length()-2)+"jav";
But it makes a warning like:
subSequence(int,int) in java.lang.String cannot be applied to (int, java.lang.String)
I think I need to mix the "jav" after take the string... c123d ... but even only taking that subSequence, and trying to put in a string, I have a warning like:
incompatible types
found: java.lang.charSequence
required: java.lang.String -
Dear all,
I have a string that will spool to a file from sql*plus, and the string maybe more than 255 characters, e.g.:
v_sql := 'select surname, firstname, sex, birth,
address1, address2,
address3, ..., .... from employee;'
dbms_output.put_line(v_sql);
Now, I want to chop the string in several lines when 'meet' the comma ',' , the output I want become to, e.g.:
dbms_output.put_line('select surname,');
dbms_output.put_line('firstname,');
dbms_output.put_line('sex,');
dbms_output.put_line('... from employee;');
So, I use the loop and instr in a procedure:
procedure xxx (p_sql in varchar2) is
v_len number := length(p_sql);
v_comma number := 0;
v_next_comma number := 0;
v_string varchar2(1000);
begin
for v_cnt in 1..v_len loop
if v_comma = 0 then
v_comma := instr(p_sql, ',');
v_string := substr(p_sql, 1, v_comma-1);
dbms_output.put_line(v_string);
else
v_comma := instr(p_sql, ',');
v_next_comma := instr(substr(p_sql, v_comma+1, v_len-v_comma), ',');
v_string := substr(p_sql, v_comma+1, v_next_comma-1);
dbms_output.put_line(v_string);
end if;
if v_comma > 0 and v_next_comma = 0 then
v_cnt := v_comma +1; <--- v_cnt will not change
elsif v_next_comma > 0 then
v_cnt := v_next_comma +1;
end if;
end loop;
end xxx;
From the above coding, however, I found a problem that v_cnt will not skip to the 'comma' position. And I feel that it is not efficient if the length of the string is very long...
So, is there another way to do? Please help. Thank you!
Remarks: Database 10g.
Regards.yes, it would see that you aren't running 10r2. here is the code you need
http://www.oraclecommunity.net/group/sqlplus/forum/topic/show?id=1988559%3ATopic%3A9386
the file - vsql.sql - is attached at the end. instead of using a cursor loop (curr_sql in my code) to get a statement, you'll just use your sql statement already in a variable. it's a simple procedure - breaks on certain keywords, or delimiters (like commas) before the linessize (132) is reached, and dbms_outputs the text.
changing the end of script to use a static sql statement:
begin
my_stmt := 'MERGE /*+ dynamic_sampling(ST 4) dynamic_sampling_est_cdn(ST) */ INTO STATS_TARG'||
'ET$ ST USING (SELECT STALENESS, OSIZE, OBJ#, TYPE#, CASE WHEN STALENESS > .5 THE'||
'N 128 ELSE 0 END + AFLAGS AFLAGS, STATUS, SID, SERIAL#, PART#, BO# FROM ( SELECT'||
' /*+ no_expand dynamic_sampling(4) dynamic_sampling_est_cdn */ DECODE(BITAND(T.F'||
'LAGS,16), 16, ROUND( LOG(0.01, NVL( LEAST( 100, GREATEST( 0.01, (DECODE(BITAND(M'||
'.FLAGS, 1), 1, GREATEST(T.ROWCNT, M.INSERTS), LEAST((M.INSERTS + M.DELETES ';
sql_frmt ( my_stmt, save_line, prefix );
if (save_line is not null) then
dbms_output.put_line( prefix || save_line );
save_line := null;
end if;
end;
MERGE /*+ dynamic_sampling ( ST 4 ) dynamic_sampling_est_cdn ( ST ) */ INTO STATS_TARGET$ ST USING (
SELECT STALENESS, OSIZE, OBJ#, TYPE#, CASE WHEN STALENESS > .5 THEN 128 ELSE 0 END + AFLAGS AFLAGS, STATUS, SID, SERIAL#, PART#,
BO#
FROM (
SELECT /*+ no_expand dynamic_sampling ( 4 ) dynamic_sampling_est_cdn */ DECODE ( BITAND ( T.FLAGS, 16 ), 16, ROUND ( LOG ( 0.01,
NVL ( LEAST ( 100, GREATEST ( 0.01, ( DECODE ( BITAND ( M.FLAGS, 1 ), 1, GREATEST ( T.ROWCNT, M.INSERTS ), LEAST ( ( M.INSERTS
+ M.DELETES -
What' wrong???
hi everybody,
I've a problem which need a genius to solve.
I've written some code into the when-button pressed trigger:
DECLARE
clob_help clob;
clob_rec clob;
video_h number(38);
clip_h number(38);
tt_h varchar2(4000);
help number(38):=0;
cursor c1 is select gt.video,gt.clip,gt.text_data from get_tt_view gt;
amt binary_integer;
pos integer:=1;
begin
for rec in c1 loop
tt_h:=rec.text_data;
amt:=length(tt_h);
dbms_lob.write(clob_rec,amt,pos,'asd');
dbms_lob.append(clob_help,clob_rec);
if help != rec.clip AND help!=0 then
insert into save_result_tt values(rec.video,rec.clip,clob_help);
commit;
end if;
help:=rec.clip;
end loop;
end;
when i start this code an error occurs(frm-40735; ora-06502).
this error says that a datatype is not correct.
I've tried to delete the dbms_lob.write line it works.
what's wrong?????
thanks in advance
tommyO
PS:
the database fields have the same length as the parameters in the script.Hey Thomas,
Just go thru the below rules and limitations and see whether you're doing any one of that, may find a solution by yourselves.
So, you'll be a genius by yourself if you solve it. Sorry it's not a direct answer for ya, but may help to ya, here you go
-- RULES AND LIMITATIONS
-- The following rules apply in the specification of functions and
-- procedures in this package.
-- LENGTH and OFFSET parameters for routines operating on BLOBs and
-- BFILEs are to be specified in terms of bytes.
-- LENGTH and OFFSET parameters for routines operating on CLOBs
-- are to be specified in terms of characters.
-- A function/procedure will raise an INVALID_ARGVAL exception if the
-- the following restrictions are not followed in specifying values
-- for parameters (unless otherwise specified):
-- 1. Only positive, absolute OFFSETs from the beginning of LOB data
-- are allowed. Negative offsets from the tail of the LOB are not
-- allowed.
-- 2. Only positive, non-zero values are allowed for the parameters
-- that represent size and positional quantities such as AMOUNT,
-- OFFSET, NEWLEN, NTH etc.
-- 3. The value of OFFSET, AMOUNT, NEWLEN, NTH must not exceed the
-- value lobmaxsize (which is (4GB-1) in Oracle 8.0) in any DBMS_LOB
-- procedure or function.
-- 4. For CLOBs consisting of fixed-width multi-byte characters, the
-- maximum value for these parameters must not exceed
-- (lobmaxsize/character_width_in_bytes) characters
-- For example, if the CLOB consists of 2-byte characters such as
-- JA16SJISFIXED, then the maximum amount value should not exceed
-- 4294967295/2 = 2147483647 characters
-- PL/SQL language specifications stipulate an upper limit of 32767
-- bytes (not characters) for RAW and VARCHAR2 parameters used in
-- DBMS_LOB routines.
-- If the value of AMOUNT+OFFSET exceeds 4GB (i.e. lobmaxsize+1) for
-- BLOBs and BFILEs, and (lobmaxsize/character_width_in_bytes)+1 for
-- CLOBs in calls to update routines - i.e. APPEND, COPY, TRIM, and
-- WRITE routines, access exceptions will be raised. Under these input
-- conditions, read routines such as READ, COMPARE, INSTR, SUBSTR, will
-- read till End of Lob/File is reached.
-- For example, for a READ operation on a BLOB or BFILE, if the user
-- specifies offset value of 3GB, and an amount value of 2 GB, READ
-- will read only ((4GB-1) - 3GB) bytes.
-- Functions with NULL or invalid input values for parameters will
-- return a NULL. Procedures with NULL values for destination LOB
-- parameters will raise exceptions.
-- Operations involving patterns as parameters, such as COMPARE, INSTR,
-- and SUBSTR do not support regular expressions or special matching
-- characters (such as % in the LIKE operator in SQL) in the PATTERN
-- parameter or substrings.
-- The End Of LOB condition is indicated by the READ procedure using
-- a NO_DATA_FOUND exception. This exception is raised only upon an
-- attempt by the user to read beyond the end of the LOB/FILE. The
-- READ buffer for the last read will contain 0 bytes.
-- For consistent LOB updates, the user is responsible for locking
-- the row containing the destination LOB before making a call to
-- any of the procedures (mutators) that modify LOB data.
-- For BFILEs, the routines COMPARE, INSTR, READ, SUBSTR, will raise
-- exceptions if the file is not already opened using FILEOPEN.
null -
Extracting string from another string
Hi,
I have a problem that I am having difficulty solving, if anyone has any bright ideas it would be a great help.
I have a description field in one of my tables and the description would read something like
my website can be found at www.mywebsite.com, and it is great
I want to be able to extract the web address from this sentance, so the result would be
www.mywebsite.com
I can do this specific for one sentance but I can't find a way to do it for many different sentances.
cheers in advancer u expecting this..?
select substr('my web site is www.abcd.com and u can...',instr('my web site is www.abcd.com and u can...','www.',1),instr(substr('my web site is www.abcd.com and u can...',instr('my web site is www.abcd.com and u can...','www.',1)),' ',1)) from dual; -
Hi all,
I am developing an application but there is a error in my code i culdnt find so far. Can anyone help?
I want to write to a .xml file in web server with servlet from remote. My code is
private static String message = "Error during Servlet processing";
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// response.setContentType("text/html;charset=UTF-8");
try {
int len = request.getContentLength();
byte[] input = new byte[len];
ServletInputStream sin = request.getInputStream();
int c, count = 0;
while ((c = sin.read(input, count, input.length - count)) != -1) {
count += c;
sin.close();
String inString = new String(input);
int index = inString.indexOf("/n");
if (index == -1) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.getWriter().print(message);
response.getWriter().close();
return;
String user = inString.substring(0, index);
String data = inString.substring(index + 2);
//decode application/x-www-form-urlencoded string
// String decodedUser = URLDecoder.decode(user, "UTF-8");
// String decodedData = URLDecoder.decode(data, "UTF-8");
// int i = decodedData.indexOf("/n");
// String user = decodedData.substring(0, i);
// String db = decodedData.substring(i + 2, decodedData.length());
String result = "no";
// response.setContentType("text/html");
String filename = "/WEB-INF/" + user + ".xml";
// String pathName = getServletContext ( ) .getRealPath ( "/" + filename ) ;
// String contentType = getServletContext ( ) .getMimeType ( pathName ) ;
// if ( contentType != null )
// response.setContentType ( contentType ) ;
// else
// response.setContentType ( "application/octet-stream" ) ;
try {
OutputStream fcheck = null;
byte[] buf = data.getBytes();
fcheck = new FileOutputStream(filename);
for (int i = 0; i < buf.length; i++) {
fcheck.write(buf);
result = "yes";
} catch (IOException ex) {
Logger.getLogger(UpdateDB.class.getName()).log(Level.SEVERE, null, ex);
result = "no";
// ServletContext context = getServletContext();
// set the response code and write the response data
response.setStatus(HttpServletResponse.SC_OK);
OutputStreamWriter writer = new OutputStreamWriter(response.getOutputStream());
writer.write(result);
writer.flush();
writer.close();
} catch (IOException e) {
try {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.getWriter().print(e.getMessage());
response.getWriter().close();
} catch (IOException ioe) {
ý am sending data from remote as a string and want to write it in xml. But it is not working. Where am i wrong?I fixed it. But now it doesnt write to file and there is no error. So i cant find where am a wrong.
I send a request, it is taking string but it is not writing to file eventhough it is entering the try block.
Why it isnt writing? Is not servlet let it to write to file. My working code is here
private static String message = "Error during Servlet processing";
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try {
int len = request.getContentLength();
byte[] input = new byte[len];
ServletInputStream sin = request.getInputStream();
int c, count = 0;
while ((c = sin.read(input, count, input.length - count)) != -1) {
count += c;
sin.close();
String inString = new String(input);
int index = inString.indexOf("/n");
if (index == -1) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.getWriter().print(message);
response.getWriter().close();
return;
String user = inString.substring(0, index);
String data = inString.substring(index + 2);
//decode application/x-www-form-urlencoded string
// String decodedUser = URLDecoder.decode(user, "UTF-8");
String decodedData = URLDecoder.decode(data, "UTF-8");
// int i = decodedData.indexOf("/n");
// String user = decodedData.substring(0, i);
// String db = decodedData.substring(i + 2, decodedData.length());
String result = "no";
String filename = user + ".xml";
try {
OutputStream fcheck = null;
byte[] buf = decodedData.getBytes();
fcheck = new FileOutputStream(filename);
for (int i = 0; i < buf.length; i++) {
fcheck.write(buf);
// char buffer[]=new char[data.length()];
// data.getChars(0, data.length(), buffer, 0);
// FileWriter f0=new FileWriter(filename);
// for(int i=0;i<buffer.length;i++){
// f0.write(buffer[i]);
result = "yes";
} catch (IOException ex) {
Logger.getLogger(UpdateDB.class.getName()).log(Level.SEVERE, null, ex);
result = "no";
// ServletContext context = getServletContext();
// set the response code and write the response data
response.setStatus(HttpServletResponse.SC_OK);
OutputStreamWriter writer = new OutputStreamWriter(response.getOutputStream());
writer.write(result);
writer.flush();
writer.close();
} catch (IOException e) {
try {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
response.getWriter().print(e.getMessage());
response.getWriter().close();
} catch (IOException ioe) { -
Writing from a text file into a table
Hi,
I have a problem with dearchiving the data from the txt file to the respective table.
The table name is dynamic & I get the required columns from all_tab_columns.
I use UTL_FILE.GET_LINE() to get the data one line at a time and INSTR() & SUBSTR() to break them into the respective columns.
My dynamic insert contains a set of bind variables equal to the no. of columns of the table.
The statement gets constructed correctly but I tried to use execute_immediate , i realised that i cannot construct the USING clause for it & hence I switced to DBMS_SQL.
The DBMS_SQL.BIND_VARIABLE() binds all of the bind variables to a table of varchar2. I've taken care to convert the date & the number variables while binding.
When i do DBMS_SQL.EXECUTE() I get the error,
ORA-01008 Not all variables bound .
I don't know the reason since the no. of bind variables & the no. of table variables are the same & the value in the table looks fine too!
Could this be a date issue ??? am using the default format DD-MON-YY both to write to the text file and to read from it.
Any help would be appreciated.
thx
kalpana
Part of the code :
Begin
destination_file := upper(p_table_name)||'_ARCH'||to_char
(p_process_date,'yyyymmdd')||'.dat';
dbms_output.put_line(destination_file);
file_id := UTL_FILE.FOPEN(file_path, destination_file,'r');
-- Get the number of columns in the table to be archived
select count(column_name)
into col_ctr
from all_tab_columns
where table_name = upper(p_table_name)
order by column_name;
sql_stmt1 := 'Insert into '||p_table_name||'(';
sql_stmt2 := ' values(';
For col_rec in column_cur loop
if col_ctr = column_cur%rowcount then -- last column in
the select statement
sql_stmt1 := sql_stmt1 || col_rec.column_name;
sql_stmt2 := sql_stmt2||':b'||column_cur%rowcount;
else
sql_stmt1 := sql_stmt1 || col_rec.column_name ||',';
sql_stmt2 := sql_stmt2||':b'||column_currowcount||',';
end if;
type_rec(column_cur%rowcount) := col_rec.data_type;
end loop;
sql_stmt1 := sql_stmt1||')';
sql_stmt2 := sql_stmt2||')';
sql_stmt := sql_stmt1||sql_stmt2;
loop
Begin
UTL_FILE.GET_LINE(file_id,v_column_value);
For i in 1..col_ctr loop
v_next_position := INSTR(v_column_value,';',1,i);
if i = 1 then
v_rec(i) := SUBSTR(v_column_value, v_prev_position, v_next_position - 1);
elsif i = col_ctr then -- last but one column
v_rec(i) := SUBSTR(v_column_value, v_prev_position);
else
v_rec(i) := SUBSTR(v_column_value, v_prev_position, (v_next_position - v_prev_position));
end if;
v_prev_position := v_next_position + 1;
end loop;
v_cursor := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(v_cursor, sql_stmt, dbms_sql.native);
For i in 1..col_ctr loop
if type_rec(i) = 'DATE' then
DBMS_SQL.BIND_VARIABLE(v_cursor,':b'||i, to_date(v_rec(i),'DD-MON-YY'));
elsif type_rec(i) = 'NUMBER' then
DBMS_SQL.BIND_VARIABLE(v_cursor,':b'||i, to_number(v_rec(i)));
end if;
end loop;
-- Insert the row into the history table
-- execute immediate sql_stmt USING value(v_rec);
v_dummy := DBMS_SQL.EXECUTE(v_cursor);
if SQL%NOTFOUND then
dbms_output.put_line('CPN_HISTORY_ARCHIVE_PKG.DEARCHIVE_DATA : No records to insert');
end if;
Exception -- for UTL_FILE.GET_LINE
when NO_DATA_FOUND then
DBMS_SQL.CLOSE_CURSOR(v_cursor);
UTL_FILE.FCLOSE(file_id);
exit;
End;
end loop; -- end of loop for UTL_FILE.GET_LINE
DBMS_SQL.CLOSE_CURSOR(v_cursor);
UTL_FILE.FCLOSE(file_id);your program is currect except u r not building bind variables for varchar2 columns
declare
type tab133 is table of varchar2(4000) index by binary_integer;
file_id utl_file.file_type;
sql_stmt1 varchar2(1000);
sql_stmt2 varchar2(1000);
v_column_value varchar2(1000);
sql_stmt varchar2(2000);
col_ctr number:=0;
p_table_name varchar2(30):='emp1';
cursor column_cur is select column_name,data_type from user_tab_columns
where table_name=upper(p_table_name);
mainstr VARCHAR2(40) := '';
splitstr VARCHAR2(30) := '';
l_count NUMBER(20) := 1;
itr_count NUMBER(20) := 0;
processed BOOLEAN := FALSE;
v_rec tab133;
type_rec tab133;
v_cursor integer;
column_currowcount number;
v_dummy number:=0;
Begin
--dbms_output.put_line(destination_file);
file_id := UTL_FILE.FOPEN('c:\suresh', 'emp.txt','r');
-- Get the number of columns in the table to be archived
select count(column_name)
into col_ctr
from user_tab_columns
where table_name = upper(p_table_name)
order by column_name;
sql_stmt1 := 'Insert into '||p_table_name||'(';
sql_stmt2 := ' values(';
For col_rec in column_cur loop
if col_ctr = column_cur%rowcount then
sql_stmt1 := sql_stmt1 || col_rec.column_name;
sql_stmt2 := sql_stmt2||':b'||column_cur%rowcount;
else
sql_stmt1 := sql_stmt1 || col_rec.column_name ||',';
sql_stmt2 := sql_stmt2||':b'||column_cur%rowcount||',';
end if;
type_rec(column_cur%rowcount) := col_rec.data_type;
end loop;
sql_stmt1 := sql_stmt1||')';
sql_stmt2 := sql_stmt2||')';
sql_stmt := sql_stmt1||sql_stmt2;
dbms_output.put_line(sql_stmt);
loop
Begin
UTL_FILE.GET_LINE(file_id,v_column_value);
itr_count := 0;
l_count :=1;
processed := FALSE;
mainstr:=v_column_value;
LOOP
itr_count := itr_count+1;
IF instr(mainstr,',',1,itr_count)>0 THEN
splitstr := SUBSTR(mainstr,l_count,(INSTR(mainstr,',',1,itr_count)-l_count));
l_count := INSTR(mainstr,',',1,itr_count)+1;
ELSE
splitstr := SUBSTR(mainstr,l_count,LENGTH(mainstr)+1-l_count);
processed := TRUE;
END IF;
v_rec(itr_count):=splitstr;
IF processed THEN
EXIT ;
END IF;
END LOOP;
v_cursor := DBMS_SQL.OPEN_CURSOR;
--dbms_output.put_line(col_ctr);
DBMS_SQL.PARSE(v_cursor, sql_stmt, dbms_sql.native);
For i in 1..col_ctr loop
if type_rec(i) = 'DATE' then
DBMS_SQL.BIND_VARIABLE(v_cursor,':b'||to_char(i), to_date(v_rec(i),'DD/mm/yyyy'));
elsif type_rec(i) = 'NUMBER' then
DBMS_SQL.BIND_VARIABLE(v_cursor,':b'||to_char(i), to_number(v_rec(i)));
elsif type_rec(i) = 'VARCHAR2' then
DBMS_SQL.BIND_VARIABLE(v_cursor,':b'||to_char(i), v_rec(i));
end if;
end loop;
v_dummy := DBMS_SQL.EXECUTE(v_cursor);
if SQL%NOTFOUND then
dbms_output.put_line('CPN_HISTORY_ARCHIVE_PKG.DEARCHIVE_DATA : No records to insert');
end if;
DBMS_SQL.CLOSE_CURSOR(v_cursor);
Exception
when NO_DATA_FOUND then
UTL_FILE.FCLOSE(file_id);
exit;
End;
end loop;
UTL_FILE.FCLOSE(file_id);
EXCEPTION
when others then
dbms_output.put_line(sqlerrm);
UTL_FILE.FCLOSE(file_id);
END;
TEST:
SQL> DESC EMP1
Name Null? Type
ENAME VARCHAR2(15)
SUBJ VARCHAR2(15)
SDATE DATE
DATA FILE:
AABC,oracle,08/08/2001
xyz,social,12/12/2001
SQL> select * from emp1;
ENAME SUBJ SDATE
AABC oracle 08/08/2001 00:00:00
xyz social 12/12/2001 00:00:00 -
Need Help to see why the performance is not good
Hi,
We have an application that all process are developed in PL/SQL on Oracle 9i Database :
Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64bit Production
PL/SQL Release 9.2.0.6.0 - Production
Why I have created this package. the application is a production management on chemical industries. I need to sometimes trace the Manufacturing order execution to eventually answer some incoherent data. If I analyze directly the data in the Table is not always responding because the origin of problem can be provide of some execution that perform some calculation.
In the procedure or function a use my package PAC_LOG_ERROR.PUT_LINE(xxxxxx) to save the information. This command save the information in the memory before. At the end of the procedure or function a perform the insert with the COMMIT calling PAC_LOG_ERROR.LOGS or PAC_LOG_ERROR.ERRORS on the catch exception.
This package is always call. On each routines performed I execute it. In the trace log of the database we have see a problem we the procedure GET_PROC_NAME in the package. We have identify that is called more that 800x and increase the performance. Who increase is this select command :
SELECT * INTO SOURCE_TEXT
FROM (SELECT TEXT FROM all_source
WHERE OWNER = SOURCE_OWNER AND
NAME=SOURCE_NAME AND
TYPE IN ('PROCEDURE','FUNCTION','PACKAGE BODY') AND
LINE <= SOURCE_LINE AND SUBSTR(TRIM(TEXT),1,9) IN ('PROCEDURE','FUNCTION ')
ORDER BY LINE DESC)
WHERE ROWNUM = 1;I use it to get the procedure or function name where my log proc is called. I now that I can pass in parameters, but I have think to use an automatic method, that can help to not have some problem with others developer team to make a copy/past and not update the parameters. Because the Log info is read by the Help Desk and if we have an error on the information, it not a good help.
COULD YOU PLEASE HELP ME TO OPTIMIZE OR SAID THE BETTER METHOD TO DO IT ?
Here my package :
create or replace
PACKAGE PAC_LOG_ERROR AS
-- Name : pac_log_error.sql
-- Author : Calà Salvatore - 02 July 2010
-- Description : Basic Error and Log management.
-- Usage notes : To active the Log management execute this statement
-- UPDATE PARAM_TECHNIC SET PRM_VALUE = 'Y' WHERE PRM_TYPE = 'TRC_LOG';
-- COMMIT;
-- To set the period in day before to delete tracability
-- UPDATE PARAM_TECHNIC SET PRM_VALUE = 60 WHERE PRM_TYPE = 'DEL_TRC_LOG';
-- COMMIT;
-- To set the number in day where the ERROR is save before deleted
-- UPDATE PARAM_TECHNIC SET PRM_VALUE = 60 WHERE PRM_TYPE = 'DEL_TRC_LOG';
-- COMMIT;
-- Requirements : Packages PAC_PUBLIC and OWA_UTIL
-- Revision History
-- --------+---------------+-------------+--------------------------------------
-- Version | Author | Date | Comment
-- --------+---------------+-------------+--------------------------------------
-- 1.0.0 | S. Calà | 02-Jul-2010 | Initial Version
-- --------+---------------+-------------+--------------------------------------
-- | | |
-- --------+---------------+-------------+--------------------------------------
PROCEDURE INITIALIZE;
PROCEDURE CLEAN;
PROCEDURE RESETS(IN_SOURCE IN VARCHAR2 DEFAULT NULL);
PROCEDURE PUT_LINE(TXT IN VARCHAR2);
PROCEDURE ERRORS(REF_TYPE IN VARCHAR2 DEFAULT 'SITE', REF_VALUE IN VARCHAR2 DEFAULT '99', ERR_CODE IN NUMBER DEFAULT SQLCODE, ERR_MSG IN VARCHAR2 DEFAULT SQLERRM);
PROCEDURE LOGS(REF_TYPE IN VARCHAR2 DEFAULT 'SITE', REF_VALUE IN VARCHAR2 DEFAULT '99');
END PAC_LOG_ERROR;
create or replace
PACKAGE BODY PAC_LOG_ERROR
AS
/* Private Constant */
CR CONSTANT CHAR(1) := CHR(13); -- Retour chariot
LF CONSTANT CHAR(1) := CHR(10); -- Saut de ligne
CR_LF CONSTANT CHAR(2) := LF || CR; --Saut de ligne et retour chariot
TAB CONSTANT PLS_INTEGER := 50;
sDelay CONSTANT PLS_INTEGER := 30;
/* Private Record */
TYPE REC_LOG IS RECORD(
ERR_DATE TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
ERR_TXT VARCHAR2(4000)
/* Private Type Table */
TYPE TAB_VALUE IS TABLE OF REC_LOG INDEX BY PLS_INTEGER;
TYPE TAB_POINTER IS TABLE OF TAB_VALUE INDEX BY VARCHAR2(80);
/* Private Variables Structures */
LOG_TRC PARAM_TECHNIC.PRM_VALUE%TYPE;
LIST_PARAM TAB_POINTER;
/* Private Programs */
FUNCTION GET_PROC_NAME( SOURCE_OWNER IN all_source.OWNER%TYPE
,SOURCE_NAME IN all_source.NAME%TYPE
,SOURCE_LINE IN all_source.LINE%TYPE) RETURN VARCHAR2
AS
SOURCE_TEXT all_source.TEXT%TYPE;
TYPE RECORD_TEXT IS TABLE OF all_source.TEXT%TYPE;
RETURN_TEXT RECORD_TEXT;
BEGIN
SELECT * INTO SOURCE_TEXT
FROM (SELECT TEXT FROM all_source
WHERE OWNER = SOURCE_OWNER AND
NAME=SOURCE_NAME AND
TYPE IN ('PROCEDURE','FUNCTION','PACKAGE BODY') AND
LINE <= SOURCE_LINE AND SUBSTR(TRIM(TEXT),1,9) IN ('PROCEDURE','FUNCTION ')
ORDER BY LINE DESC)
WHERE ROWNUM = 1;
IF SOURCE_TEXT IS NOT NULL OR SOURCE_TEXT != '' THEN
SOURCE_TEXT := TRIM(SUBSTR(SOURCE_TEXT,1,INSTR(SOURCE_TEXT,'(')-1));
SOURCE_TEXT := LTRIM(LTRIM(TRIM(SOURCE_TEXT),'PROCEDURE'),'FUNCTION');
SOURCE_TEXT := SOURCE_NAME||'.'|| TRIM(SOURCE_TEXT);
ELSE
SOURCE_TEXT := 'ANONYMOUS BLOCK';
END IF;
RETURN SOURCE_TEXT;
END GET_PROC_NAME;
PROCEDURE SELECT_MASTER(REF_TYPE IN VARCHAR2, PARAM_VALUE IN VARCHAR2, SITE OUT VARCHAR2, REF_MASTER OUT VARCHAR2)
AS
BEGIN
REF_MASTER := '';
SITE := '99';
CASE UPPER(REF_TYPE)
WHEN 'PO' THEN -- Process Order
SELECT SITE_CODE INTO SITE FROM PO_PROCESS_ORDER WHERE PO_NUMBER = PARAM_VALUE;
WHEN 'SO' THEN -- Shop Order
SELECT P.SITE_CODE,P.PO_NUMBER INTO SITE,REF_MASTER FROM SO_SHOP_ORDER S
INNER JOIN PO_PROCESS_ORDER P ON P.PO_NUMBER = S.PO_NUMBER
WHERE S.NUMOF = PARAM_VALUE;
WHEN 'SM' THEN -- Submixing
SELECT SITE_CODE,NUMOF INTO SITE,REF_MASTER FROM SO_SUBMIXING WHERE IDSM = PARAM_VALUE;
WHEN 'IDSM' THEN -- Submixing
SELECT SITE_CODE,NUMOF INTO SITE,REF_MASTER FROM SO_SUBMIXING WHERE IDSM = PARAM_VALUE;
WHEN 'PR' THEN -- Pourring
SELECT B.SITE_CODE,P.NUMOF INTO SITE,REF_MASTER FROM SO_POURING P
INNER JOIN SO_SUBMIXING B ON B.IDSM=P.IDSM
WHERE P.IDSM = PARAM_VALUE;
WHEN 'NUMSMP' THEN -- Pourring
SELECT SITE_CODE,NUMOF INTO SITE,REF_MASTER FROM SAMPLE WHERE NUMSMP = TO_NUMBER(PARAM_VALUE);
-- WHEN 'MSG' THEN -- Messages
-- SELECT SITE_CODE,PO_NUMBER INTO SITE,REF_MASTER FROM CMS_INTERFACE.MAP_ITF_PO WHERE MSG_ID = PARAM_VALUE;
ELSE
SITE := sys_context('usr_context', 'site_attribute');
END CASE;
EXCEPTION
WHEN OTHERS THEN
REF_MASTER := '';
SITE := sys_context('usr_context', 'site_attribute');
END SELECT_MASTER;
PROCEDURE ADD_LIST_PROC
AS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
MERGE INTO LOG_PARAM A
USING (SELECT OWNER, TYPE
,NAME PROC
, CASE NAME WHEN SUBNAME THEN NULL
ELSE SUBNAME
END SUBPROC
FROM (
SELECT owner,TYPE,UPPER(NAME) NAME,UPPER(trim(substr(substr(trim(text),1,instr(trim(text),'(')-1),instr(substr(trim(text),1,instr(trim(text),'(')-1),' ')))) SUBNAME
FROM ALL_SOURCE where owner in ('CMS_ADM','CMS_INTERFACE')
and type in ('FUNCTION','PROCEDURE','PACKAGE BODY')
and (instr(substr(trim(text),1,instr(trim(upper(text)),'(')-1),'FUNCTION') = 1 or instr(substr(trim(text),1,instr(trim(upper(text)),'(')-1),'PROCEDURE')=1)
)-- ORDER BY OWNER,PROC,SUBPROC NULLS FIRST
) B
ON (A.OWNER = B.OWNER AND A.TYPE = B.TYPE AND A.PROC=B.PROC AND NVL(A.SUBPROC,' ') = NVL(B.SUBPROC,' '))
WHEN NOT MATCHED THEN
INSERT (OWNER,TYPE,PROC,SUBPROC) VALUES (B.OWNER,B.TYPE,B.PROC,B.SUBPROC)
WHEN MATCHED THEN
UPDATE SET ACTIVE = ACTIVE;
DELETE LOG_PARAM A
WHERE NOT EXISTS (SELECT OWNER, TYPE
,NAME PROC
, CASE NAME WHEN SUBNAME THEN NULL
ELSE SUBNAME
END SUBPROC
FROM (
SELECT owner,TYPE,NAME,upper(trim(substr(substr(trim(text),1,instr(trim(text),'(')-1),instr(substr(trim(text),1,instr(trim(text),'(')-1),' ')))) SUBNAME
FROM ALL_SOURCE where owner in ('CMS_ADM','CMS_INTERFACE')
and type in ('FUNCTION','PROCEDURE','PACKAGE BODY')
and (instr(substr(trim(text),1,instr(trim(text),'(')-1),'FUNCTION') = 1 or instr(substr(trim(text),1,instr(trim(text),'(')-1),'PROCEDURE')=1)
) WHERE A.OWNER = OWNER AND A.TYPE = TYPE AND A.PROC=PROC AND NVL(A.SUBPROC,' ') = NVL(SUBPROC,' '));
COMMIT;
EXCEPTION
WHEN OTHERS THEN
NULL;
END ADD_LIST_PROC;
PROCEDURE INITIALIZE
AS
BEGIN
LIST_PARAM.DELETE;
CLEAN;
-- ADD_LIST_PROC;
EXCEPTION
WHEN OTHERS THEN
NULL;
END INITIALIZE;
PROCEDURE CLEAN
AS
PRAGMA AUTONOMOUS_TRANSACTION;
dtTrcLog DATE;
dtTrcErr DATE;
BEGIN
BEGIN
SELECT dbdate-NUMTODSINTERVAL(to_number(PRM_VALUE),'DAY') INTO dtTrcLog
FROM PARAM_TECHNIC WHERE PRM_TYPE = 'DEL_TRC_LOG';
EXCEPTION
WHEN OTHERS THEN
dtTrcLog := dbdate -NUMTODSINTERVAL(sDelay,'DAY');
END;
BEGIN
SELECT dbdate-NUMTODSINTERVAL(to_number(PRM_VALUE),'DAY') INTO dtTrcErr
FROM PARAM_TECHNIC WHERE PRM_TYPE = 'DEL_TRC_ERR';
EXCEPTION
WHEN OTHERS THEN
dtTrcErr := dbdate -NUMTODSINTERVAL(sDelay,'DAY');
END;
DELETE FROM ERROR_LOG WHERE ERR_TYPE ='LOG' AND ERR_DATE < dtTrcLog;
DELETE FROM ERROR_LOG WHERE ERR_TYPE ='ERROR' AND ERR_DATE < dtTrcErr;
COMMIT;
EXCEPTION
WHEN OTHERS THEN
NULL; -- Do nothing if error occurs and catch exception
END CLEAN;
PROCEDURE RESETS(IN_SOURCE IN VARCHAR2 DEFAULT NULL)
AS
SOURCE_OWNER all_source.OWNER%TYPE;
SOURCE_NAME all_source.NAME%TYPE;
SOURCE_LINE all_source.LINE%TYPE;
SOURCE_TEXT all_source.TEXT%TYPE;
SOURCE_PROC VARCHAR2(32727);
BEGIN
OWA_UTIL.WHO_CALLED_ME(owner => SOURCE_OWNER,
name => SOURCE_NAME,
lineno => SOURCE_LINE,
caller_t => SOURCE_TEXT);
IF SOURCE_PROC IS NULL THEN
SOURCE_PROC := SUBSTR(GET_PROC_NAME(SOURCE_OWNER,SOURCE_NAME,SOURCE_LINE),1,125);
ELSE
SOURCE_PROC := IN_SOURCE;
END IF;
LIST_PARAM.DELETE(SOURCE_PROC);
EXCEPTION
WHEN OTHERS THEN
NULL;
END RESETS;
PROCEDURE PUT_LINE(TXT IN VARCHAR2)
AS
PRAGMA AUTONOMOUS_TRANSACTION;
SOURCE_OWNER all_source.OWNER%TYPE;
SOURCE_NAME all_source.NAME%TYPE;
SOURCE_LINE all_source.LINE%TYPE;
SOURCE_TEXT all_source.TEXT%TYPE;
SOURCE_PROC VARCHAR2(128);
BEGIN
IF TXT IS NULL OR TXT = '' THEN
RETURN;
END IF;
OWA_UTIL.WHO_CALLED_ME(owner => SOURCE_OWNER,
name => SOURCE_NAME,
lineno => SOURCE_LINE,
caller_t => SOURCE_TEXT);
SOURCE_PROC := GET_PROC_NAME(SOURCE_OWNER,SOURCE_NAME,SOURCE_LINE);
IF LIST_PARAM.EXISTS(SOURCE_PROC) THEN
LIST_PARAM(SOURCE_PROC)(LIST_PARAM(SOURCE_PROC).COUNT+1).ERR_TXT := TXT;
ELSE
LIST_PARAM(SOURCE_PROC)(1).ERR_TXT := TXT;
END IF;
EXCEPTION
WHEN OTHERS THEN
NULL;
END PUT_LINE;
PROCEDURE LOGS(REF_TYPE IN VARCHAR2 DEFAULT 'SITE', REF_VALUE IN VARCHAR2 DEFAULT '99')
AS
PRAGMA AUTONOMOUS_TRANSACTION;
MASTER_VALUE ERROR_LOG.ERR_MASTER%TYPE;
SITE PARAMTAB.SITE_CODE%TYPE;
SOURCE_OWNER all_source.OWNER%TYPE;
SOURCE_NAME all_source.NAME%TYPE;
SOURCE_LINE all_source.LINE%TYPE;
SOURCE_TEXT all_source.TEXT%TYPE;
SOURCE_PROC VARCHAR2(128);
ERR_KEY NUMBER;
BEGIN
-- NULL;
OWA_UTIL.WHO_CALLED_ME(owner => SOURCE_OWNER,
name => SOURCE_NAME,
lineno => SOURCE_LINE,
caller_t => SOURCE_TEXT);
SOURCE_PROC := SUBSTR(GET_PROC_NAME(SOURCE_OWNER,SOURCE_NAME,SOURCE_LINE),1,128);
LIST_PARAM.DELETE(SOURCE_PROC);
-- SELECT NVL(MAX(ACTIVE),'N') INTO LOG_TRC FROM LOG_PARAM WHERE TRIM(UPPER((PROC||'.'||SUBPROC))) = TRIM(UPPER(SOURCE_PROC))
-- AND OWNER =SOURCE_OWNER AND TYPE = SOURCE_TEXT ;
-- IF LOG_TRC = 'N' THEN
-- LIST_PARAM.DELETE(SOURCE_PROC);
-- RETURN;
-- END IF;
-- SELECT_MASTER(REF_TYPE => UPPER(REF_TYPE), PARAM_VALUE => REF_VALUE, SITE => SITE, REF_MASTER => MASTER_VALUE);
-- ERR_KEY := TO_CHAR(LOCALTIMESTAMP,'YYYYMMDDHH24MISSFF6');
-- FOR AIX IN 1..LIST_PARAM(SOURCE_PROC).COUNT LOOP
-- INSERT INTO ERROR_LOG (ERR_KEY, ERR_SITE,ERR_SLAVE ,ERR_MASTER ,ERR_TYPE ,ERR_PROC,ERR_DATE,ERR_TXT)
-- VALUES (ERR_KEY,SITE,REF_VALUE,MASTER_VALUE,'LOG',SOURCE_PROC,LIST_PARAM(SOURCE_PROC)(AIX).ERR_DATE ,LIST_PARAM(SOURCE_PROC)(AIX).ERR_TXT);
-- END LOOP;
-- UPDATE SESSION_CONTEXT SET SCX_ERR_KEY = ERR_KEY WHERE SCX_ID = SYS_CONTEXT('USERENV','SESSIONID');
-- LIST_PARAM.DELETE(SOURCE_PROC);
-- COMMIT;
EXCEPTION
WHEN OTHERS THEN
LIST_PARAM.DELETE(SOURCE_PROC);
END LOGS;
PROCEDURE ERRORS(REF_TYPE IN VARCHAR2 DEFAULT 'SITE', REF_VALUE IN VARCHAR2 DEFAULT '99', ERR_CODE IN NUMBER DEFAULT SQLCODE, ERR_MSG IN VARCHAR2 DEFAULT SQLERRM)
AS
PRAGMA AUTONOMOUS_TRANSACTION;
MASTER_VALUE ERROR_LOG.ERR_MASTER%TYPE;
SITE PARAMTAB.SITE_CODE%TYPE;
SOURCE_OWNER all_source.OWNER%TYPE;
SOURCE_NAME all_source.NAME%TYPE;
SOURCE_LINE all_source.LINE%TYPE;
SOURCE_TEXT all_source.TEXT%TYPE;
SOURCE_PROC VARCHAR2(4000);
ERR_KEY NUMBER := TO_CHAR(LOCALTIMESTAMP,'YYYYMMDDHH24MISSFF6');
BEGIN
OWA_UTIL.WHO_CALLED_ME(owner => SOURCE_OWNER,
name => SOURCE_NAME,
lineno => SOURCE_LINE,
caller_t => SOURCE_TEXT);
SOURCE_PROC := SUBSTR(GET_PROC_NAME(SOURCE_OWNER,SOURCE_NAME,SOURCE_LINE),1,125);
SELECT_MASTER(REF_TYPE => UPPER(REF_TYPE), PARAM_VALUE => REF_VALUE, SITE => SITE, REF_MASTER => MASTER_VALUE);
IF LIST_PARAM.EXISTS(SOURCE_PROC) THEN
FOR AIX IN 1..LIST_PARAM(SOURCE_PROC).COUNT LOOP
INSERT INTO ERROR_LOG (ERR_KEY,ERR_SITE,ERR_SLAVE,ERR_MASTER,ERR_PROC,ERR_DATE,ERR_TXT,ERR_CODE,ERR_MSG)
VALUES (ERR_KEY,SITE,REF_VALUE,MASTER_VALUE,SOURCE_PROC,LIST_PARAM(SOURCE_PROC)(AIX).ERR_DATE, LIST_PARAM(SOURCE_PROC)(AIX).ERR_TXT,ERR_CODE,ERR_MSG);
END LOOP;
LIST_PARAM.DELETE(SOURCE_PROC);
ELSE
INSERT INTO ERROR_LOG (ERR_KEY,ERR_SITE,ERR_SLAVE,ERR_MASTER,ERR_PROC,ERR_DATE,ERR_TXT,ERR_CODE,ERR_MSG)
VALUES (ERR_KEY,SITE,REF_VALUE,MASTER_VALUE,SOURCE_PROC,CURRENT_TIMESTAMP,'Error info',ERR_CODE,ERR_MSG);
END IF;
UPDATE SESSION_CONTEXT SET SCX_ERR_KEY = ERR_KEY WHERE SCX_ID = sys_context('usr_context', 'session_id');
COMMIT;
EXCEPTION
WHEN OTHERS THEN
LIST_PARAM.DELETE(SOURCE_PROC);
END ERRORS;
END PAC_LOG_ERROR;This package is always call. On each routines performed I execute it. In the trace log of the database we have see a problem we the procedure GET_PROC_NAME in the package. We have identify that is called more that 800x and increase the performance. Who increase is this select command :
SELECT * INTO SOURCE_TEXT
FROM (SELECT TEXT FROM all_source
WHERE OWNER = SOURCE_OWNER AND
NAME=SOURCE_NAME AND
TYPE IN ('PROCEDURE','FUNCTION','PACKAGE BODY') AND
LINE <= SOURCE_LINE AND SUBSTR(TRIM(TEXT),1,9) IN ('PROCEDURE','FUNCTION ')
ORDER BY LINE DESC)
WHERE ROWNUM = 1;Complex SQL like inline views and views of views can overwhelm the cost-based optimizer resulting in bad execution plans. Start with getting an execution plan of your problem query to see if it is inefficient - look for full table scans in particular. You might bet better performance by eliminating the IN and merging the results of 3 queries with a UNION.
Maybe you are looking for
-
Can't find European Apps in App Store
I am from the United States and moved to France six months ago. I have tried a number of times to download apps that I see here in France but I can't find them at all in the app store. For example - I have two store loyalty cards. One for Carrefour a
-
No Data dropped while trying to deleting Master Data
Hi All, I recently enhanced a Master Data to include a field and needed to drop the content of the Master Data, then reload. I try via the InfoObject (right click -> Delete Data) and it would not drop data - Message: Not all master data can be delet
-
Raw file settings missing from smart objects in tiff files after upgrade to CS6
Yesterday I was using Photoshop CS5 and RAW 6.4 (?) in a Windows environment. When editing photographs, I generally open the photo in Camera Raw, make development changes (ie exposure, contrast, etc) and then open the developed image as Smart Object
-
Please help. :(
-
Hi Guys, I need to create a report which will extract all the inactive customers.My criteria for selection is "A customer will inactive if there has been no sales activity for more than 18 months and no open items exist."Now as I am from ABAP backgro