Quantcast
Channel: Toad for Oracle Forum - Recent Threads
Viewing all 4385 articles
Browse latest View live

Pivoting an SQL script that already has pivot

$
0
0

Greetings!

I currently have a script with pivot function in it. Attached you will find a JPEG file of my script (for ease of reading) and two files that shows current result of the script and desired result.

My script groups result based on nationalities (UAE & Non-UAE). I would like to further group it by gender. The 'Desired.JPEG' shows how I would like to display my result. Will I be able to further pivot my result to break down the nationality group by gender? Below you will find my script.

Script

.............................................................................................................................................................................................................................................................................................

select *

from

(
     select Ou.SGBSTDN_PIDM PIDM, decode(substr(Ou.SGBSTDN_CAMP_CODE,3,1),'M','M','W','W') Gender, STVCOLL_DESC College,
     STVMAJR_DESC Major,
     case
     when STVNATN_NATION = 'United Arab Emirates' then 'UAE'
     else 'Non_UAE'
     end as UAE_Non_UAE
     

    from SPRIDEN, SGBSTDN Ou, STVCOLL, STVMAJR, GOBINTL, STVNATN

   where SPRIDEN_PIDM = Ou.SGBSTDN_PIDM
   and SPRIDEN_CHANGE_IND is null
   and Ou.SGBSTDN_STST_CODE in ('AS','AW','CW','DA','DW','OW','PA','RA','SP','WN','XP','XT')
   and Ou.SGBSTDN_TERM_CODE_EFF = ( select max(Inn.SGBSTDN_TERM_CODE_EFF)
                                                                                 from SGBSTDN Inn
                                                                                 where Inn.SGBSTDN_PIDM = Ou.SGBSTDN_PIDM
                                                                                 and Inn.SGBSTDN_TERM_CODE_EFF <= '201610'
                                                                              )
   and (Ou.SGBSTDN_COLL_CODE_1 = '05' or Ou.SGBSTDN_MAJR_CODE_1 in ('H094', 'NURS', 'NURB'))
   and Ou.SGBSTDN_COLL_CODE_1 = STVCOLL_CODE
   and Ou.SGBSTDN_MAJR_CODE_1 = STVMAJR_CODE
   and Ou.SGBSTDN_PIDM = GOBINTL_PIDM(+)
   and GOBINTL_NATN_CODE_LEGAL = STVNATN_CODE(+)
)

pivot

(
count (PIDM)--, count (Gender) as MW
for UAE_Non_UAE in ('UAE' as UAE, 'Non_UAE' as Non_UAE)
)

order by College, Major
;

.............................................................................................................................................................................................................................................................................................

Result

.............................................................................................................................................................................................................................................................................................

GENDERCOLLEGEMAJORUAENON_UAE
MHealth SciencesClinical Nutrition & Dietetics02
WHealth SciencesClinical Nutrition & Dietetics22209
MHealth SciencesEnvironmental Health212
WHealth SciencesEnvironmental Health2423
MHealth SciencesHealth Services Administration15
WHealth SciencesHealth Services Administration645
MHealth SciencesMedical Diagnostic Imag - Bdg06
WHealth SciencesMedical Diagnostic Imag - Bdg03

.............................................................................................................................................................................................................................................................................................

Desired

.............................................................................................................................................................................................................................................................................................

UAENon_UAE
COLLEGEMAJORMWMW
Health SciencesClinical Nutrition & Dietetics0222209
Health SciencesEnvironmental Health2241223
Health SciencesHealth Services Administration16545
Health SciencesMedical Diagnostic Imag - Bdg0063

.............................................................................................................................................................................................................................................................................................


RE: Pivoting an SQL script that already has pivot

$
0
0

Just put your entire query into a subquery, and then add a pivot to sort out the UAE/NonUAE Male/Female

So...

Select * from

(<your entire query so far, including the "select * from", and the pivot, but without the order by and without the semicolon>)

then, for the "2nd" pivot, add

Pivot (<whatever>)

 

 

RE: Pivoting an SQL script that already has pivot

$
0
0

Thanks John for your prompt reply.

I followed your suggestion but it did not work. I tried different variations of pivot options. It seems like I am doing something wrong. The modified code is as follows:

