Sei sulla pagina 1di 5

SELECT COUNT(*) FROM DBC.Tables WHERE Databasename = 'DATABASE_NAME' AND Tablename = 'TABLE_NAME' HAVING COUNT(*) > 0; .

IF ERRORCODE <> 0 THEN .QUIT 10; .IF ACTIVITYCOUNT = 1 THEN .GOTO ACT_1; .IF ACTIVITYCOUNT = 0 THEN .GOTO ACT_2; .LABEL DROP_TAB; action 1 sql; .LABEL CT_TAB; action 2 sql; ----------------------------------------------------------------------DELETE FROM Million_Dollar_Customer ALL; .IF ERRORCODE = 0 THEN .GOTO TableOK CREATE TABLE Million_Dollar_Customer (Account_Number INTEGER ,Customer_Last_Name VARCHAR(20) ,Customer_First_Name VARCHAR(15) ,Balance_Current DECIMAL(9,2)); .LABEL TableOK INSERT INTO Million_Dollar_Customer SELECT A.Account_Number ,C.Last_Name ,C.First_Name ,A.Balance_Current FROM Accounts A INNER JOIN Account_Customer AC INNER JOIN Customer C ON C.Customer_Number = AC.Customer_Number ON A.Account_Number = AC.Account_Number WHERE A.Balance_Current GT 1000000; .IF ACTIVITYCOUNT > 0 THEN .GOTO Continue .QUIT .LABEL Continue ------------------------------------------------------------------------BTEQ Return codes and Error codes BTEQ Return Codes: Bteq return codes are the two digit values that BTEQ returns to the client opera ting system as a result of any error code occured in BTEQ session. Possible BTEQ return codes are as given below Return Code Description 00 Job completed with no errors. 02 User alert to log on to the Teradata Database. 04 Warning error. 08 User error. 12 Severe internal error

The return code is decided by the Error messages that BTEQ receives from the Ter adata database. Different Teradata database error codes are assigned a specific return code value. The below table will give what different return codes are returned by BTEQ for d ifferent Error codes it receives from Teradata database. For an Example : If you issue a SQL statement in BTEQ session to create a table which is alrady there, then Teradata database will return an error code of 3803 to the BTEQ session and in turn in BTEQ will send a return code of 04 to the cli ent operating system where you have intiated the BTEQ session. Return Code = 04 ( BTEQ returns a return code of 04 for the following Teradata e rror codes ) 2580 - Mload not active on table %TVMID. 2667 - Statistics cannot be collected on an empty table. 3534 - Index already exists. 3666 - This view has too many columns to store or retrieve comments. 3737 - Name is longer than 30 characters. 3747- No start-up string defined for this user. 3803 - Table %VSTR already exists. 3804 - View %VSTR already exists. 3805 - Macro %VSTR already exists. Return Code = 08 ( BTEQ returns a return code of 04 for the following Teradata e rror codes ) CLI0530 -Character set name or code unknown. 2123- A segment could not be read successfully. 2538 -A disk read error occurred in the tables area. 2541- End of hash code range reached. 2632- All AMPs own sessions for this Fast/MultiLoad 2639 - Too many simultaneous transactions. 2641 %DBID.%TVMID was restructured. Resubmit. 2644 No more room in database %DBID. 2654 Operation not allowed: %DBID.%TVMID is being restored. 2805 Maximum row length exceeded in %TVMID. 2809 Invalid recovery sequence detected. 2815 Apparent invalid restart of a restore. 2818 Invalid lock to dump table without after image journaling. 2825 No record of the last request was found after Teradata Database restart. 2826 Request completed but all output was lost due to Teradata Database restart. 2827 Request was aborted by user or due to statement error. 2828 Request was rolled back during system recovery. 2830 Unique secondary index must be dropped before restoring table. 2835 A unique index has been invalidated. Resubmit request. 2837 Table being fast loaded; no data dumped. 2838 Table is unhashed; no data dumped. 2840 Data rows discarded due to inconsistent hash codes. 2843 No more room in data base. 2866 Table was recovery aborted; no data dumped. 2868 This permanent journal table is damaged; no data dumped. 2920 Delete journal and AMP down without dual. 2921 No saved subtable for journal %DBID.%TVMID. 2926 No more room in %DBID.%TVMID. 3001 Session is already logged on. 3111 The dispatcher has timed out the transaction. 3116 Response buffer size is insufficient to hold one record. 3119 Continue request submitted but no response to return. 3120 The request is aborted because of a Teradata Database recovery.

3523 %FSTR does not have %VSTR access to %DBID.%TVMID. 3524 %FSTR does not have %VSTR access to data base %DBID. 3566 Data base does not have a PERMANENT journal. 3596 RESTORE Teradata Database invalid if table, view or macro exists outside of Teradata Database. 3598 Concurrent change conflict on data base; try again. 3603 Concurrent change conflict on table; try again. 3613 Dump/restore, no hashed nonfallback tables found. 3656 Journal table specified no longer exists. 3658 ROLLBACK/ROLLFORWARD table specifications are invalid. 3705 Teradata SQL request is longer than the Simulator maximum. 3802 Database %VSTR does not exist. 3807 Table/view %VSTR does not exist. 3824 Macro %VSTR does not exist. 3873 %VSTR is not a journal table. 3877 NO FALLBACK specified and the table is FALLBACK. 3897 Request aborted due to Teradata Database restart. Resubmit. 3916 Requested information not in dictionary. 5495 Stored Procedure %VSTR does not exist. Return Code = 12 ( BTEQ returns a return code of 04 for the following Teradata e rror codes ) CLI0001 Parameter list invalid or missing. CLI0002 Invalid number of parameters received. CLI0003 Error validating HSIRCB. CLI0004 Error validating HSICB. CLI0005 Error validating HSISPB. CLI0006 Invalid destination HSICB detected. CLI0007 Invalid destination RCB detected. CLI0008 DBCFRC unable to free RCB/HSICB control blocks because they are not contiguous in storage. CLI0009 Invalid DBCAREA pointer or id. CLI0010 ECB already waiting. 2971 The AMP lock table has overflowed. 2972 No table header exists for table. How to handle Errors : BTEQ alos maintains the return code value in an internal Atrribute called ERRORL EVEL which you can later test and take necessary action depending upon the retur n code. For any database error message which is not given above, BTEQ assigns a default return code of 8 to it. Also there is a way to specify a different return code t o it. . SET ERRORLEVEL UNKNOWN SEVERITY N This BTEQ return codes can be used to Test and Branch accordingly For an example. SELECT * FROM TABLE1; .IF ERRORLEVEL >= 14 THEN .QUIT 17 Also we can change the severity level of different error codes. example : .SET ERRORLEVEL 2168 SEVERITY 4 (2173,3342,5262 ) SEVERITY 8 .SET ERRORLEVEL UNKNOWN SEVERITY 14

BTEQ error level severity has no immediate impact on operations unless the error checking is incorporated in the scripts. The MAXERROR attribute sets threshhold value. So if any error occurs for which the return codes in greater than the MA XERROR the scripts terminates. .SET MAXERROR 12 Note : If you do not specify a MAXERROR value, BTEQ jobs execute until one of the follo wing conditions occurs: End-of-file for the primary command input file is encountered. A QUIT command is processed. A fatal error is detected. When BTEQ receives an I/O abend, system error messages either appear in the MVS JES job log or are displayed on the CMS terminal. When BTEQ receives an I/O error or an abend, the SAS/C runtime library produces an LSCX message that may provide more information about the error. For more information on I/O errors and abends, refer to I/O Errors and Abends SEL C1,Count(*) from T1 GROUP BY 1; .IF ERRORCODE<> 0 THEN .QUIT Select $a Where $a = 1; .If ActivityCount = 1 Then .Goto NoCheck SEL * from T2 where Status='F'; .IF ACTIVITYCOUNT >0 THEN .QUIT 99 .Label NoCheck .Quit 0 ----------------------------------------------------------------------------------No More Spool Space Teradata Query Solution By Kedar March 2, 2010 Have you ever come across a situation called NO MORE SPOOL SPACE? My friend doe s and hence I studied a bit about Teradata. The query: SELECT DISTINCT fieldname FROM tablename; The error: NO MORE SPOOL SPACE . Correct, the problem wasn t related to MySQL, that was for something called Terada ta. Initially, I could see that query should be using temporary space (from name SPO OL SPACE I guessed) to get distinct data may be it s a huge table or something. So I think one has to look into temporary table space s size they call it SPOOL SP ACE.

Next is Google s turn to explain me more, I Googled with appropriate keywords and got following understandings: Spool is temporary disk space used to hold intermediate rows during query proces sing, and to hold the rows in the answer set of a transaction. Spool space is allocated to a user as a total amount available for that user, ho wever this total amount is spread across all AMPS. This means if you re allocated 200G of spool and you re on a system with 24 AMPS, you re allocated ~8.3G of spool o n each AMP. If any AMP exceeds its allocated amount of spool during a transactio n you submit, your query is cancelled with error: NO MORE SPOOL SPACE. Common reasons for No More Spool Space Error : 1) All the rows in the query are being processed on a few amps creating a hot amp situation. In this case, just a few amps are racking up spool while the others s it comparatively idle. This is caused when the tables in the query are missing s tats, have been improperly PI d, or are otherwise untuned . 2) The query is excluding critical join criteria resulting in Cartesian products . 3) You just don t have enough space to perform the query. [ad#ad-2-300x250] From other readings I suggested one query change: SELECT fieldname FROM tablename GROUP BY fieldname; The reason behind above query is: Teradata uses two different methods to produce the result sets of above queries, However the performance varies dramatically depending on the data. SELECT DISTINCT is designed for data sets that are nearly unique to begin with a nd works by sorting the entire intermediate spool file and discarding duplicate values. SELECT/GROUP BY is designed for data sets that have relatively few unique values and works by performing an AMP local grouping operation and then merging the pa rtial result sets for final processing. Few other steps (even) I can suggest to solve such problem are: - Explain to see execution plan to have an idea. - Check table definition for indexes: Show table table-name; - CREATE INDEX indexName (field-name) on table-name; Finally, if nothing happens contact your DBA or the I hope this will help someone, somewhere, someday. If you know that I ve misunderstood something please comment and give respective l inks I should be correcting it asap. right person :)

Potrebbero piacerti anche