Oracle Problemetic query
Hi All,
I encountered a strange problem in oracle PL/SQL.
I have a select query which fetches records from more than one table and it returns n rows lets say 1000 rows.
Note: The tables used in select query have a constant data.At any time i query, it returns the same result.
But when the same select query is used in an insert statement, it inserts less number records, say 300 records instead of 1000 rows.
Note: The destination table does not have any constraints (primary key/not null constraints).
Example
The select query :
SELECT
A.COL1,
A.COL2,
B.COL3,
B.COL2
FROM
TAB1 A
JOIN
TAB2 B
ON (A.COL4 = B.COL4);
The above query returns 1000 rows.
The insert query
INSERT INTO
TAB3
C1,
C2,
C3,
C4
SELECT
A.COL1,
A.COL2,
B.COL3,
B.COL2
FROM
TAB1 A
JOIN
TAB2 B
ON (A.COL4 = B.COL4);
The above insert statement inserts only less rows i.e., 300 instead of 1000.
Can any one help me out to sort this issue.
Thanks in advance.
Sorry, I can't replicate the problem. I'm on 10.2.0.4, Windows XP.
SQL> select o.object_id
2 ,o.created
3 ,s.synonym_name
4 ,s.table_name
5 from all_objects o
6 join all_synonyms s
7 on o.object_name = s.synonym_name
8 and o.owner = s.owner
9 ;
20080 rows selected.
SQL> insert into tab3
2 (object_id
3 ,created
4 ,synonym_name
5 ,table_name
6 )
7 select o.object_id
8 ,o.created
9 ,s.synonym_name
10 ,s.table_name
11 from all_objects o
12 join all_synonyms s
13 on o.object_name = s.synonym_name
14 and o.owner = s.owner
15 ;
20080 rows created.
SQL> select count(*) from tab3;
COUNT(*)
20080
SQL> truncate table tab3;
Table truncated.
SQL> create or replace
2 procedure insert_rows as
3 begin
4 insert into tab3
5 (object_id
6 ,created
7 ,synonym_name
8 ,table_name
9 )
10 select o.object_id
11 ,o.created
12 ,s.synonym_name
13 ,s.table_name
14 from all_objects o
15 join all_synonyms s
16 on o.object_name = s.synonym_name
17 and o.owner = s.owner
18 ;
19 commit;
20 end;
21 /
Procedure created.
SQL> exec insert_rows
PL/SQL procedure successfully completed.
SQL> select count(*) from tab3;
COUNT(*)
20080
Similar Messages
-
Oracle Text query: Escaping characters and specifying progression sequences
How can I combine the escaping of a search string and the specification of progression sequences within an oracle text query
so that in all cases the correct results are delivered (see example below)?
The scenario in which to use this is the following:
+ Database: Oracle Database 10g Enterprise Edition Release 10.2.0.2.0
+ Requirement: Hitlist of results ordered by score whereby the different part within
the result list are specified using progression sequences within oracle text query
Example:
create table service_provider (
id number,
name_c varchar(100),
uri_c varchar(255)
insert into service_provider values (1,'ABB Company Mgmt','http://www.abb-company-mgmt.de');
insert into service_provider values (2,'Dr. Abbas Ming','http://www.dr-abbas-ming.de');
insert into service_provider values (3,'SABBATA United','http://www.sabbata-united.de');
insert into service_provider values (4,'ABB','http://www.abb.de');
insert into service_provider values (5,'AND Company Mgmt','http://www.and-company-mgmt.de');
insert into service_provider values (6,'Dr. Andas Ming','http://www.dr-andas-ming.de');
insert into service_provider values (7,'SANDATA United','http://www.sandata-united.de');
insert into service_provider values (8,'AND','http://www.and.de');
Query 1: works correctly in this case
select * from (
select /*+ FIRST_ROWS */ score(1), this_.*
from service_provider this_
where
CONTAINS ( this_.NAME_C , '<QUERY><textquery grammar="CONTEXT">' ||
'<progression>' ||
'<seq>abb</seq>' ||
'<seq>abb%</seq>' ||
'<seq>%abb%</seq>' ||
'<seq>fuzzy(abb,1,100,WEIGHT)</seq>' ||
'</progression></textquery></QUERY>', 1 ) > 0
order by score(1) desc, this_.NAME_C
) where rownum < 21
delivers
76 4 ABB http://www.abb.de
76 1 ABB Company Mgmt http://www.abb-company-mgmt.de
51 2 Dr. Abbas Ming http://www.dr-abbas-ming.de
26 3 SABBATA United http://www.sabbata-united.de
Query 2: procudes error
select * from (
select /*+ FIRST_ROWS */ score(1), this_.*
from service_provider this_
where
CONTAINS ( this_.NAME_C , '<QUERY><textquery grammar="CONTEXT">' ||
'<progression>' ||
'<seq>and</seq>' ||
'<seq>and%</seq>' ||
'<seq>%and%</seq>' ||
'<seq>fuzzy(and,1,100,WEIGHT)</seq>' ||
'</progression></textquery></QUERY>', 1 ) > 0
order by score(1) desc, this_.NAME_C
) where rownum < 21
produces ORA-29902, ORA-20000, DRG-50901 because AND is a reserved word in oracle text
So we need escaping ...
Query 3: does not work correctly
select * from (
select /*+ FIRST_ROWS */ score(1), this_.*
from service_provider this_
where
CONTAINS ( this_.NAME_C , '<QUERY><textquery grammar="CONTEXT">' ||
'<progression>' ||
'<seq>{abb}</seq>' ||
'<seq>{abb%}</seq>' ||
'<seq>{%abb%}</seq>' ||
'<seq>fuzzy({abb},1,100,WEIGHT)</seq>' ||
'</progression></textquery></QUERY>', 1 ) > 0
order by score(1) desc, this_.NAME_C
) where rownum < 21
delivers
76 4 ABB http://www.abb.de
76 1 ABB Company Mgmt http://www.abb-company-mgmt.de
Query 4: does not produce an error, but also does not work correctly
select * from (
select /*+ FIRST_ROWS */ score(1), this_.*
from service_provider this_
where
CONTAINS ( this_.NAME_C , '<QUERY><textquery grammar="CONTEXT">' ||
'<progression>' ||
'<seq>{and}</seq>' ||
'<seq>{and%}</seq>' ||
'<seq>{%and%}</seq>' ||
'<seq>fuzzy({and},1,100,WEIGHT)</seq>' ||
'</progression></textquery></QUERY>', 1 ) > 0
order by score(1) desc, this_.NAME_C
) where rownum < 21
delivers
76 8 AND http://www.and.de
76 5 AND Company Mgmt http://www.and-company-mgmt.deAnywhere that you just use the word by itself, enclose it in {}, but anywhere that you add % on either side or both don't enclose it in {}. Please see the demonstration below.
SCOTT@10gXE> SELECT * FROM v$version
2 /
BANNER
Oracle Database 10g Express Edition Release 10.2.0.1.0 - Product
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
SCOTT@10gXE> create table service_provider
2 (id number,
3 name_c varchar(100),
4 uri_c varchar(255))
5 /
Table created.
SCOTT@10gXE> insert all
2 into service_provider values (1,'ABB Company Mgmt','http://www.abb-company-mgmt.de')
3 into service_provider values (2,'Dr. Abbas Ming','http://www.dr-abbas-ming.de')
4 into service_provider values (3,'SABBATA United','http://www.sabbata-united.de')
5 into service_provider values (4,'ABB','http://www.abb.de')
6 into service_provider values (5,'AND Company Mgmt','http://www.and-company-mgmt.de')
7 into service_provider values (6,'Dr. Andas Ming','http://www.dr-andas-ming.de')
8 into service_provider values (7,'SANDATA United','http://www.sandata-united.de')
9 into service_provider values (8,'AND','http://www.and.de')
10 into service_provider values (9,'EBB','fuzzy test')
11 into service_provider values (10,'OND','fuzzy test')
12 select * from dual
13 /
10 rows created.
SCOTT@10gXE> CREATE INDEX your_index
2 ON service_provider (name_c)
3 INDEXTYPE IS CTXSYS.CONTEXT
4 PARAMETERS ('STOPLIST CTXSYS.EMPTY_STOPLIST')
5 /
Index created.
SCOTT@10gXE> VARIABLE search_string VARCHAR2 (100)
SCOTT@10gXE> EXEC :search_string := 'abb'
PL/SQL procedure successfully completed.
SCOTT@10gXE> COLUMN name_c FORMAT A20 WORD_WRAPPED
SCOTT@10gXE> COLUMN uri_c FORMAT A40
SCOTT@10gXE> select *
2 from (select /*+ FIRST_ROWS */ score(1), this_.*
3 from service_provider this_
4 where CONTAINS
5 (this_.NAME_C ,
6 '<QUERY>
7 <textquery grammar="CONTEXT">
8 <progression>
9 <seq>{' || :search_string || '}</seq>
10 <seq>' || :search_string || '%</seq>
11 <seq>%' || :search_string || '%</seq>
12 <seq>fuzzy({' || :search_string || '},1,100,WEIGHT)</seq>
13 </progression>
14 </textquery>
15 </QUERY>', 1 ) > 0
16 order by score(1) desc, this_.NAME_C)
17 where rownum < 21
18 /
SCORE(1) ID NAME_C URI_C
76 4 ABB http://www.abb.de
76 1 ABB Company Mgmt http://www.abb-company-mgmt.de
51 2 Dr. Abbas Ming http://www.dr-abbas-ming.de
26 3 SABBATA United http://www.sabbata-united.de
4 9 EBB fuzzy test
SCOTT@10gXE> EXEC :search_string := 'and'
PL/SQL procedure successfully completed.
SCOTT@10gXE> /
SCORE(1) ID NAME_C URI_C
76 8 AND http://www.and.de
76 5 AND Company Mgmt http://www.and-company-mgmt.de
51 6 Dr. Andas Ming http://www.dr-andas-ming.de
26 7 SANDATA United http://www.sandata-united.de
5 10 OND fuzzy test
SCOTT@10gXE> -
Converting Oracle XML Query Result in Java String by using XSU
Hi,
I have a problem by converting Oracle XML Query Result in Java
String by using XSU. I use XSU for Java.
For example:
String datum=new OracleXMLQuery(conn,"Select max(ps.datum) from
preise ps where match='"+args[0]+"'");
String datum1=datum;
I become the following error:
Prototyp.java:47: Incompatible type for declaration. Can't
convert oracle.xml.sql.query.OracleXMLQuery to java.lang.String.
Can somebody tell me a method() for converting to solve my
problem??????
ThanksHmmm.. Pretty basic just look at the example:
OracleXMLQuery qry = new OracleXMLQuery(conn,"Select max(ps.datum) from preise ps where match='"+args[0]+"'");
String xmlString = qry.getXMLString();
Hi,
I have a problem by converting Oracle XML Query Result in Java
String by using XSU. I use XSU for Java.
For example:
String datum=new OracleXMLQuery(conn,"Select max(ps.datum) from
preise ps where match='"+args[0]+"'");
String datum1=datum;
I become the following error:
Prototyp.java:47: Incompatible type for declaration. Can't
convert oracle.xml.sql.query.OracleXMLQuery to java.lang.String.
Can somebody tell me a method() for converting to solve my
problem??????
Thanks -
Hi,
I have a View object with various attributes (eg, name1, name2, name3, address1, address2, address3 etc). A query/table component based on this view object works just fine. However, I wish to replace name1, name2, name3 and other attributes in the query with just 'name'. These attributes are still to be shown in the result table. This new 'name' attribute will be used in an Oracle Text query clause, instead of individual searches on each attribute.
My plan was to simply make the various name1, name2 etc attributes non-'queryable' in the View def to hide them from the query. Then I'd add a transient 'name' attribute. My hope was, that I could override the getWhereClause() in the ViewObjectImpl and simply tack on the oracle text clause to the WHERE (example below):
WHERE CONTAINS (
SOMECOLUMN,
'<query>
<textquery lang="ENGLISH" grammar="CONTEXT">TRANSIENT_ATTR_VALUE
..... Oracle Text query grammar stuff here .... </query>') > 0How do I access the transient value in the ViewObjectImpl to add the above SQL? Or am I going about this in completely the wrong way?
thanks,
Barry.Based on what I found in
http://www.oracle.com/technology/oramag/oracle/09-nov/o69frame.html?_template=/ocom/print
and
http://blogs.oracle.com/smuenchadf/examples/
136. Introducing a Checkbox to Toggle a Custom SQL Predicate on an LOV's Search Form. [11.1.1.0.0] 19-NOV-2008
I have the following implementation, which seems to work. Does anyone see any problems with this?
With regard to SQL injection, does ViewCriteriaItem sanitise the 'val' from the query, or should I do that manually here myself?
@Override
public java.lang.String getCriteriaItemClause(ViewCriteriaItem vci) {
if ("OraTextTransientAttrib".equals(vci.getAttributeDef().getName())) {
if (vci.getViewCriteria().isCriteriaForQuery()) {
String val = (String)vci.getValue();
logger.debug("Doing oracle text name search on '" + val + "'");
// simplified version of my oracle text query
return "CONTAINS ('<query>..... " + val + "....</query>') > 0 ";
} else {
// SQL predicate for no changes to the results
// spaces needed if you have several of these blocks
return " 1=1 ";
// other blocks for other similar oracle text attribs
return super.getCriteriaItemClause(vci);
} -
Oracle 9i query in Oracle 8 (Running Total)
Please tell me the alternate SQL for Oracle 8 against this query which is written in Oracle 9i:
SELECT empid,empname,empgpay,sum(empgpay) over (order by empid) AS runningtotal
FROM employee;There is not a sql structure in Oracle8i to do that directly in SQL Statement. You have to create a program unit to carry out it.
Joel P�rez -
User Function Name wrong resultset in Oracle Apps Query
Hi,
I am using the below query to extarct the user function names alonng with responsilibity .But doing so i am getting a User Function Name for eg 'Cross Validation Rules' under Order Management User.But thats wrong.Cross validation rules should exists in Receivables,GL and Payables.
select distinct frv.menu_id, frv.responsibility_id, frv.responsibility_name, fff.function_name, ffft.user_function_name
from
fnd_responsibility_vl frv,
fnd_responsibility frp,
fnd_form_functions fff,
fnd_form_functions_tl ffft,
fnd_resp_functions resp,
fnd_menu_entries mnu,
fnd_menus fmn
where
fff.function_id = ffft.function_id
and mnu.menu_id=frp.menu_id
and mnu.menu_id=fmn.menu_id
and frv.responsibility_id=resp.responsibility_id
and mnu.function_id=ffft.function_id
and resp.rule_type='M'
and frv.menu_id in (select me.menu_id
from fnd_menu_entries me
start with me.function_id = fff.function_id
connect by prior me.menu_id = me.sub_menu_id )
and (frv.responsibility_name like '%Order%')
order by 1
Kindly any help will be helpful for meWhat is your application release?
I am using the below query to extarct the user function names alonng with responsilibity .But doing so i am getting a User Function Name for eg 'Cross Validation Rules' under Order Management User.But thats wrong.Cross validation rules should exists in Receivables,GL and Payables.Please try the queries in these docs.
Script To Extract Submenu And Function Information About A Menu [ID 458701.1]
HOW TO GENERATE MENU TREE FOR A MENU ATTACHED TO A RESPONSIBILITY IN ORACLE APPLICATIONS 11i ? [ID 312014.1]
Thanks,
Hussein -
View links in oracle ADF/query featching from Database
Please any one help for this query
I have two tables Emp, Dept
I have query like this select * from Emp e, Dept d where e.deptno=d.deptno
Query is fetching like this
Empno Ename job Salary Comm deptno deptno dname Loc
15 i1 support 50000 11 5 5 IT sss
15 i1 support 50000 11 3 3 Account sss
16 i2 support 8000 10 5 5 IT sss
16 i2 support 8000 10 3 3 Account sss
16 i2 support 8000 10 3 3 Software sss
16 i2 support 8000 10 4 4 Operation sss
Query is fetching 6 rows.
but my requirement is what ever records fetching from database with same employee number is one record that is same employee number dept names grouped I will show it as one record how to fetch records from data base.
Here is the example (My Requirement):
This is first row:
Empno Ename job Salary Comm
15 i1 support 50000 11
Deptno dname Loc
5 IT sss
3 Account sss
This is second row:
Empno ename job Salary Comm
16 i2 support 8000 10
Deptno dname Loc
5 IT sss
3 Account sss
2 Software sss
4 Operation sss
i am useing oracle ADF if any possibility in view links either i get from the query as i mentioned.
plz any one can help
thanksPlease any one help for this query
I have two tables Emp, Dept
I have query like this select * from Emp e, Dept d where e.deptno=d.deptno
Query is fetching like this
Empno Ename job Salary Comm deptno deptno dname Loc
15 i1 support 50000 11 5 5 IT sss
15 i1 support 50000 11 3 3 Account sss
16 i2 support 8000 10 5 5 IT sss
16 i2 support 8000 10 3 3 Account sss
16 i2 support 8000 10 3 3 Software sss
16 i2 support 8000 10 4 4 Operation sss
Query is fetching 6 rows.
but my requirement is what ever records fetching from database with same employee number is one record that is same employee number dept names grouped I will show it as one record how to fetch records from data base.
Here is the example (My Requirement):
This is first row:
Empno Ename job Salary Comm
15 i1 support 50000 11
Deptno dname Loc
5 IT sss
3 Account sss
This is second row:
Empno ename job Salary Comm
16 i2 support 8000 10
Deptno dname Loc
5 IT sss
3 Account sss
2 Software sss
4 Operation sss
i am useing oracle ADF if any possibility in view links either i get from the query as i mentioned.
plz any one can help
thanks -
Conversion of Mysql query in oracle acceptable query format
Hi
I have successfully converted my MySql database in oracle. Now the problem is how to execute already written hundreds of Mysql query on the oracle. There are many syntax variation in Mysql query format which is not acceptable for oracle.
For Example
Select case_id as 'this is alias' from cases
The above query can run on Mysql database but have problem while executing Oracle, because single quotes should be replaced with double quotes before executing it on oracle. There are also many other syntax conflicts.
I have tried to resolve the problem through SwisSQLAPI but problem still exist as SwisSQLAPI is not dealing with all syntax conflict. In my case (select if (expresion, true,false)) must be replace with decode (expression, value,true,false) function of oracle and this conversion is not supported by SwisSQLAPI.
Please help me in resolving this problem
ThanksThe problem with trying to port from one language (mysql SQL) to another (oracle SQL) is that there's generally no hard rules for a computer to follow, that it will get it 100% correct.
Look at babelfish when you translate a foreign language to English. The end result is readable (usually), but it's rarely completely correct.
The problem is when you feed something into Oracle SQL, it needs to be 100% correct.
All you can really do here is rewrite these queries. It shouldn't actually take as long as you think, because 50% of queries will generally need very minor changes you can do in a minute, and 25% won't need any changes at all. -
Check Index used in an oracle select query
Hi Friends,
I have partitioned an oracle table and created Local Index for the Partitioned table .
Now i want to make sure that the Local index is being used when i perform select query on the Table partition.
How do i confirm that ?
can i check the explain plan generted for the select query to confirm local index is being used ?
Please let me know.
Regards,
DBNow i want to make sure that the Local index is being used when i perform select query on the Table partition.Why? Have you proven that using this local index is the "best" plan?
How do i confirm that ?
can i check the explain plan generted for the select query to confirm local index is being used ?When I asked Google "how to read an oracle explain plan," I found lots of information - what did you find? -
How to generate XML file from oracle database query result
Hi dudes,
as stated on the subject, can anyone suggests me how can i achieve the task stated above??
Here is a brief description of my problem:
I need to create a XML file once i query from the oracle database, and the query result returned from the database will be stored in XML file.
I'd searched around the JAXB, DOM, SAXP and the like basic concepts, but i still don't know how to start??
Any suggestions ???Read this:
http://www.cafeconleche.org/books/xmljava/chapters/ch08s05.html
You might have to read more of the book to understand that chapter. -
Hi all....
I am using oracle 10g........
The following query is a union of two queries....The second query is a subset of the first meaning that it has fewer tables and fewer select columns as well....(I have to use union on the two queries....for a gud reason) .What i want is that the union return only the superset records from result of the union of the two queries when i pass a parameter at runtime like supplier_name as mentioned in the the query below .......
/* Formatted on 2012/05/14 16:49 (Formatter Plus v4.8.8) */
SELECT * FROM(SELECT DISTINCT reql.unit_meas_lookup_code "UNIT",
reqh.type_lookup_code "PR_TYPE",
reql.document_type_code "SUBTYPE",
reqh.segment1 "PR_NO", reqh.creation_date "PR DATE",
mtb.segment1 "ITEM_CODE",
pol.item_description "DESCRIPTION",
mcb.segment1 "INVENTORY_CATEGORY",
reql.manufacturer_part_number "MFG NO/DRG NO",
poh.authorization_status "AUTHORIZATION STATUS",
papf.full_name "BUYER", NULL "CUSTOMER",
DECODE (poh.type_lookup_code,
'RFQ', poh.segment1
) "RFQ NO",
DECODE (poh.type_lookup_code,
'RFQ', poh.creation_date
) "RFQ DATE",
NULL "RFQ SUPPLIER",
DECODE (poh.type_lookup_code,
'QUOTATION', poh.segment1
) "QTN NO",
DECODE (poh.type_lookup_code,
'QUOTATION', poh.reply_date
) "QTN DATE",
DECODE (poh.type_lookup_code,
'STANDARD', poh.segment1,
'BLANKET', poh.segment1,
'PLANNED', poh.segment1
) "PO_NO",
DECODE (poh.type_lookup_code,
'STANDARD', poh.creation_date,
'BLANKET', poh.creation_date,
'PLANNED', poh.creation_date
) "PO DATE",
pv.vendor_name "SUPPLIER",
NULL "SUPPLIER ACKNOWLEDGMENT DATE",
TRUNC
(reqh.creation_date
- TRUNC (poh.creation_date)
"NO OF DAYS TAKEN FROM PR TO PO",
DECODE (rcvh.asn_type,
'ASBN', rcvh.shipment_num
) "ASBN NO",
rcvh.receipt_num "RECEIPT NO",
rcvh.creation_date "RECEIPT DATE",
apia.invoice_num "INVOICE_NO",
NULL "QUALITY INSPECTION DATE",
rcvt.inspection_status_code "INSPECTION RESULT",
NULL "STOCKING DATE",
TRUNC (poh.creation_date)
- TRUNC (reqh.creation_date) "NO OF DAYS TAKEN FROM",
NULL "PV NO", NULL "PV DATE",
apc.amount "PAYMENT RELEASE AMOUNT",
apc.released_date "PAYMENT RELEASE DATE",
apc.payment_method_code "PAYMENT RELEASE MODE",
NULL "NO OF DAYS TAKEN FROM RECEIPT"
FROM po_requisition_headers_all reqh,
po_requisition_lines_all reql,
po_req_distributions_all reqd,
po_distributions_all pod,
po_headers_all poh,
po_lines_all pol,
po_line_locations_all poll,
rcv_shipment_headers rcvh,
rcv_shipment_lines rcvl,
rcv_transactions rcvt,
ap_invoice_distributions_all apid,
ap_invoices_all apia,
ap_payment_schedules_all aps,
ap_invoice_payments_all app,
ap_checks_all apc,
per_all_people_f papf,
po_vendors pv,
mtl_system_items_b mtb,
mtl_categories_b mcb,
mtl_item_categories mic
WHERE reqh.requisition_header_id =
reql.requisition_header_id
AND reql.requisition_line_id = reqd.requisition_line_id
AND pod.req_distribution_id = reqd.distribution_id
AND pol.po_line_id = pod.po_line_id
AND poh.po_header_id = pol.po_header_id
AND pol.po_line_id = poll.po_line_id
AND pod.po_distribution_id = apid.po_distribution_id
AND pod.po_distribution_id = rcvt.po_distribution_id
AND rcvl.shipment_header_id = rcvh.shipment_header_id
AND rcvh.shipment_header_id = rcvt.shipment_header_id
AND rcvt.po_distribution_id = apid.po_distribution_id
AND app.check_id = apc.check_id
AND apid.invoice_id = apia.invoice_id
AND apia.invoice_id = app.invoice_id
AND app.invoice_id = aps.invoice_id
AND poh.agent_id = papf.person_id
AND poh.vendor_id = pv.vendor_id
AND pol.item_id = mtb.inventory_item_id
AND mic.inventory_item_id = pol.item_id
AND poh.authorization_status = 'APPROVED'
AND mcb.category_id = mic.category_id
UNION
SELECT DISTINCT NULL "UNIT", NULL "PR_TYPE", NULL "SUBTYPE",
NULL "PR_NO", NULL "PR DATE",
mtb.segment1 "ITEM_CODE",
pol.item_description "DESCRIPTION",
mcb.segment1 "INVENTORY_CATEGORY", NULL,
poh.authorization_status "AUTHORIZATION STATUS",
papf.full_name "BUYER", NULL "CUSTOMER",
DECODE (poh.type_lookup_code,
'RFQ', poh.segment1
) "RFQ NO",
DECODE (poh.type_lookup_code,
'RFQ', poh.creation_date
) "RFQ DATE",
NULL "RFQ SUPPLIER",
DECODE (poh.type_lookup_code,
'QUOTATION', poh.segment1
) "QTN NO",
DECODE (poh.type_lookup_code,
'QUOTATION', poh.reply_date
) "QTN DATE",
DECODE (poh.type_lookup_code,
'STANDARD', poh.segment1,
'BLANKET', poh.segment1,
'PLANNED', poh.segment1
) "PO_NO",
DECODE (poh.type_lookup_code,
'STANDARD', poh.creation_date,
'BLANKET', poh.creation_date,
'PLANNED', poh.creation_date
) "PO DATE",
pv.vendor_name "SUPPLIER",
NULL "SUPPLIER ACKNOWLEDGMENT DATE", NULL,
DECODE (rcvh.asn_type,
'ASBN', rcvh.shipment_num
) "ASBN NO",
rcvh.receipt_num "RECEIPT NO",
rcvh.creation_date "RECEIPT DATE",
apia.invoice_num "INVOICE_NO",
NULL "QUALITY INSPECTION DATE",
rcvt.inspection_status_code "INSPECTION RESULT",
NULL "STOCKING DATE", NULL, NULL "PV NO",
NULL "PV DATE", apc.amount "PAYMENT RELEASE AMOUNT",
apc.released_date "PAYMENT RELEASE DATE",
apc.payment_method_code "PAYMENT RELEASE MODE",
NULL "NO OF DAYS TAKEN FROM RECEIPT"
FROM po_distributions_all pod,
po_headers_all poh,
po_lines_all pol,
rcv_shipment_headers rcvh,
rcv_shipment_lines rcvl,
rcv_transactions rcvt,
ap_invoice_distributions_all apid,
ap_invoices_all apia,
ap_payment_schedules_all aps,
ap_invoice_payments_all app,
ap_checks_all apc,
per_all_people_f papf,
po_vendors pv,
mtl_system_items_b mtb,
mtl_categories_b mcb,
mtl_item_categories mic
WHERE pol.po_line_id = pod.po_line_id
AND poh.po_header_id = pol.po_header_id
AND pod.po_distribution_id = apid.po_distribution_id
AND pod.po_distribution_id = rcvt.po_distribution_id
AND rcvl.shipment_header_id = rcvh.shipment_header_id
AND rcvh.shipment_header_id = rcvt.shipment_header_id
AND rcvt.po_distribution_id = apid.po_distribution_id
AND app.check_id = apc.check_id
AND apid.invoice_id = apia.invoice_id
AND apia.invoice_id = app.invoice_id
AND app.invoice_id = aps.invoice_id
AND poh.agent_id = papf.person_id
AND poh.vendor_id = pv.vendor_id
AND pol.item_id = mtb.inventory_item_id
AND mic.inventory_item_id = pol.item_id
AND poh.authorization_status = 'APPROVED'
AND mcb.category_id = mic.category_id) a
WHERE 1 = 1
AND ( a.pr_type = NVL (:pr_type, a.pr_type)
OR (:pr_type IS NULL AND a.pr_type IS NULL)
AND ( a.pr_no = NVL (:pr_no, a.pr_no)
OR (:pr_no IS NULL AND a.pr_no IS NULL)
AND ( a.unit = NVL (:unit_lookup_code, a.unit)
OR (:unit_lookup_code IS NULL AND a.unit IS NULL)
AND a.supplier = NVL (:supplier_name, a.supplier)
AND a.inventory_category = NVL (:inventory_category, a.inventory_category)
AND a.buyer = NVL (:buyer_name, a.buyer)
AND a.invoice_no = NVL (:invoice_no, a.invoice_no)
AND a.item_code = NVL (:item_code, a.item_code)
Edited by: Dave on May 14, 2012 5:08 AM
Edited by: Dave on May 14, 2012 5:14 AMDave wrote:
What i want is that the union return only the superset records from result of the union of the two queriesThat is what Union does.
If it doesn't, then it means it's not real duplicates.
For example :Scott@my11g SQL>with
2 table_A(val) as (
3 select 'This is a duplicate' from dual
4 union all select 'This is another' from dual
5 union all select 'This is not' from dual
6 )
7 ,table_B(val) as (
8 select 'This is a duplicate' from dual
9 union all select 'This is another' from dual
10 )
11 ------ end of sample data ------
12 select val from table_A
13 union
14 select val from table_B ;
Scott@my11g SQL>/
VAL
This is a duplicate
This is another
This is notSee ? only 3 rows from the 5 (3+2) originals.
But if I add some pseudo columns Which_table with different values for each table, then :Scott@my11g SQL>with
2 table_A(val) as (
3 select 'This is a duplicate' from dual
4 union all select 'This is another' from dual
5 union all select 'This is not' from dual
6 )
7 ,table_B(val) as (
8 select 'This is a duplicate' from dual
9 union all select 'This is another' from dual
10 )
11 ------ end of sample data ------
12 select val, 'from table_A' which_table from table_A
13 union
14 select val, 'from table_B' from table_B ;
VAL WHICH_TABLE
This is a duplicate from table_A
This is a duplicate from table_B
This is another from table_A
This is another from table_B
This is not from table_AThere is now 5 rows, they are no longer duplicates. -
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.. -
Oracle Sql Query issue Running on Different DB Version
Hello All,
I have come into situation where we are pruning sql queries on different DB version of Oracle and have performance issue. Let me tell you in brief and i really appreciate for your prompt response as its very imperative stuff.
I have a query which is running on a DB of version 7.3.4 and it takes around 30 mins where as the same query when run on 8i it takes 15sec., its a huge difference. I have run the statistics to analyze on 7.3 and its comparatively very high. Question here is, the sql query trys to select data from same schema table and 2 tables from another DB using DB link and 2 other tables from another DB using DB link.So,how can we optimize this stuff and achieve this run as same time as 8i DB in 7.3. Hope i am clear about my question, Eagerly waiting for your replies.
Thanks in Advance.
Message was edited by:
Ram8Difficult to be sure without any more detailed information, but I suspect that O7 is in effect copying the remote tables to local temp space, then joining; 8i is factoring out a better query to send to the remote DBs, which does as much work as possible on the remote DB before shipping remaining rows back to local.
You should be able to use EXPLAIN PLAN to identify what SQL is being shipped to the remote DB, If you can't (and it's been quite a while since I tried DB links or O7) then get the remote DBs to yourself, and set SQL_TRACE on for the remote instances. Execute the query and then examine the remote trace files, And don't forget to turn off the tracing when you're done.
Of course it could just be that the CBO got better,,,
HTH - if not, post your query and plans for the local db, and the remote queries.
Regards Nigel -
A Oracle sql query is needed, please help me out
Hi,
I have a table similar to scott.emp table and i should get first three recently joined employees salaries according to their joined date from each deptno
output should like this:
deptno firstempsalary secondemplsal thirdemploysalary
10 xxx xxx xxxx
20 xx xx
30 xx xxx xxxx
40 xx
50 xx xxxx xxx
60 xx xx
70 xx
it means that 70 dept having only one employee and 20 dept having only two employees and 10 dept having more than three employees but we should get only three recently joined employees salaries from 10 dept.
Hope this is clear .. please give me a query to get this info ..
oracle is 10g version
great thanks in advance.select deptno,
max(case jd_rank when 1 then salary end) firstempsal,
max(case jd_rank when 2 then salary end) secondempsal,
max(case jd_rank when 3 then salary end) thirdempsal
from
(select salary, deptno, row_number() over(partition by deptno order by join_date desc) jd_rank from emp)
group by deptno
Problem here is what to do when employees have the same join date? This example will arbitrarily choose their order and if, for example, three employees share the same (most recent) join date then they will arbitrarily be classed as "first", "second" and "third". If four employees join at the same time, one of them will be ignored at random!
Edited by: user10548434 on 03-Dec-2008 06:27 -
Oracle SQL Query from EXCEL 2007 with prompt
Hello,
I have many excel reports where I am pulling information from our Oracle 9 db through Excel using the following method:
http://blog.mclaughlinsoftware.com/microsoft-excel/how-to-query-oracle-from-excel-2007/
http://blog.mclaughlinsoftware.com/2009/11/30/sql-query-in-excel-2007/
However, I am having trouble when I try the following query due to the prompt:
SELECT
IM.ITEM_GROUP,
IM.ITEM,
IM.DESCRIPTION
FROM
LAWSON.ITEMMAST IM
WHERE
IM.ITEM = '&ITEM';
Does any one know how I can connect a prompt to an excel cell and then pass the query on to Oracle, or have a PL SQL prompt work from Excel?
Thanks,
BenThe 'prompt' as you call it is a sqlplus feature, so does not belong to the SQL language
You would need to write a stored procedure returning a resultset.
create or replace procedure foo(rc in out sys_refcursor, p_item) as
begin
open rc for
'SELECT
IM.ITEM_GROUP,
IM.ITEM,
IM.DESCRIPTION
FROM
LAWSON.ITEMMAST IM
WHERE
IM.ITEM = '||p_item;
end;
and call that using ODBC or asp.net
Obviously this is profusely documented.
Sybrand Bakker
Senior Oracle DBA
Maybe you are looking for
-
Substitute approver report?
Does anyone know if there is a report that will show my who have been set up as the substitue approvers for a list of users? If not could anyone point me to the tables which hold substitue approver info? Looking forward to hearing the answer. Thanks.
-
I can't upgrade my forms central account
Every time I go to upgrade there's no options to upgrade so I can have more than 50 responses, how do I get more than 50 responses then? There's no upgrade or buy functions, just information, not even price or anything, it just takes me here.. Quickl
-
My iPod touch sleep/wake button is jammed.
Does anyone know any way to get my sleep/wake button fixed for cheap? I don't even inderstand why it's jammed. I have been gental with it, such. I'm really expecting any good support as Apple is horrible with that. (From past expierences) But I just
-
Hello, I just downloaded a template on the internet and I want to render it now, But when i try to render it I get the error: 2 footage files required to render composition "Template by IntroArtZ" are missing. How can I fix this?
-
Javax.mail.SendFailedException: 553 sorry, that domain isn't in my list of
i have put all the lines in the code required to set the server name and the username and the password but it still gives me the error. i have the following code to send the mail. package com.wesra.mail; import java.io.PrintStream; import java.util.H