SQL & PL/SQL :: ANSI Join Returning Wrong Dataset?

May 25, 2011

...continued from "Problems with full outer join"I think that ANSI joins in Oracle doesn't work correctly. Or am I doing something wrong? The query looks like this:

select nvl(k.id_pers,t.id_pers) id_pers, k.dat_avst
, id_trans, dat_trans
from
( select ka.id_pers, ka.dat_avst, ka.dat_nasta_avst

[code]...

It's a full outer join between one table (with a subquery) and an inline view with two tables You can see the returned rows in the listing below. The query returns one row where there is a match between t_trans and t_kontoavst.It also returns two rows from table t_kontoavst with no correspondence in t_trans.Finally it returns 26 rows from the table t_trans with no correspondence in t_kontoavst. But among them there are many rows in contradiction to the conditions:

and trunc(dat_trans) >= to_date('20040101','yyyymmdd')
and trunc(dat_trans) <= to_date('20050604','yyyymmdd')

Actually it seems to return all the 27 rows in t_trans (one of them joined to t_kontoavst).These conditions are actually not part of the join so I changed it to:

where trunc(dat_trans) >= to_date('20040101','yyyymmdd')
and trunc(dat_trans) <= to_date('20050604','yyyymmdd')

It's not clear to me if this where condition belongs to the joined result or just to the right joined inline view.With this change the correct rows from t_trans where returned but unfortunately the two rows from t_kontoavst with no correspondence in t_transdisappeared. I thought maybe that is because dat_trans is null for these two rows after the join. Therfore I also includeddat_trans to be null. This can only happen when t_trans is missing

where dat_trans is null
or (trunc(dat_trans) >= to_date('20040101','yyyymmdd')
and trunc(dat_trans) <= to_date('20050604','yyyymmdd'))

But that didn't change the result I have also tried right and left joins and it produces similar errors.One other thing i tried was to replace the inline view with one of the underlying tables t_trans. But the result was the same.Data returned from the original query (see query above):

ID_PERSDAT_AVSTID_TRANSDAT_TRANS
1945050505022005-05-011721642005-05-16
194505050502null1723722005-06-16
194505050502null1723732005-07-16

[code]...

Data in the tables.SQL Statement which produced this data:

select id_trans, id_pers, dat_trans
from t_trans
order by id_pers, dat_trans, id_trans

ID_TRANSID_PERSDAT_TRANS
1721641945050505022005-05-16
1723721945050505022005-06-16
1723731945050505022005-07-16

[code]...

SQL Statement which produced this data:

select id_pers, dat_avst
from t_kontoavst
order by id_pers, dat_avst

ID_PERSDAT_AVST
1945050505021997-05-01
1945050505022005-05-01
1958080808071997-05-01

[code]...

View 16 Replies


ADVERTISEMENT

SQL & PL/SQL :: Use ANSI Standard JOIN Syntax?

Oct 9, 2013

Use ANSI standard JOIN syntax for example i have this code.

SELECT resv_num, unit_date
FROM p_resv_unit ru, p_pm_unit_night pun
WHERE pun.property_id = in_property_id
AND pun.pm_unit_num = cvUnitNum
AND pun.unit_date BETWEEN start_date AND end_date
AND pun.resv_unit_id = ru.resv_unit_id;

[code]....

and is it a good idea to change it, because both ways it works?

View 15 Replies View Related

SQL & PL/SQL :: Where To Implement ANSI JOIN In Real Time

Dec 9, 2010

I want to know about ANSI JOIN in Oracle 9i and how to use this ANSI JOINS and where we have to implement this ANSI JOIN in real time.

View 2 Replies View Related

SQL & PL/SQL :: Filtering Dataset Based On Records Returned By Table Join

Nov 10, 2010

I need to work on this requirement.

There are FOUR tables ( T1 , T11 & T2, T22) ALL store order information.

One of four conditions are possible for each Supply Reorder Number:

•Both table queries return no records

oPopulate all the output fields with nulls

•T1 returns a record, but T2 returns no records

oPopulate output fields with values from the join of T1 and T11.

•T1 returns no records, but T2 returns one record

oPopulate output fields with values from the join of T2 and T22.

•T1 returns a record, and T2 returns a record

oIf the latest order is in T1, then populate output fields with values from the join of T1 and T11.

oIf order dates are equal from both join results, then populate output fields with values from the join of T1 and T11 .

oIf the latest order is in T2, then populate output fields with values from the join of T2 and T22.

How do we filter the dataset based on result of table join ?

View 1 Replies View Related

Multiple Table Query Returning Duplicates With Wrong Values

Oct 20, 2012

These are the tables I'm working with:

SQL> desc custinfo;
Name Null? Type
----------------------------------------- -------- ----------------------------
CUSTID VARCHAR2(4)
CUSTNAME VARCHAR2(18)
CUSTADR VARCHAR2(12)
CUSTCITY VARCHAR2(10)
CUSTSTATE CHAR(2)
CUSTZIP VARCHAR2(5)
CAPACITY NUMBER(3)
HOUSECODE VARCHAR2(2)
[code]...

I don't understand why the custid is the same for each customer, and why it's selecting every customer and not just those with more than 150 gallons ordered.

For this one use the oil tables that you set up and use a subquery. Select the minimum average fall use from the house table. Then show all customers whose number of gallons delivered times two is greater than the minimum.

View 4 Replies View Related

SQL & PL/SQL :: ANSI To NON-ANSI SQL Conversion

Dec 10, 2010

A very simple question yet so difficult...

I have a ansi query...

select * from
tz1
left outer join tz2 on tz1.aa=tz2.cc and tz1.bb is null;

What is the most efficient non-ansi way of writing it?

-----------------script-----------------
create table tz1(aa int, bb int);
create table tz2(cc int, dd int);

insert into tz1 values (1, 100);
insert into tz1 values (2, 200);
insert into tz1 values (3, 300);

[Code]......

View 6 Replies View Related

SQL & PL/SQL :: Rewrite Query Which Is In ANSI 92 Standard To ANSI 89 Standard

Jun 17, 2011

To rewrite this sql which is in ANSI 92 standard to ANSI 89 standard.

SELECT "PROJECT"."X_SAMPLED_DATE", SAMPLE"."SAMPLE_NUMBER"
FROM "SHIRE_PRD"."LimsUser"."SAMPLE" "SAMPLE" INNER JOIN "SHIRE_PRD"."LimsUser"."PROJECT" "PROJECT" ON"SAMPLE"."PROJECT"="PROJECT"."NAME"
WHERE ("SAMPLE"."SAMPLE_TYPE"='EM' OR "SAMPLE"."SAMPLE_TYPE"='WATER') AND "SAMPLE"."STATUS"<>'X' AND("PROJECT"."X_SAMPLED_DATE">={ts '2011-05-01 00:00:00'} AND "PROJECT"."X_SAMPLED_DATE"<{ts '2011-06-01 00:00:00'})
ORDER BY "SAMPLE"."PRODUCT"

View 4 Replies View Related

PL/SQL :: Insert Dataset Into Some Table?

Jul 9, 2013

Can we use result of with query_name ... to insert dataset into some table? I'm usung 11.2.0.3 

View 5 Replies View Related

Oracle Dataset - How To Split Datetime

Jun 2, 2008

my problem is:

i running a sql-query in visual studio 2005 with the oracle dataset. currently my datetime is in format mm/dd/yyyy hh:mm:ss. I wish to split the datetime in dd/mm/yyyy only(without the hh:mm:ss)

EXEC ('
SELECT
XNP_TIMER_VIOLATION.VIOLATION_TIME,..
FROM XNP_TIMER_VIOLATION,..
) AT npcrpt ;

View 4 Replies View Related

Convert Content Of Blob Ansi To Utf-8?

Nov 25, 2011

I wondered the possibility of converting a content file in the format ansi to utf-8 directly from Oracle.

View 1 Replies View Related

SQL & PL/SQL :: Convert Oracle Joins To Ansi?

Apr 11, 2011

the below merge statements has outer join.

merge into merge_st t
using (select * from merge_st1) src
on (t.id=src.id(+))
when matched then update set name=src.name;

I need to convert oracle joins to ANSI joins. I have tried below

update (select t1.name as t1_name,t2.name as t2_name
from merge_st t1 lef outer join merge_st t2
on(t1.id=t2.id))
set t1_name=t2_name;

It statements shows error like cannot modify the non key preserved tables.I have cheked these table has contains whether primary key or not.there is no constraints for these tables.Our application, constaints handle in front end. so we cannot create any constraints in oracel database.how to convert oracle joins to ansi join?

View 4 Replies View Related

PL/SQL :: Are Truncate And Trunc SQL ISO ANSI Compliance

Jun 10, 2013

 which of the statements TRUNCATE and TRUNC are SQL ISO ANSI compliance ?is Truncate a function or a statement ?

View 3 Replies View Related

SQL & PL/SQL :: Dataset From Two Sets Of Tables Based On Condition

Nov 26, 2010

have two queries that will return same columns from two different set of tables ( column mapping has been taken care of). The return type is out ref cursor. (P_SUPPLY_REORDER )

Query 1-SO
-----------------------------------
select
so.SMO_NO,
so.SPLY_ORD_DT,
so.fk_CUST_ID as CUST_ID,
so.CUST_PO_NO,
so.ATTENTION_NAME,
[code].....

Query-2 Xcom
--------------------------------------
select
null as sMO_NO,
xso.created_date as SPLY_ORD_DT,
xso.fk_cust_id as cust_id,
cust.cust_po_no as cust_PO_NO
,(sta.SHIP_TO_ATTN_FIRST_NAME||''||sta.SHIP_TO_ATTN_LAST_NAME) as attention_name,
xsol.CARTONS_ORDERED as SPLY_ORD_QTY,
[code].......

Now the requirement is
One of four conditions are possible for each Supply Reorder Number:

. Both table queries return no records- Populate all the P_SUPPLY_REORDER output fields with nulls
. SUPPLY_ORDER returns a record, but XCOM_ORDER_HEADER returns no records
- Populate output fields with values from the join of SUPPLY_ORDER and SUPPLY_ORDER_LINE.
. SUPPLY_ORDER returns no records, but XCOM_ORDER_HEADER returns one record
- Populate output fields with values from the join of XCOM_ORDER_HEADER and XCOM_ORDER_LINES.
. SUPPLY_ORDER returns a record, and XCOM_ORDER_HEADER returns a record; find out the latest order by comapring max(SPLY_ORD_DT)
from SUPPLY_ORDER with max(CREATED_DATE) from XCOM_ORDER_HEADER.
- If the latest order is in SUPPLY_ORDER, then populate output fields with values from the join of SUPPLY_ORDER and SUPPLY_ORDER_LINE.
- If order dates are equal from both join results, then populate output fields with values from the join of SUPPLY_ORDER and SUPPLY_ORDER_LINE.
- If the latest order is in XCOM_ORDER_HEADER, then populate output fields with values from the join of XCOM_ORDER_HEADER and XCOM_ORDER_LINES.

Question is how can we switch over the queries to pull respective dataset based on these conditions ( checking that which table join is going to return a row and then based upon latest order if both tables return a row) and all this logic as part of single SQL statement that is returned as OUT Ref Cursor.

View 7 Replies View Related

Oracle Dataset In Visual Studio 2005

Jun 1, 2008

i'm newbie in oracle and visual studio 2005..i running a sql-query in visual studio 2005 with the oracle dataset..i want the data that displayed is in the date range and the parameter is set by user..

EXEC ('
SELECT DISTINCT
XNP_TIMER_VIOLATION.VIOLATION_TIME,

FROM
XNP_TIMER_VIOLATION, ...

WHERE
(DATEADD(hh, 8,XNP_TIMER_VIOLATION.VIOLATION_TIME) BETWEEN ? AND ?)',@FROM_DATE, @TO_DATE ) AT npcrpt ;

View 4 Replies View Related

SQL & PL/SQL :: Record Count Mismatch In Dataset And Query Executed

Oct 14, 2011

I am using an query to fetch the data from oracle DB and fill dataset using oledb dataadapter in ASP.net.When i run the same query in PL/SQL i am getting 14952 records,but when i am filling it to dataset i am getting only 13700 records.

View 2 Replies View Related

ODP.NET :: Updating Dataset / Datarow If Data Is Populated From Stored Procedure

Mar 11, 2013

I am using:

Oracle Database 11g Enterprise Edition Release 11.2.0.1.0
Microsoft Visual Studio 2010 : VB Express
Microsoft .NET Framework : Version 4.0.30319 RTMRel

When I populate dataset using select query and use OracleCommandBuilder and update dataadapter, data is saved in database.

But if I put same select in store procedure and use this to populate dataset then data is not updated in db.

I get this error

Update requires a valid UpdateCommand when passed DataRow collection with modified rows.

at da1.Update(ds1, "req") where I am going wrong.

Dim conn As New OracleConnection
        Dim da1 As OracleDataAdapter = New OracleDataAdapter
        Dim ds1 = New DataSet
        With conn
            If .State = ConnectionState.Open Then .Close()

[Code]....

View 2 Replies View Related

SQL & PL/SQL :: Normal Join And Outer Join

Oct 19, 2013

Lets say I have three tables t1 and t2 and t3.

SELECT * FROM T1;

Id
____
1
2
3
4

SELECT * FROM T2;

Id
____
1

SELECT * FROM T3;

Id
____
1

Now when data exists in T2 and T3, I want to return only the records in T1 that match the records in T2 and T3 which is basically a normal join

select t1.id from t1, t2,t3 where t1.id = t2.id and t1.id = t3.id

However when there are no records in T2 or T3, I want to return all records in T1 i.e 1,2,3,4

One way of doing that is using the not exists clause

select * from t1 where not exists ( select null from t2 where t2.Id != t1.id) and not exists ( select null from t3 where t1.Id != t3.id)

Is there a better way of doing this in sql ?

View 5 Replies View Related

Format Of Dates Goes Wrong

Jan 26, 2013

I have database jobs that upload the data in my applications.My problem is while copying the record of one application to another, the format of dates goes wrongFor example:

The date in one column is 01-JAN-1941 but in the other record while copying ot goes as 01-JAN-2041.

View 4 Replies View Related

SQL & PL/SQL :: How To Find Out Wrong Value From Table

Jan 13, 2011

I've written the code (see below) and after run I get an error:

ORA-06502: PL/SQL: numeric or value error: Bulk Bind: Truncated Bind

I don't know how to find out the wrong value from table. How to find it out?

DECLARE
TYPE rowids IS TABLE OF ROWID;
r1 rowids;
type t_varchar is table of varchar2(50);
n1 t_varchar ;

cursor c1 is select e.rowid rid,msisdn_displayed
from the_table
where contract_id is not null;
BEGIN
OPEN c1;
[code].........

View 3 Replies View Related

Datafile In Wrong Location

Jun 18, 2013

My production DB has a couple of datafiles that were created in the wrong place, plus they are tiny - 100mb each.  What is best way to get rid of them?

View 3 Replies View Related

SQL & PL/SQL :: Wrong Result For Query With Like And %?

Jul 21, 2012

I have a strange problem with query with like and %.

When I run this script:

ALTER SESSION SET NLS_SORT = 'BINARY_CI';
ALTER SESSION SET NLS_COMP = 'LINGUISTIC';
-- drop table test1;
CREATE TABLE TEST1(K1 NVARCHAR2(80));
INSERT INTO TEST1 VALUES ('gsdk');

[code]....

I get this:

K1
ŁFa
ła
Śab <- WRONG
Śrrrb <- WRONG
4 rows selected

When i change datatype in column to varchar2 this code work correct.

The execution plan:

PLAN_TABLE_OUTPUT
SQL_ID d3d64aupz4bb5, child number 2
select * from TEST1 where k1 like N'Ł%'
Plan hash value: 4122059633
Id Operation Name Rows Bytes Cost (%CPU) Time
0 SELECT STATEMENT 2 (100)
* 1 TABLE ACCESS FULL TEST1 1 82 2 (0) 00:00:01

[code]....

View 7 Replies View Related

Sysdate Showing Wrong Timezone?

May 24, 2012

I have one issue My server is in france and it is in french timezone but when I query for sysdate it returns US time.

In '/etc/sysconfig/clock/'
Zone= europe/paris
UTC= true

echo $TZ variable is returning nothing.

sysdate = us time
systimestamp= us time
current_timestamp = french time
current_date = french time
dbtimezone= europe/warsove, sessiontimezone=+2.00( which is also europe timezone offset)
tz_offset(dbtimezone)=+2.00, tz_offset(sessiontimezone)= +2.00 i.e europe
os timezone= europe/paris.

This command "./emctl config agent getTZ" is also returning timezone as europe/paris

Also in "emd.properties" file "agentTZRegion" parameter is set to europe/paris

Oracle version= 11.2.0

Now I don't understand why this sysdate and systimestamp is returning "US time zone" while everything else is returning french time zone.

View 9 Replies View Related

SQL & PL/SQL :: Export Data To CSV - Wrong Diacritics?

Jun 20, 2013

I would like to need export data to csv file, but I got problems with diacritics.The simply PLSQL looks like:

declare
f utl_file.file_type;
cursor c1 is Select ACTIVITY_SUB_TYPE
from the_table;
begin

[code]...

After run of plsql the record in the csv file looks like "Vypršanie skuš.lehoty kontakt"So there is a problem with that diacritics.

View 7 Replies View Related

SQL & PL/SQL :: PL-00382 Expression Is Of Wrong Type

Apr 12, 2013

I am using pipelined functions. I've written a few with no problem this one seems to be giving an error when I am using techniques that appear very similar to ones that work.

I am doing this all in a package;

The type definition is;

TYPE SUSPECT_LINKAGES_FAC_RECORD IS RECORD
(
PATIENT_ID TUMOR.TUMOR_PATIENT_ID%TYPE,
CENTRAL_SEQ TUMOR.TUMOR_CENTRAL_SEQ%TYPE,
MP_REVIEW_FLAG NUMBER(1),
FACILITY_FLAG NUMBER
);

The variable definition is;

OUT_REC SUSPECT_LINKAGES_FAC_RECORD;

The line with the error is;

PIPE ROW(OUT_REC);

This is the entire function;

FUNCTION GET_SUSPECT_LINKAGE_FAC_FLAGS RETURN SUSPECT_LINKAGES_TABLE PIPELINED AS
CURSOR CURS_SUSPECT_LINKAGES IS
SELECT * FROM TABLE(TUMOR_UTILITIES.GET_SUSPECT_LINKAGE_FLAGS())
order by 1,2,3 DESC;
TEMP_REC SUSPECT_LINKAGES_RECORD;
MATCH_COUNT NUMBER;
OUT_REC SUSPECT_LINKAGES_FAC_RECORD;

[code].....

I get "PL-00382 expression is of wrong type" on both pipe row (out_rec); lines.

View 1 Replies View Related

SQL & PL/SQL :: PLS-00382 - Expression Is Of Wrong Type

Mar 19, 2013

i got this error 'PLS-00382: expression is of wrong type'
--declaration

l_recipe_detail_tbl apps.gmd_recipe_detail.recipe_detail_tbl;
begin
ln_recipe_id := NULL;

[Code].....

View 1 Replies View Related

Globalization :: Wrong Result For Query With Like And %?

Jun 28, 2012

I have a strange problem with query with like and %.

When I run this script:

ALTER SESSION SET NLS_SORT = 'BINARY_CI';
ALTER SESSION SET NLS_COMP = 'LINGUISTIC';
-- SELECT * FROM NLS_SESSION_PARAMETERS;
-- drop table test1;
CREATE TABLE TEST1(K1 NVARCHAR2(80));

[code]....

When i change datatype to varchar2 this code work correct.

The execution plan:

PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SQL_ID d3d64aupz4bb5, child number 2
-------------------------------------
select * from TEST1 where k1 like N'Ł%'

[code]....

Note - dynamic sampling used for this statement (level=2)

View 2 Replies View Related

Application Express :: Layout OK In 4.1 All Wrong In 4.2?

Nov 16, 2012

I have a show/hide region of type HTML with empty region source which I use to show/hide a subregion (tabular form)because I don't like the layout of a show/hide region when it is shownthis worked without a problem in APEX 4.1.1

however in 4.2 the tabular form is just a couple of pixels widehave been playing around with grids but can't seem to find the right combination of settingsthe layout is messed up

I put the app on apex.oracle.com :
workspace : xonixrs
login/password : demo/demo

View 2 Replies View Related

DBMS_JOB Running At Wrong Time

Jan 7, 2013

We have a bunch of jobs scheduled using DBMS_JOB (yes, I know I should be using DBMS_SCHEDULER, but we haven't migrated there yet). We are running Oracle 11.2.0.3 on Windows Server 2003 x64.

For example, we have a job that is supposed to run every Wednesday at 20:00. The Interval we have set up is "NEXT_ DAY (TRUNC(SYSDATE), 'WEDNESDAY')+20/24". This has been working as intended. Today (Monday), however, the job kicked off at 11:52. It was the wrong day and the wrong time.

I don't see anything weird in my alert log. Where else should I check to figure out why this job ran today?

JOB     LAST_DATE     LAST_SEC     NEXT_DATE     NEXT_SEC     INTERVAL     WHAT
293     1/7/2013 11:52:46 AM     11:52:46     1/9/2013 8:00:00 PM     20:00:00     NEXT_DAY(TRUNC(SYSDATE), 'WEDNESDAY')+20/24     ACQUISITIONS.WORKLOAD_STATUS_UPDATE_NOTIF;

View 5 Replies View Related

Wrong Number Format Display Using DBLink

Jan 7, 2013

I have an issue trying to execute some queries using a dblink. When i run any query with numeric fields only display 4 digit and int the source database the fields have 5 digit. The dblink work between ans MSSQL database to an Oracle Database

Example:
MSSQL
select cardnumber from card
cardnumber
19121
19122

Oracle (with dblink)
select cardnumber from card@dblink1
cardnumber
1912
1912

View 1 Replies View Related

ORA-06553 / PLS-306 / Wrong Number Of Types Of Arguments

Apr 9, 2012

I'm trying to call a custom made PL/SQL function in a SQL query. I want to supply the values of the parameters during the query. I can call the function if I "hard code" the parameter values, but when I try to supply them I get the ORA-06553 error.

This call works:

select pkg_tm_import_util.wb_screen_hr_refresh_func('','','','','','','','','','','','') from dual

However, this does not, but should be the same as the call that works:

select pkg_tm_import_util.wb_screen_hr_refresh_func(
''''','||
''''','||
''''','||
''''','||
''''','||
''''','||
''''','||

[code]....

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved