INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Store Procedure Declaration

Store Procedure Declaration

(OP)
Hi @ all,

what's my mistake?
I want to build up a table with relevant row-count information of specific tables in the database.
Therefor in the first step I create a temp-table with all relevant tables from dbc and the sql-queries to select the data.
After then I loop with a cursor around every entry in this table and generate a dynamic sql to insert the table and row-count
information in the target table.
But I get different failure messages and don't know why.
I had a look at the examples in the SQl-Reference,too. There is no END Definition before the DECLARE Statements and the
declarations are the same like mine.

error messages:

SPL1027:E(L14), Missing/Invalid SQL statement'E(3707):Syntax error, expected something like an 'END' keyword between ';' and the 'DECLARE' keyword.'.
SPL1027:E(L15), Missing/Invalid SQL statement'E(3707):Syntax error, expected something like an 'END' keyword between ';' and the 'DECLARE' keyword.'.
SPL1027:E(L18), Missing/Invalid SQL statement'E(3707):Syntax error, expected something like an 'END' keyword between ';' and the 'DECLARE' keyword.'.
SPL1030:E(L19), Referring to undefined cursor 'tblcursor'.
SPL1027:E(L21), Missing/Invalid SQL statement'E(3707):Syntax error, expected something like a 'DO' keyword between ')' and the 'FETCH' keyword.'.
SPL2001:E(L24), Undefined symbol 'ctbl'.
SPL2001:E(L24), Undefined symbol 'sql_str'.

I work on a Teradata RELEASE    V2R.06.02.02.30
Thanks for every help.

Leira

Procedure

CREATE PROCEDURE table_facts
(IN DBase VARCHAR(30))
BEGIN

CREATE TABLE tables
AS ( SELECT
      CAST('SELECT country, cdate, ccode, COUNT(*) AS rowcnt  FROM ' || TRIM(tt.Tablename) || ';' AS VARCHAR(1000)) AS sql_str
  , CAST(TRIM(tt.Tablename) AS VARCHAR(30))  AS ctbl
            FROM ( SELECT TableName FROM dbc.tables
            WHERE TableKind = 'T'
            AND TRIM(DatabaseName) = '' || :DBase || ''
            AND TRIM(TableName) LIKE '%_c') tt
      ) WITH DATA ;

DECLARE sql_str VARCHAR(1000) ;
DECLARE ctbl VARCHAR(30) ;
DECLARE tblcursor CURSOR FOR
        SELECT sql_str, ctbl  FROM tables
        ORDER BY 2 ;
        
OPEN tblcursor ;

WHILE (SQLCODE = 0)
FETCH tblcursor INTO sql_str, ctbl ;
DELETE FROM tables_info ;
CALL DBC.SysExecSQL (
'INSERT INTO tables_info (table_name, country, cdate, ccode, rowcnt) SELECT ''' || :ctbl || ''',a1.* FROM (' || :sql_str || 'GROUP BY 1,2,3) a1' ) ;
END WHILE ;

CLOSE tblcursor ;

END ;

RE: Store Procedure Declaration

I am not sure why you want this SP, but anyways the WHILE needs a DO as well as an END WHILE.  As in

WHILE x > 0
DO
something
END WHILE;

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close