Sql Question #3

530 views

Published on

How to approach solving a SQL problem?

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
530
On SlideShare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Sql Question #3

  1. 1. SQL Question #3 When I run this code (table OPJEUL.MCD_COSTS_9C_ACCTS_05 does not exist) CREATE TABLE OPJEUL.MCD_COSTS_9C_ACCTS_05 AS SELECT * FROM OPJEUL.COSTS_9C_ACCTS_05 I get an Ora-01847, day must be between 1 and end of the month. There are 2 dates in the input view and all are valid. I wrote a PL/SQL proc to kick out any invalid dates and none were rejected. Also, looking at the dates, none of them seem wrong. If I create an empty table and do an Insert, the same error occurs. However, if I change from a table to a view CREATE or replace view OPJEUL.COSTS_9C_ACCTS_05_V AS SELECT * FROM OPJEUL.COSTS_9C_ACCTS_05 the view is created without any problems.
  2. 2. How to debug problem? <ul><li>Do you have Bad Dates in Table? </li></ul><ul><li>Visually see bad dates. </li></ul><ul><li>Write a procedure to check for bad dates. </li></ul><ul><li>Create an empty table and do select Inserts. </li></ul><ul><li>Create table again without date fields. </li></ul><ul><li>Check On-line source for help. </li></ul><ul><li>Create SR with Oracle Support. </li></ul><ul><li>See if Teacher can help solved problem. </li></ul>
  3. 3. One Approach! <ul><li>Were trying to find the bad records or record? </li></ul><ul><li>As we can see other methods have failed in this case. </li></ul><ul><li>So, I would recommend using TOAD Export to see if we can find problems. </li></ul><ul><li>Use the empty table from #4, to see if we can populate with Export. </li></ul>
  4. 4. TOAD Schema Browser Use Feature - Export data as Insert Statements
  5. 5. Sample Export <ul><li>INSERT INTO LOAD ( LOAD_ID, STEP_NU, AMT_SRC_ID, LPPY_ID, LOCUS_ID, ENTITY_ID, LGL_ENTITY_ID, </li></ul><ul><li>RPT_LN_ID, ACCT_ID, TRAN_TYPE_ID, VIEW_TYPE_ID, YTD_AMT ) VALUES ( </li></ul><ul><li>2131438, 2, 0, 4130, 0, 13167, 13745, 22444, 53871, 1, 1, -10892); </li></ul><ul><li>INSERT INTO LOAD ( LOAD_ID, STEP_NU, AMT_SRC_ID, LPPY_ID, LOCUS_ID, ENTITY_ID, LGL_ENTITY_ID, </li></ul><ul><li>RPT_LN_ID, ACCT_ID, TRAN_TYPE_ID, VIEW_TYPE_ID, YTD_AMT ) VALUES ( </li></ul><ul><li>2131438, 2, 0, 4130, 0, 13167, 13745, 22444, 53872, 1, 1, 10892); </li></ul><ul><li>INSERT INTO LOAD ( LOAD_ID, STEP_NU, AMT_SRC_ID, LPPY_ID, LOCUS_ID, ENTITY_ID, LGL_ENTITY_ID, </li></ul><ul><li>RPT_LN_ID, ACCT_ID, TRAN_TYPE_ID, VIEW_TYPE_ID, YTD_AMT ) VALUES ( </li></ul><ul><li>2131438, 2, 0, 4130, 0, 13167, 13745, 25998, 209177, 1, 1, -2172); </li></ul><ul><li>INSERT INTO LOAD ( LOAD_ID, STEP_NU, AMT_SRC_ID, LPPY_ID, LOCUS_ID, ENTITY_ID, LGL_ENTITY_ID, </li></ul><ul><li>RPT_LN_ID, ACCT_ID, TRAN_TYPE_ID, VIEW_TYPE_ID, YTD_AMT ) VALUES ( </li></ul><ul><li>2131438, 2, 0, 4130, 0, 13218, 13218, 26393, 203660, 1, 0, -0.001); </li></ul><ul><li>INSERT INTO LOAD ( LOAD_ID, STEP_NU, AMT_SRC_ID, LPPY_ID, LOCUS_ID, ENTITY_ID, LGL_ENTITY_ID, </li></ul><ul><li>RPT_LN_ID, ACCT_ID, TRAN_TYPE_ID, VIEW_TYPE_ID, YTD_AMT ) VALUES ( </li></ul><ul><li>2131438, 2, 0, 4130, 0, 13218, 13218, 26394, 203663, 1, 0, -0.0024); </li></ul><ul><li>INSERT INTO LOAD ( LOAD_ID, STEP_NU, AMT_SRC_ID, LPPY_ID, LOCUS_ID, ENTITY_ID, LGL_ENTITY_ID, </li></ul><ul><li>RPT_LN_ID, ACCT_ID, TRAN_TYPE_ID, VIEW_TYPE_ID, YTD_AMT ) VALUES ( </li></ul><ul><li>2131438, 2, 0, 4130, 0, 13218, 13218, 26395, 203669, 1, 0, 0.8048); </li></ul><ul><li>commit; </li></ul>
  6. 6. SQL*Plus <ul><li>We need modify to target source for empty table. </li></ul><ul><li>Look for bad records that don’t insert into empty table. </li></ul><ul><li>SQL> @I:Trainingload_test </li></ul>

×