select     PIDM, Gender, College, Major--, UAE_Non_UAE
from       (
                 select     *
                 from        (
                                    select     Ou.SGBSTDN_PIDM PIDM, decode(substr(Ou.SGBSTDN_CAMP_CODE,3,1),'M','M','W','W') Gender, STVCOLL_DESC College,
                                                     STVMAJR_DESC Major,
                                    case
                                    when       STVNATN_NATION = 'United Arab Emirates' then 'UAE'
                                    else        'Non_UAE'
                                    end as   UAE_Non_UAE
                                    from       SPRIDEN, SGBSTDN Ou, STVCOLL, STVMAJR, GOBINTL, STVNATN
                                    where    SPRIDEN_PIDM = Ou.SGBSTDN_PIDM
                                    and        SPRIDEN_CHANGE_IND is null
                                    and        Ou.SGBSTDN_STST_CODE in ('AS','AW','CW','DA','DW','OW','PA','RA','SP','WN','XP','XT')
                                    and        Ou.SGBSTDN_TERM_CODE_EFF = ( select      max(Inn.SGBSTDN_TERM_CODE_EFF)
                                                                                                                         from        SGBSTDN Inn
                                                                                                                         where     Inn.SGBSTDN_PIDM = Ou.SGBSTDN_PIDM
                                                                                                                         and Inn.SGBSTDN_TERM_CODE_EFF <= '201610'
                                                                                                                       )
                                    and        (Ou.SGBSTDN_COLL_CODE_1 = '05' or Ou.SGBSTDN_MAJR_CODE_1 in ('H094', 'NURS', 'NURB'))
                                    and        Ou.SGBSTDN_COLL_CODE_1 = STVCOLL_CODE
                                    and        Ou.SGBSTDN_MAJR_CODE_1 = STVMAJR_CODE
                                    and        Ou.SGBSTDN_PIDM = GOBINTL_PIDM(+)
                                    and        GOBINTL_NATN_CODE_LEGAL = STVNATN_CODE(+)
                                  )
                 pivot        (
                                   count (PIDM)--, count (Gender) as MW
                                   for UAE_Non_UAE in ('UAE' as UAE, 'Non_UAE' as Non_UAE)
                                  )
                  )
pivot         (
                   Count (Gender) --Count (PIDM),
                    --for UAE_Non_UAE in ('UAE' as UAE, 'Non_UAE' as Non_UAE)
                   for Gender in ('M' as M, 'W' as W)
                  )
order by  College, Major
;

RE: Pivoting an SQL script that already has pivot

$
0
0

Hi Jollydoe,

  "It didn't work" is a little vague.   Was there an error?  If so, what was it?   Or did the query run OK but not produce the result you were looking for?    Please be more precise.  

  Not having your original tables, I decided to just make a table with the data of your original result set.     So I made a table called "JOLLY" with columns GENDER, COLLEGE, MAJOR, UAE, and NON_UAE and filled it with those 8 rows.

  There may be a way to get the result that you are looking for with PIVOT, but to be honest I haven't used PIVOT very much, so I decided to tackle this with SUM and DECODE.  I was able to get your desired result with this query:

select college, major,
       sum(decode(gender, 'M', UAE, 0)) as UAE_M,
       sum(decode(gender, 'W', UAE, 0)) as UAE_W,
       sum(decode(gender, 'M', NON_UAE, 0)) as NON_UAE_M,
       sum(decode(gender, 'W', NON_UAE, 0)) as NON_UAE_W
from jolly      
group by college, major            

and one way you could turn your query into mine is

with JOLLY AS
     (<your prior query here, with pivot but without order by>)
select college, major,
       sum(decode(gender, 'M', UAE, 0)) as UAE_M,
       sum(decode(gender, 'W', UAE, 0)) as UAE_W,
       sum(decode(gender, 'M', NON_UAE, 0)) as NON_UAE_M,
       sum(decode(gender, 'W', NON_UAE, 0)) as NON_UAE_W
from JOLLY      
group by college, major              

Create new revision using TFO with GIT?

$
0
0

For Toad for Oracle version 12.9.0.71 ...

Is there anyway to force a new revision for an Oracle object when using GIT with Toad for Oracle? I have installed GIT and created the base or initial repository/revision but I am having trouble getting TFO / Team Coding to manage the Oracle objects. After the initial revision has been created if you edit the object using the Schema browser it does not check out or attempt to manage the object. If I had an object to force the changed code into GIT that would help resolve this issue.

RE: Pivoting an SQL script that already has pivot

$
0
0

Hi John,

