SQL Query (oracle 10.2.0.3.0)
Hi All,
I have columns called Ph_Num in Table EMP.
the values of these columns as follows.
PH_NUM
8614558500-8614558505||8614558550||8614558555But I want to modify it as
PH_NUM
014/55.85.00||014/55.85.05||014/55.85.50||014/55.85.55OR
PH_NUM
014/55.85.00-014/55.85.05||014/55.85.50||014/55.85.55can any one please help me to write a query for this.
Thank you,
SSH
Hi All,
I have written the folowing query.
SELECT DECODE (SUBSTR (PHNUM, 1, 1),
'2', '0'
|| SUBSTR (PHNUM, 1, 1)
|| '/'
|| SUBSTR (PHNUM, 2, 3)
|| '.'
|| SUBSTR (PHNUM, 5, 2)
|| '.'
|| SUBSTR (PHNUM, 7, 2),
'3', '0'
|| SUBSTR (PHNUM, 1, 1)
|| '/'
|| SUBSTR (PHNUM, 2, 3)
|| '.'
|| SUBSTR (PHNUM, 5, 2)
|| '.'
|| SUBSTR (PHNUM, 7, 2),
'4', DECODE (SUBSTR (PHNUM, 2, 1),
'7', '0'
|| SUBSTR (PHNUM, 1, 3)
|| '/'
|| SUBSTR (PHNUM, 4, 2)
|| '.'
|| SUBSTR (PHNUM, 6, 2)
|| '.'
|| SUBSTR (PHNUM, 8, 2),
'8', '0'
|| SUBSTR (PHNUM, 1, 3)
|| '/'
|| SUBSTR (PHNUM, 4, 2)
|| '.'
|| SUBSTR (PHNUM, 6, 2)
|| '.'
|| SUBSTR (PHNUM, 8, 2),
'9', '0'
|| SUBSTR (PHNUM, 1, 3)
|| '/'
|| SUBSTR (PHNUM, 4, 2)
|| '.'
|| SUBSTR (PHNUM, 6, 2)
|| '.'
|| SUBSTR (PHNUM, 8, 2),
'0'
|| SUBSTR (PHNUM, 1, 1)
|| '/'
|| SUBSTR (PHNUM, 2, 3)
|| '.'
|| SUBSTR (PHNUM, 5, 2)
|| '.'
|| SUBSTR (PHNUM, 7, 2)
'8', DECODE (SUBSTR (PHNUM, 3, 1),
'0','0'
|| SUBSTR (PHNUM, 1, 3)
|| '/'
|| SUBSTR (PHNUM, 4, 2)
|| '.'
|| SUBSTR (PHNUM, 6, 3),
'0'
|| SUBSTR (PHNUM, 1, 2)
|| '/'
|| SUBSTR (PHNUM, 3, 2)
|| '.'
|| SUBSTR (PHNUM, 5, 2)
|| '.'
|| SUBSTR (PHNUM, 7, 2)
'9', DECODE (SUBSTR(PHNUM, 2,1),
'0','0'
|| SUBSTR (PHNUM, 1, 3)
|| '/'
|| SUBSTR (PHNUM, 4, 2)
|| '.'
|| SUBSTR (PHNUM, 6, 3),
'0'
|| SUBSTR (PHNUM, 1, 1)
|| '/'
|| SUBSTR (PHNUM, 2, 3)
|| '.'
|| SUBSTR (PHNUM, 5, 2)
|| '.'
|| SUBSTR (PHNUM, 7, 2)
'0', SUBSTR (PHNUM, 1, 3)
|| '/'
|| SUBSTR (PHNUM, 4, 2)
|| '.'
|| SUBSTR (PHNUM, 6, 2)
|| '.'
|| SUBSTR (PHNUM, 8, 2),
'0'
|| SUBSTR (PHNUM, 1, 2)
|| '/'
|| SUBSTR (PHNUM, 3, 2)
|| '.'
|| SUBSTR (PHNUM, 5, 2)
|| '.'
|| SUBSTR (PHNUM, 7, 2)
FROM dual;Teh O/P is as follows.
9914558500-9914558505||9914558550||9914558555
But required O/P to be
014/55.85.00||014/55.85.05||014/55.85.50||014/55.85.55
OR
014/55.85.00-014/55.85.05||014/55.85.50||014/55.85.55
so please let me know what are the required modifications I need to do in the above mentioned query.
Thank you
Similar Messages
-
Retrieve a range of records from SQL query Oracle
I want to retrieve range of rows in Oracle database. This is the table structure:
CREATE TABLE ACTIVESESSIONSLOG(
ASESSIONID VARCHAR2(30 ) NOT NULL,
USERID VARCHAR2(30 ),
ACTIVITYSTART TIMESTAMP(6),
ACTIVITYEND TIMESTAMP(6),
ACTIVITY CLOB
/This is the SQL command that I use to get rows from the table:
SELECT * FROM ACTIVESESSIONSLOG WHERE ROWNUM >= 5 AND ROWNUM <= 10 ORDER BY USERID ASC;When I rum it no data is displayed. What is the proper way to get only 5 rows from the database?
Best wishes
PeterIs this SQL query valid?I tend to say no: ORDER BY is applied last, so your rownum is not in correct anymore:
SQL> select rownum, ename, empno from emp order by empno
ROWNUM ENAME EMPNO
3 SMITH 7369
4 ALLEN 7499
5 WARD 7521
6 JONES 7566
7 MARTIN 7654
8 BLAKE 7698
9 CLARK 7782
2 SCOTT 7788
10 KING 7839
11 TURNER 7844
12 ADAMS 7876
1 JAMES 7900
13 FORD 7902
14 MILLER 7934
14 rows selected.You either use analytic ROW_NUMBER() as in my previous post - or you need to nest once again:
SQL> select rn, empno, ename
from (select rownum rn, ename, empno
from ( select ename, empno
from emp
order by empno))
where rn between 4 and 5
RN EMPNO ENAME
4 7566 JONES
5 7654 MARTIN
2 rows selected. -
SQL Query (Oracle 10g)
Hi All,
Please find the following requirement.
Requirement -
There are 2 standalone database named database A and
database B used by 2 separate application. Database A
has schema S1 and Database B has schema S2.
Schema S1 has around 40 master tables which get updated
very frequently. This 40 tables are also present in S2
also.
We want the both the 40 tables to be in sync every
hourly or half any hour.
eg. If records are added/updated deleted in S1.emp then
same should be done in S2.emp and visa versa also.
We dont want to use dblink,materialised views or
scripts. Is there any feature in Oracle 10G like
replication or Streams where in this can be done.
Incase if are not able to replicate both ways then at
least one way can we replicate ? like any records are
added/updated deleted in S1.emp then same should be done
in S2.emp and similarly in the other 39 tables.
Thank you
Message was edited by:
User71408Can anyone provide a SQl query to create a
schema/user named 'test' with username as 'system'
and password as 'manager'system user is created during database creation, it's internal Oracle admin user that shouldn't be used as schema holder.
In Oracle database, Oracle user is schema holder there's no seperate schema name to be defined other than username. -
Hi,
We are using Oracle 8i (Oracle8i Enterprise Edition Release *8.1.7.4.0 - 64bit Production*).
My requirement is -
I need output like
USER_NAME Company
Suri 01,86,65
Srinu 01,86,65
Here is the sample data.
WITH t AS ( SELECT 'SURI' user_name ,'01' Company FROM dual UNION ALL
SELECT 'SURI' user_name, '86' Company FROM dual UNION ALL
SELECT 'SURI' user_name ,'65' Company FROM dual UNION ALL
SELECT 'SRINU' user_name, '01' Company FROM dual UNION ALL
SELECT 'SRINU' user_name ,'86' Company FROM dual UNION ALL
SELECT 'SRINU' user_name ,'65' Company FROM dual )
SELECT * FROM t ;
USER_NAME COMPANY
SURI 01
SURI 86
SURI 65
SRINU 01
SRINU 86
SRINU 65Many thanks in advance for the help.
Thanks,
SuriUse my HIERARCHY package:
CREATE OR REPLACE
PACKAGE Hierarchy
IS
TYPE BranchNameTableType IS TABLE OF VARCHAR2(4000)
INDEX BY BINARY_INTEGER;
BranchNameTable BranchNameTableType;
TYPE BranchNumberTableType IS TABLE OF NUMBER
INDEX BY BINARY_INTEGER;
BranchNumberTable BranchNumberTableType;
BranchSumTable BranchNumberTableType;
PreviousLevel NUMBER;
FUNCTION BranchName(pLevel IN NUMBER,
pValue IN VARCHAR2,
pDelimiter IN VARCHAR2 DEFAULT CHR(0)
RETURN VARCHAR2;
PRAGMA RESTRICT_REFERENCES(BranchName,WNDS);
FUNCTION BranchNumber(pLevel IN NUMBER,
pRnum IN NUMBER,
pDelimiter IN VARCHAR2 DEFAULT '.'
RETURN VARCHAR2;
PRAGMA RESTRICT_REFERENCES(BranchNumber,WNDS);
FUNCTION BranchSum(pLevel IN NUMBER,
pValue IN NUMBER
RETURN NUMBER;
PRAGMA RESTRICT_REFERENCES(BranchSum,WNDS);
FUNCTION BranchProd(pLevel IN NUMBER,
pValue IN NUMBER
RETURN NUMBER;
PRAGMA RESTRICT_REFERENCES(BranchProd,WNDS);
FUNCTION IsNewBranch(pLevel IN NUMBER,
pRnum IN NUMBER
RETURN NUMBER;
PRAGMA RESTRICT_REFERENCES(IsNewBranch,WNDS);
END Hierarchy;
CREATE OR REPLACE
PACKAGE BODY Hierarchy
IS
ReturnStrValue VARCHAR2(4000);
ReturnNumValue NUMBER;
FUNCTION BranchName(pLevel IN NUMBER,
pValue IN VARCHAR2,
pDelimiter IN VARCHAR2 DEFAULT CHR(0)
RETURN VARCHAR2
IS
BEGIN
BranchNameTable(pLevel) := pValue;
ReturnStrValue := pValue;
FOR I IN REVERSE 1..pLevel - 1 LOOP
ReturnStrValue := BranchNameTable(I)|| pDelimiter || ReturnStrValue;
END LOOP;
RETURN ReturnStrValue;
END BranchName;
FUNCTION BranchNumber(pLevel IN NUMBER,
pRnum IN NUMBER,
pDelimiter IN VARCHAR2 DEFAULT '.'
RETURN VARCHAR2
IS
BEGIN
BEGIN
IF pRnum = 1
THEN
BranchNumberTable.DELETE;
END IF;
BranchNumberTable(pLevel) := BranchNumberTable(pLevel) + 1;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
BranchNumberTable(pLevel) := 1;
END;
ReturnStrValue := BranchNumberTable(pLevel);
FOR I IN pLevel + 1..BranchNumberTable.LAST LOOP
BranchNumberTable.DELETE(I);
END LOOP;
FOR I IN REVERSE 1..pLevel - 1 LOOP
ReturnStrValue := BranchNumberTable(I)|| pDelimiter || ReturnStrValue;
END LOOP;
RETURN ReturnStrValue;
END BranchNumber;
FUNCTION BranchSum(pLevel IN NUMBER,
pValue IN NUMBER
RETURN NUMBER
IS
BEGIN
BranchSumTable(pLevel) := pValue;
ReturnNumValue := pValue;
FOR I IN REVERSE 1..pLevel - 1 LOOP
ReturnNumValue := BranchSumTable(I) + ReturnNumValue;
END LOOP;
RETURN ReturnNumValue;
END BranchSum;
FUNCTION BranchProd(pLevel IN NUMBER,
pValue IN NUMBER
RETURN NUMBER
IS
BEGIN
BranchSumTable(pLevel) := pValue;
ReturnNumValue := pValue;
FOR I IN REVERSE 1..pLevel - 1 LOOP
ReturnNumValue := BranchSumTable(I) * ReturnNumValue;
END LOOP;
RETURN ReturnNumValue;
END BranchProd;
FUNCTION IsNewBranch(pLevel IN NUMBER,
pRnum IN NUMBER
RETURN NUMBER
IS
BEGIN
IF pRnum = 1
THEN
PreviousLevel := pLevel;
RETURN 1;
END IF;
IF pLevel > PreviousLevel
THEN
PreviousLevel := pLevel;
RETURN 0;
ELSE
PreviousLevel := pLevel;
RETURN 1;
END IF;
END IsNewBranch;
END Hierarchy;
/Now:
WITH t AS ( SELECT 'SURI' user_name ,'01' Company FROM dual UNION ALL
SELECT 'SURI' user_name, '86' Company FROM dual UNION ALL
SELECT 'SURI' user_name ,'65' Company FROM dual UNION ALL
SELECT 'SRINU' user_name, '01' Company FROM dual UNION ALL
SELECT 'SRINU' user_name ,'86' Company FROM dual UNION ALL
SELECT 'SRINU' user_name ,'65' Company FROM dual ),
t1 AS (
SELECT user_name,
company,
row_number() over(partition by user_name order by company) rn,
count(*) over(partition by user_name) cnt
FROM t
t2 AS (
SELECT user_name,
Hierarchy.BranchName(level,company,',') company,
cnt,
rn
FROM t1
START WITH rn = 1
CONNECT BY user_name = PRIOR user_name
AND rn = PRIOR rn + 1
SELECT user_name,
company
FROM t2
WHERE rn = cnt
USER_NAME COMPANY
SRINU 01,65,86
SURI 01,65,86
SQL> SY. -
How to set a sql query time out with jdbc:oracle:thin
should i change the JDBC driver with jdbc:oralce:XA:thin or other driver with XA?
SQL query timeout may be set with setQueryTimeout.
http://java.sun.com/j2se/1.4.2/docs/api/java/sql/Statement.html#setQueryTimeout(int)
A query timeout bug is fixed in Oracle JDBC Drivers release
10.1.0.2.0 (10g)
FIXED BUG-2249191
In the Server Internal Driver, setting the query timeout does not
+(and likely will never) work. The query execution will not be+
canceled when the timeout expires, even if the query runs forever.
Further, after the query returns, the execution of your code
may pause for the length of the timeout.
http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/htdocs/jdbc_readme101020.html -
Using a SQL for Oracle in Microsoft Excel Query
I am having the most difficult time (in fact, I can't get it to work) trying to use an SQL I created in Toad for Oracle. It works fine in Toad for Oracle...gives me all the data I need. I am trying to use it in Excel for users that don't know SQL or Oracle so they can use the query to extract data they need for Charts, Graphs, etc.
Here is the SQL code from Toad for Oracle:
/* Formatted on 2006/09/22 11:42 (Formatter Plus v4.8.6) */
SELECT a_compl_summary.incident_number, a_compl_summary.case_number,
a_compl_summary.part_sequence, a_compl_summary.part_number,
a_compl_summary.lot_number, a_compl_summary.alert_date,
a_compl_summary.entry_date, a_compl_summary.NAME,
a_compl_summary.MONTH, a_compl_summary.product_family,
a_compl_summary.complaint, a_compl_summary.reportable,
a_compl_summary.product_returned, a_compl_summary.case_desc,
a_compl_summary.failure_invest_desc, a_compl_summary.lhr_search,
a_compl_summary.root_cause, a_compl_summary.corrective_action,
a_compl_summary.region,
rp_qa_reported_device_codes.reported_device_code,
rp_qa_reported_device_codes.reported_dev_clarification,
rp_qa_reported_device_codes.reported_dev_code_desc,
rp_qa_patient_codes.patient_code,
rp_qa_patient_codes.patient_code_clarif,
rp_qa_patient_codes.patient_code_severity,
rp_qa_patient_codes.description
FROM chsuser.a_compl_summary,
chsuser.rp_qa_patient_codes,
chsuser.rp_qa_reported_device_codes
WHERE ( (a_compl_summary.product_division = 'CP')
AND ( a_compl_summary.entry_date >= :date1
AND a_compl_summary.entry_date <= :date2
AND ( a_compl_summary.product_family LIKE :pf1
OR a_compl_summary.product_family LIKE :pf2
OR a_compl_summary.product_family LIKE :pf3
OR a_compl_summary.product_family LIKE :pf4
OR a_compl_summary.product_family LIKE :pf5
AND (a_compl_summary.region = :r1)
AND ( a_compl_summary.NAME = :c1
OR a_compl_summary.NAME = :c2
OR a_compl_summary.NAME = :c3
OR a_compl_summary.NAME = :c4
OR a_compl_summary.NAME = :c5
AND (a_compl_summary.complaint = :yorn)
AND ( rp_qa_reported_device_codes.reported_dev_clarification LIKE
:cl1
OR rp_qa_reported_device_codes.reported_dev_clarification LIKE
:cl2
OR rp_qa_reported_device_codes.reported_dev_clarification LIKE
:cl3
OR rp_qa_reported_device_codes.reported_dev_clarification LIKE
:cl4
OR rp_qa_reported_device_codes.reported_dev_clarification LIKE
:cl5
AND (rp_qa_reported_device_codes.reported_dev_clarification NOT LIKE
:dc1
AND (a_compl_summary.incident_number =
rp_qa_patient_codes.incident_number
AND (a_compl_summary.case_number = rp_qa_patient_codes.case_number)
AND (a_compl_summary.part_sequence = rp_qa_patient_codes.part_sequence
AND (a_compl_summary.incident_number =
rp_qa_reported_device_codes.incident_number
AND (a_compl_summary.case_number =
rp_qa_reported_device_codes.case_number
AND (a_compl_summary.part_sequence =
rp_qa_reported_device_codes.part_sequence
AND (rp_qa_reported_device_codes.incident_number =
rp_qa_patient_codes.incident_number
AND (rp_qa_reported_device_codes.case_number =
rp_qa_patient_codes.case_number
AND (rp_qa_reported_device_codes.part_sequence =
rp_qa_patient_codes.part_sequence
)Can someone help me...maybe point out what I'm doing wrong.
Note: I also tried creating this query in Microsoft Query (the simple way) and when I first create it...it works...But then if I go back in to edit the query, and refresh the query or try to Return data to Excel, it gives me a ORA-00936 error message.
Why it works when I first create the query in Excel, I don't know. But I have to validate the queries I'm creating (SQL or not) and I can't validate it if every time I go into edit the query (which may have to happen; that's why I have to fix this before I can submit my validation).
Anyway, any help would be greatly appreciated.Okay, I know I'm replying to my own threads here...but I want to add a little bit more information again.
I was successful in figuring out that changing the :criteria to a ? worked.
I tested this on 1 criteria at a time. Adding one more scenario ? at at time.
It only worked up until about 3 scenarios of each criteria.
Then when I refreshed the query in Microsoft Excel Query, I got an "out of memory" error, and then it ended up just erasing the SQL I had been using.
Here's the SQL I had where it gave me this error. Am I possibly just making Excel work too hard? It just doesn't make sense because Toad for Oracle handled it in like 4 seconds. Which brings me back to an intial question I had. Can Excel use Toad for Oracle somehow?
Here's the code:
SELECT a_compl_summary.incident_number, a_compl_summary.case_number,
a_compl_summary.part_sequence, a_compl_summary.part_number,
a_compl_summary.lot_number, a_compl_summary.alert_date,
a_compl_summary.entry_date, a_compl_summary.NAME,
a_compl_summary.MONTH, a_compl_summary.product_family,
a_compl_summary.complaint, a_compl_summary.reportable,
a_compl_summary.product_returned, a_compl_summary.case_desc,
a_compl_summary.failure_invest_desc, a_compl_summary.lhr_search,
a_compl_summary.root_cause, a_compl_summary.corrective_action,
a_compl_summary.region,
rp_qa_reported_device_codes.reported_device_code,
rp_qa_reported_device_codes.reported_dev_clarification,
rp_qa_reported_device_codes.reported_dev_code_desc,
rp_qa_patient_codes.patient_code,
rp_qa_patient_codes.patient_code_clarif,
rp_qa_patient_codes.patient_code_severity,
rp_qa_patient_codes.description
FROM chsuser.a_compl_summary,
chsuser.rp_qa_patient_codes,
chsuser.rp_qa_reported_device_codes
WHERE ( (a_compl_summary.incident_number =
rp_qa_patient_codes.incident_number
AND (a_compl_summary.case_number = rp_qa_patient_codes.case_number)
AND (a_compl_summary.part_sequence = rp_qa_patient_codes.part_sequence
AND (a_compl_summary.incident_number =
rp_qa_reported_device_codes.incident_number
AND (a_compl_summary.case_number =
rp_qa_reported_device_codes.case_number
AND (a_compl_summary.part_sequence =
rp_qa_reported_device_codes.part_sequence
AND (rp_qa_reported_device_codes.incident_number =
rp_qa_patient_codes.incident_number
AND (rp_qa_reported_device_codes.case_number =
rp_qa_patient_codes.case_number
AND (rp_qa_reported_device_codes.part_sequence =
rp_qa_patient_codes.part_sequence
AND (a_compl_summary.product_division = 'CP')
AND ( a_compl_summary.entry_date >= ?
AND a_compl_summary.entry_date <= ?
AND ( a_compl_summary.product_family LIKE ?
OR a_compl_summary.product_family LIKE ?
OR a_compl_summary.product_family LIKE ?
OR a_compl_summary.product_family LIKE ?
OR a_compl_summary.product_family LIKE ?
AND (a_compl_summary.region = ?)
AND ( a_compl_summary.NAME = ?
OR a_compl_summary.NAME = ?
OR a_compl_summary.NAME = ?
OR a_compl_summary.NAME = ?
OR a_compl_summary.NAME = ?
AND (a_compl_summary.complaint = ?)
AND ( rp_qa_reported_device_codes.reported_dev_clarification LIKE
OR rp_qa_reported_device_codes.reported_dev_clarification LIKE
OR rp_qa_reported_device_codes.reported_dev_clarification LIKE
OR rp_qa_reported_device_codes.reported_dev_clarification LIKE
OR rp_qa_reported_device_codes.reported_dev_clarification LIKE
AND (rp_qa_reported_device_codes.reported_dev_clarification NOT LIKE
)) -
SQL Query as Item Source/Oracle Reports w/ HTML DB?
I have successfully used a SQL Query as an item source in the past on several occasions. However, in this instance, every time I try to do this, I get the following error:
Error ERR-1019 Error computing item default value: page=3 name=P3_TEST_ITEM.
ORA-01460: unimplemented or unreasonable conversion requested ORA-02063: preceding line from [database_name]
If I use the exact same query in creating a report region, the page displays fine and the query returns the correct data. Why might this be happening, and what can I do to fix it?
Also - off the subject - is there a way to use HTML DB to deploy reports that are created in Oracle Reports Builder? I have created several employee productivity reports for supervisors and managers in HTML DB, which is great for allowing them to run them live and have fields as parameters for varying employees, date ranges, etc... but formatting them to be browser and printer friendly is an absolute nightmare so far. If I could create and format the reports in Reports Builder and then deploy them using HTML DB, while still being able to offer parameters to the user, that would be perfect. Is this possible?Here is my query:
SELECT
TO_CHAR((sum(decode(ef.production_function,'Y',ef.function_minutes+ef.function_ot_minutes))/60)/8, '9999999.99')
FROM
RLAPPLSG.EMPLOYEE_INFO@REMOTE_SERVER EI,
RLAPPLSG.SC_EMP_FUNCTIONS@REMOTE_SERVER EF,
RLAPPLSG.SC_EMP@REMOTE_SERVER E
WHERE
( e.SC_EMP_NBR=ef.SC_EMP_NBR )
AND ( ei.EMP_ID=e.EMP_ID )
AND (
( trunc(( e.SC_DATE )) BETWEEN :P2_BEGIN_DATE AND :P2_END_DATE )
AND (ei.EMP_MGRS_ID = :P2_SUPERVISOR_ID
OR ei.EMP_ID = :P2_SUPERVISOR_ID)
Every table and/or view that is referenced here is done so remotely. The column datatype breakdown is as follows:
production_function - BOOLEAN
function_minutes - NUMBER
function_ot_minutes - NUMBER -
How to Suppress The Output of a SQL Query In Oracle 11gR2
Hi Friends,
I am using oracle version 11.2.0.1, I have set a cronjob which will run on every 15 minutes and give us a log file mentioning the execution time taken for that SQL query:-
For example:
SQL> set timing on;
SQL> SELECT objProp FROM aradmin.arschema WHERE (schemaId = 175);
OBJPROP+
--------------------------------------------------------------------------------+
*6\60006\4\0\\60008\40\0\60009\4\0\\60010\4\0\\60018\4\0\\600*
*22\4\68\1\63\AR:jRL#*
Elapsed: 00:00:00.00
The above query will return the output as well as the time taken for execution of the query. I want to suppress the output of the query and only want the time taken to be printed. Is it possible by set commands. I have marked the output as bold and made it Italic.
Please help me at the earliest.
Regards,
Arijit>
I am using oracle version 11.2.0.1, I have set a cronjob which will run on every 15 minutes and give us a log file mentioning the execution time taken for that SQL query:-
The above query will return the output as well as the time taken for execution of the query. I want to suppress the output of the query and only want the time taken to be printed. Is it possible by set commands. I have marked the output as bold and made it Italic.
>
How would that even be useful?
A query from a tool such as sql*plus is STILL going to send the output to the client and the client. You can keep sql*plus from actually displaying the data by setting autotrace to trace only.
But that TIME TAKEN is still going to include the network time it takes to send ALL rows that the query returns across the network.
That time is NOT the same as the actual execution time of the query. So unless you are trying to determine how long it takes to send the data over the network your 'timing' method is rather flawed.
Why don't you tell us WHAT PROBLEM you are trying to solve so we can help you solve it? -
SQL query was failed in my report after migrating to Oracle 10gR2
We have a aplication running under Oracle 9.2.0.4 DB. we migrated our DB to Oracle 10gR2. While running the report, we got an error:
ORA-00904: "A3"."FACILITY_SYSTEM_ID": invalid identifier
ORA-06512: at "CEAS_MK_RPT.GET_LIST", line 12
The SQL query which causes this error is:
INSERT INTO gtt_facility_seq_generator
(date_range)
SELECT get_list
(CURSOR (SELECT auf.facility_system_id
FROM authorized_facility auf
WHERE auf.facility_system_id = afs.facility_system_id
AND auf.credit_application_system_id = :p_cred_appln_id
FROM authorized_facility afs,
(SELECT af.facility_system_id facility_system_id
FROM facility_obligor fo, authorized_facility af, party p
WHERE fo.facility_system_id = af.facility_system_id
AND fo.party_system_id = p.party_system_id
AND NOT EXISTS (
SELECT NULL
FROM facility_third_party_subst iftps
WHERE iftps.facility_system_id =
fo.facility_system_id)
) tab1
WHERE afs.credit_application_system_id = :p_cred_appln_id
AND tab1.facility_system_id = afs.facility_system_id
ORDER BY afs.creation_date;
The content of function get_list() is:
CREATE OR REPLACE FUNCTION CEAS_MK_RPT.Get_List
p_cursor IN sys_refcursor
RETURN VARCHAR2
IS
l_sep VARCHAR2(4);
l_text VARCHAR2(30000);
l_text_return VARCHAR2(30000);
BEGIN
LOOP
FETCH p_cursor INTO l_text;
EXIT WHEN p_cursor%NOTFOUND;
l_text_return := l_text_return || l_sep || l_text;
l_sep := CHR(10);
END LOOP;
CLOSE p_cursor;
RETURN l_text_return;
dbms_output.put_line ('a');
END Get_List;
The same report was executed perfectly in Oracle 9i. Kindly help us to short out this issue. Thanks in advance.
Regards,
Sengol SHi Nirav,
Many thanks for your response. I verified the same, but the same query was executed successfully after removing the INSERT INTO part(executed the SELECT part only). What might be the cause for this error?
For your kind information :
I have 2 schema in my DB( ceas_mk_app and ceas_mk_rpt ).
All the source tables are present in ceas_mk_app schema - These tables are used by ceas_mk_rpt schema(using synonym) to generate the report.
I'm executing the above said query from ceas_mk_rpt to insert the necessary data in to report temp. table.
Thanks,
Sengol S
Edited by: seng1256 on Dec 22, 2008 12:31 PM -
How to use this sql query in oracle?
Hi all,
i am using one sql query that is
SELECT @ToDate = '2012-10-03 00:00:00.000'
select @BetweenDate = DATEADD(MM,-1,@ToDate)
select @FromDate = DATEADD(m,DATEDIFF(m,0,@BetweenDate),0)
SELECT @ToDate = DATEADD(month, ((YEAR(@BetweenDate) - 1900) * 12) + MONTH(@BetweenDate), -1)
so @todate value is = '2012-10-03 00:00:00.000'
so in @betweendate value will come 1 month before like '2012-09-03 00:00:00.000'
again in @fromdate value will come like that '2012-09-01 00:00:00.000' means first date of @betweendate
and again @todate value will come like that '2012-09-30 00:00:00.000' means last date of @betweendate
it's happening in sql and i have to use same logic in oracle also.
how to use it??
thanksdeclare
todate date:= to_date('2012-10-03 00:00:00','yyyy-mm-dd hh:mi:ss');
betwendate date := add_months(todate,-1);
for datediff / additions you can direct subtract/add two different date variables
like
datediff = betweendate -todate
dateadd := todate+1; -
Sub-Select SQL query in Oracle BI Answers
Hi
What's the proper usage of Sub-Select SQL query in Oracle BI Answers Version Oracle Business Intelligence 10.1.3.2.1?
I get [SQL_STATE: HY000] [nQSError: 10058] A general error has occured when trying to Sub Select query like:
itemno = (SELECT MIN(orders.itemno) FROM mydatabase where rownum < 2 order by orders.itemno)Maybe the best is to create a new physical and logical object for your sub-select and join this with your current objects.
-
Store SQL Query in Oracle database
Hello,
I am storing SQL query in database. here is an example of query.
INSERT INTO TABLE_1 Values (' " + getValue1() + " ', ' " + getValue2() + " ' )
getValue1() and getValue2() are functions to retrieve values.
When I read query from the database and execute it, it doesn't read values from function.
After I read query from database I would expect it to be
INSERT INTO TABLE_1 Values ('value1', ' value2' ) but it is not reading values and trying to execute whatever I got from database.
Any help?
ThanksThanks for your reply. Let me give you more info.
All I am trying to do is storing queries in oracle
database to use it in future for reporting. As I am
doing reporting where clause will be different every
time. Reporting involves queries not updates. But in any case that means that you would use a java SQL string that is useable via a prepared statement. As such your statement would look like....
INSERT INTO TABLE_1 Values (?,?)
Is it not possible to substitute variable string I
got from database?What do you mean?
SQL is SQL. You construct SQL so it is valid and runs. Can you construct SQL so it runs a function/select and uses that value in some more SQL - depends on the database, but usually.
But that has nothing to do with java - it is SQL.
Query contains variables that I have in Java code .Then it is SQL. It is java. You use bind variables (see PreparedStatement) and assign values to it.
The SQL for such a query would look like the following...
select field1, field2 from table1 where id=?
In your java you would then use something like PreparedStatement.setInt(1, 100), to fill in the value for the '?' in the above.
You might also note that your solution will not work for any arbritrary SQL statement unless you are also storing meta data about the SQL itself. For instance the following SQL statements would return the same result set but your java code would have to populate the bind variables different for both...
select field1, field2 from table1 where id=? and name=?
select field1, field2 from table1 where name=? and id=? -
Can users see the query plan of a SQL query in Oracle?
Hi,
I wonder for a given sql query, after the system optimization, can I see the query plan in oracle? If yes, how to do that? thank you.
XingYou can use explain plan in SQLPlus
SQL> explain plan for select * from user_tables;
Explained.
Elapsed: 00:00:01.63
SQL> select * from table(dbms_xplan.display());
PLAN_TABLE_OUTPUT
Plan hash value: 806004009
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 2014 | 1123K| 507 (6)| 00:00:07 |
|* 1 | HASH JOIN RIGHT OUTER | | 2014 | 1123K| 507 (6)| 00:00:07 |
| 2 | TABLE ACCESS FULL | SEG$ | 4809 | 206K| 34 (3)| 00:00:01 |
|* 3 | HASH JOIN RIGHT OUTER | | 1697 | 873K| 472 (6)| 00:00:06 |
| 4 | TABLE ACCESS FULL | USER$ | 74 | 1036 | 3 (0)| 00:00:01 |
|* 5 | HASH JOIN OUTER | | 1697 | 850K| 468 (6)| 00:00:06 |
| 6 | NESTED LOOPS OUTER | | 1697 | 836K| 315 (6)| 00:00:04 |
|* 7 | HASH JOIN | | 1697 | 787K| 226 (8)| 00:00:03 |
| 8 | TABLE ACCESS FULL | TS$ | 13 | 221 | 5 (0)| 00:00:01 |
| 9 | NESTED LOOPS | | 1697 | 759K| 221 (8)| 00:00:03 |
| 10 | MERGE JOIN CARTESIAN | | 1697 | 599K| 162 (10)| 00:00:02 |
|* 11 | HASH JOIN | | 1 | 326 | 1 (100)| 00:00:01 |
|* 12 | FIXED TABLE FULL | X$KSPPI | 1 | 55 | 0 (0)| 00:00:01 |
| 13 | FIXED TABLE FULL | X$KSPPCV | 100 | 27100 | 0 (0)| 00:00:01 |
| 14 | BUFFER SORT | | 1697 | 61092 | 162 (10)| 00:00:02 |
|* 15 | TABLE ACCESS FULL | OBJ$ | 1697 | 61092 | 161 (10)| 00:00:02 |
|* 16 | TABLE ACCESS CLUSTER | TAB$ | 1 | 96 | 1 (0)| 00:00:01 |
|* 17 | INDEX UNIQUE SCAN | I_OBJ# | 1 | | 0 (0)| 00:00:01 |
| 18 | TABLE ACCESS BY INDEX ROWID| OBJ$ | 1 | 30 | 1 (0)| 00:00:01 |
|* 19 | INDEX UNIQUE SCAN | I_OBJ1 | 1 | | 0 (0)| 00:00:01 |
| 20 | TABLE ACCESS FULL | OBJ$ | 52728 | 411K| 151 (4)| 00:00:02 |
Predicate Information (identified by operation id):
1 - access("T"."FILE#"="S"."FILE#"(+) AND "T"."BLOCK#"="S"."BLOCK#"(+) AND
"T"."TS#"="S"."TS#"(+))
3 - access("CX"."OWNER#"="CU"."USER#"(+))
5 - access("T"."DATAOBJ#"="CX"."OBJ#"(+))
7 - access("T"."TS#"="TS"."TS#")
11 - access("KSPPI"."INDX"="KSPPCV"."INDX")
12 - filter("KSPPI"."KSPPINM"='_dml_monitoring_enabled')
15 - filter("O"."OWNER#"=USERENV('SCHEMAID') AND BITAND("O"."FLAGS",128)=0)
16 - filter(BITAND("T"."PROPERTY",1)=0)
17 - access("O"."OBJ#"="T"."OBJ#")
19 - access("T"."BOBJ#"="CO"."OBJ#"(+))
42 rows selected.
Elapsed: 00:00:03.61
SQL> If your plan table does not exist, execute the script $ORACLE_HOME/RDBMS/ADMIN/utlxplan.sql to create the table. -
Doubt in conversion of SQL query to oracle
Hi guys,
I'm new to oracle. I have a SQL query like the following,
Select * From my_table With(Index(PK_my_key))
I want to convert this to oracle. How can I specify the syntax *'With(Index(PK_my_key)) '* in oracle.
Please advice.
RamIs it possible to test that and find out the performance of the query? You need to check the execution plan of the query.
See these informative threads that explain in more detail :
When your query takes too long... When your query takes too long ...
How to post a SQL statement tuning request HOW TO: Post a SQL statement tuning request - template posting
Also, please post your database version (the result of: select * from v$version; ).
INDEX hints are nowadays (almost) never needed, unless you're on ancient database version.
As SomeoneElse already said: let Optimizer decide. -
Clarification on using function in where clause of oracle sql query
I have an issue in regarding function using where clause of sql query..
We are facing performance issue while executing query, so in what ways to improve the performance of the query which i have posted below.
select col ,case when my_function(parameter)
from tab1 a ,tab2 b,tabl3 c
where a.column1=b.column2
and b.column3 =c.column6
and my_function(parameter)>0
Regards
Dinesh
Edited by: wild fire on May 18, 2012 4:15 PMDinesh,
remind that when you use a function in the where clause it normally will get started for each record in the table.
So your answer is two-fold:
1. make the function only start when needed by adding a function based index on the table (this will make inserts and updates slower)
2. make the function faster by adding the DETERMINISTIC clause if possible. this will make Oracle "cache" the result of the function.
Regards,
Richard
blog: http://blog.warp11.nl
twitter: @rhjmartens
If this question is answered, please mark the thread as closed and assign points where earned..
Maybe you are looking for
-
Execution time for Call Library Function Node
I am experimenting with the Call Library Function Node block in LabVIEW and am curious if it should be running faster than what I'm seeing. For testing purposes, I have compiled and transfered to my RT target the .out file from the KB article http:/
-
Specified Order Grouping does not show if Distinct Count is Zero
Post Author: Hieu CA Forum: General Hello, I'm using Crystal Reports XI R2 with SQL data source. I have a cross-tab report with grouping in specified order. It's a report of applicants applying to a college. The grouping is of various majors (degrees
-
Do I really need to install an app iOS Updater for iOS 6.0.1 for my iPhone5?
-
SAP EXPRESS Pop-up not displaying
Hello Workflow experts, My workflow needs to display a pop-up when it arrives in the workflow inbox. I researched the site and found references to setting the priority to 1 in the activity step. This I understood to mean that I needed to go to the ta
-
Can use another web form UI instead of ADF forms for human task?
Hi everybody Can I use different web UI like primeface, ZK, Spring, Ext Js,... for generating forms base on human task instead of ADF forms? For both worklist and workspace Thanks.