Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Simple insert into table hanging

AParmNov 10 2016 — edited Nov 11 2016

Hi there,

I have a query that joins 2 tables, 1 table has 2 million records and other 1 million records, the query returns 1 record in less than 1 second, both the 2 tables being joined are accessed across a database link, despite the query running in less than a second, if I do a simple insert using the query it just hangs, and I don't understand why. The table is not locked, I have tried dropping the table before the insert and recreating it, to ensure there are no locks.

If I look at the wait events all  I a can see this

I am running 12c on Windows, the database link is to database in another pluggable database in the same container.

SQL*Net message from dblink

This post has been answered by AParm on Nov 11 2016
Jump to Answer

Comments

KarK
Answer

Your query has syntax error apart from the logic:

Try the below:

select * from

(

select dept,sales,

--activemonth,

rtrim(to_char(activemonth,'Month')) as currentM,

length(rtrim(to_char(activemonth,'Month'))) as length1

from dateorder

)

pivot

(

  sum(sales) as total

  for currentM in ('March')

);

OUTPUT:

DEPT           LENGTH1 'March'_TOTAL

----------- ---------- -------------

Stationery           7

Books                8

Toys                 7

Toys                 8

Toys                 3

Stationery           4

China                7

Books                5         82.34

Books                7

Toys                 4

China                3

DEPT           LENGTH1 'March'_TOTAL

----------- ---------- -------------

Stationery           8

Stationery           3

13 rows selected.

Marked as Answer by user8167598 · Sep 27 2020
Partha Sarathy S

Try this.

select * from (

select dept,sales,

--activemonth,

rtrim(to_char(activemonth,'Month')) as currentM,

length(rtrim(to_char(activemonth,'Month'))) as length1

from dateorder)

pivot

(

  sum(sales) as total

  for currentM in ('March')

);


Don't know what you are trying to achieve, but it would be better to do like this.

select DEPT,

       LENGTH1,

       NVL("'March'_TOTAL",0)

from (

select dept,sales,

--activemonth,

rtrim(to_char(activemonth,'Month')) as currentM,

length(rtrim(to_char(activemonth,'Month'))) as length1

from dateorder)

pivot

(

  sum(sales) as total

  for currentM in ('March')

);

AnnEdmund

You mean this?

SELECT dept,

       SUM(DECODE(currentM,'March',sales)) Total,

       currentM

FROM(SELECT dept,

       sales,

       to_char(activemonth,'fmMonth') AS currentM

FROM DATEORDER)

WHERE currentM = 'March'

GROUP BY dept,currentM;


OUTPUT:-

DEPT         TOTAL CURRENTM

----------- ---------- ---------

Books        82.34 March
AnnEdmund

Like this with PIVOT? If this is not your requirement then tell your requirement and expected output

SELECT *

FROM(SELECT dept,

       sales,

       to_char(activemonth,'fmMonth') AS currentM

FROM DATEORDER)

PIVOT(SUM(sales) Total FOR currentM IN('March'))


OUTPUT:-

-------

DEPT    'March'_TOTAL

----------- -------------

Stationery

China

Books           82.34

Toys

user8167598

Thanks ! I should have gone to spec savers !

1 - 5
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Dec 9 2016
Added on Nov 10 2016
40 comments
24,992 views