Sorry about the vagueness. I will not get into error detail for two reasons – your alternate solution worked for me & since you have not used PIVOT much, I will not bother you with PIVOT error issues. If you still want to know the error, please let me know. I will gladly share it with you.

Thank you for providing an alternate solution. Going forward, I will use this solution whenever I need to perform double pivot functions.

RE: error when opening session browser

$
0
0

Go into your User Files folder (Probably something like  C:\Documents and Settings\<windows username>\Application Data\Quest Software\Toad for Oracle\10.1\User Files).    Then go down one more folder into the GUISettings folder.

Delete every file in the GUISettings folder that matches the pattern *SessionBrowser*.*

That ought to do it.   These files just contain saved settings for the Session Browser.  Deleting these files will restore the Session Browser to its default state.

error when opening session browser

$
0
0

Hi,

I am getting "Stream read error" with below exception details when tried to open session browser in Toad

Exception:

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

  2.1

Date          : Wed, 14 Sep 2016 02:38:04 -0400

  2.2

Address       : 0043B1B1

  2.3

Module Name   : Toad.exe - (Toad for Oracle)

  2.4

Module Version: 10.1.1.8

  2.5

Type          : EReadError

  2.6

Message       : Stream read error.

  2.7

ID            : 14F3

  2.8

Count         : 1

  2.9

Status        : New

  2.10

Note         :

can you please suggest me the steps to resolve this issue.

Thanks,

Vijay


RE: TortoiseHg Workbench

$
0
0
Hi Becky,
 
TortoiseHg is for the Mercurial version control system, which is supported in the soon to be released Toad 12.10 (the next few weeks).  TortoiseHg Workbench should install the Mercurial command-line client, which Toad will use to do all its work.  We’ve made a lot of changes to Source Control and Team Coding since Toad 10.1.  I would definitely recommend upgrading your version of Toad if all possible – your workflow in Toad will be much easier.
 
-John
 

RE: TortoiseHg Workbench

TortoiseHg Workbench

$
0
0

Hello!

I would like to use Source Control within Toad.  What version if any uses TortoiseHG Workbench?  I am using Toad 10.1.1.8.  I have seen posts about Tortoise SVN.  Is this the same thing?

Thanks so much,

Becky

RE: formatter setting for alignments

formatter setting for alignments

$
0
0

Please tell me how can I get the formatter to take this:

     AND D.EFFDT = (SELECT MAX ( D_ED.EFFDT )
                      FROM PS_CF_ATTRIB_TBL D_ED
                     WHERE D.SETID = D_ED.SETID
                       AND D.CHARTFIELD_VALUE = D_ED.CHARTFIELD_VALUE
                       AND D.CF_ATTRIBUTE = 'STATEFUND'
                       AND D_ED.EFFDT <= SYSDATE)

and format as this:

     AND D.EFFDT = (SELECT MAX ( D_ED.EFFDT )
                      FROM PS_CF_ATTRIB_TBL D_ED
                     WHERE D.SETID            = D_ED.SETID
                       AND D.CHARTFIELD_VALUE = D_ED.CHARTFIELD_VALUE
                       AND D.CF_ATTRIBUTE     = 'STATEFUND'
                       AND D_ED.EFFDT         <= SYSDATE )
                   
                                                                                             ^  I want these to line up


I've been setting "Alignments" at either fixed or dynamic with various offset values and 'space between' values but it doesn't seem to do anything.

How to get the most out of this forum – Best practices for what information to include

$
0
0

The better a problem is described, the better the assistance tends to be.
In order to better assist with your issue at hand, please include the following information in your initial post.

-          Product, Version, and relevant environment details.

-          Include a screenshot of the problem

-          Describe the problem fully. What result was expected?

-          Can the issue be created on demand or is it intermittent?

-          If the problem can be generated faithfully, what are the exact steps to recreate the problem?

-          Any other pertinent information (see below)


How to create Support Bundles

The support bundle window provides information about several aspects of your Oracle and Toad setups. In addition, the Support Bundle lets you easily report problems to our peer-to-peer mailing lists or directly to Support.
If Toad itself fails, the Error dialog box displays. This type of an error creates a log, saved as toad.elf. This Eureka LogFile (.elf) contains both the application information and the callstack of the error created, and can be very helpful to Support in solving issues you are having with Toad.

To create a support bundle:

Select Help | Support Bundle.

Review the following for additional information:

Email Dell Support

This opens the "Email Dell Support" window with instructions and links to contact Support, and to open a new case or service request.

Dell Web Support

This opens Dell Software's award-winning Support portal in your default browser, with access to Licensing Assistance, the searchable Knowledge Base, product downloads and more.

Attach TOAD.INI (or SQL Tuning Support details) to emails

If selected, this attaches the details to any email sent through the support bundle, whether it is to the peer-to-peer Toad list or to Support.

 *Note: Please refrain from including private data in your posts. Be as thorough as you can with the provided info. We will reply to you as quick as possible. We are glad to assist you. 

Latest Release Information: 

This announcement includes information on our latest releases, links to our downloads and documentation and overview of new features.  This way you can stay as informed as possible: 

-          "What’s New" Section:

-          http://documents.software.dell.com/toad-for-oracle/12.9/release-notes/new-features

-           

-          Link to Download & Documentation:

-          https://support.software.dell.com/toad-for-oracle/12.9

-           

-          Link to Trial:

-          https://software.dell.com/products/toad-for-oracle/software-downloads.aspx

-           

-          Overview of new feature(s) (with link to the release notes)

-          http://documents.software.dell.com/toad-for-oracle/12.9/release-notes/new-features

-          http://documents.software.dell.com/toad-for-oracle/12.9/release-notes/  

 

Top 5 Knowledge Base Articles:

On this post, you can find our top trending knowledge articles that other customers are inquiring about and popular solutions.

This month’s Top Knowledge Base Articles

  1. Video - How to make a database connection using Direct, TNS and LDAP in Toad for Oracle (205157) https://support.software.dell.com/toad-for-oracle/kb/205157
  2. VIDEO - How to install Toad for Oracle using the new Web Installer (178737) https://support.software.dell.com/toad-for-oracle/kb/178737
  3. Video - How to use the SQL Tracker tool? (193849) https://support.software.dell.com/toad-for-oracle/kb/193849
  4. VIDEO - Get more out of your Toad for Oracle investment with free training. (145507) https://support.software.dell.com/toad-for-oracle/kb/145507
  5. Video: Need help to download Toad for Oracle from the Support Portal. (108974) https://support.software.dell.com/toad-for-oracle/kb/108974

 Feel free to browse them. Remember to sign in to your account to view.

Explain plan bug

$
0
0

Toad 12.9.0.71 (but saw this problem before as well).

  1. Start query (F9) in editor (no selection at all, sql determined with ";"
  2. while SQL is running (sometimes saw that even SQL finished), I click on the plan button
  3. Somehow toad select first word and report an error

  • from that moment whenever I try to get plan-error is the same
  • then I edited the query and put all in one line and "Explain plan" works again

but couldn't reproduce this bug all the time.

Bug is present on 11 and 12 databases so I think it is something related to "internal" Toad parsing and manipulating with SQL text.

Brg

Damir


RE: copy schema and data into new schema in a different existing db instance

$
0
0

Can this be done in script (instead of navigating),

if I want to run it as a part of big script in the task scheduler?

RE: Explain plan bug

$
0
0

If you have part of a SQL statement selected, and you do an explain plan, Toad will attempt to run the explain plan just on the selected portion.   This is so you can run it on a subquery.   Your best bet to run it on an entire query is to include semicolons, so Toad can best determine where the query begins and ends.  

RE: copy schema and data into new schema in a different existing db instance

$
0
0

Parag121 - you can use Toad's automation designer to

  generate a schema script

  run it in the target schema

  Do a "copy table data" action after that.

But it would probably be faster to do all of this in one step with a Data Pump Import action.    If you make a database link from the target database to the source database, datapump can pull the source schema through the DB Link and import into the target database all in one motion.   The database link is chosen on the "Params" tab of Toad's datapump import window.

copy schema and data into new schema in a different existing db instance

$
0
0
Hi -

From an existing schema, what is a quick way to create the same schema with a different name in a different database instance?  And also copy the data from the existing schema into the new schema?

Please advise.  Thanks, in advance.

RE: Explain plan bug

$
0
0

John,

Maybe it was no so obvious, but repeating:
>Somehow toad select first word and report an error

This means mine cursor was at the begin of the line and nothing was selected.

Toad did higlight (only word "select") and then shows an error. After that i can repeat run many times, but whenever I click on Explain plan, toad highlight "select" and reports an error.

On second picture you see that I have edite query (lines removed) and then Explain plan runs normally.

Viewing all 4385 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>