Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Friday, 7 November 2014

Fetch Sample data in Teradata

We can fetch sample data from Teradata table as shown below:-

SELECT *  FROM PROD.EMPLOYEE SAMPLE 10;

Drop Macro in Teradata

We can drop Macro in Teradata as:-

DROP MACRO MY_MACRO;


Parameterize Macro in Teradata

We can have parameterized Macro in Teradata as:-

CREATE MACRO MY_MACRO(PAR_EMP_NO INTEGER) AS
(
SELECT *  FROM PROD.EMPLOYEE
WHERE EMP_NO=PAR_EMP_NO;
);


To execute parameterized Macro:-

EXEC MY_MACRO(10);


Execute Macro in Teradata

After creating Macro we can execute it as:-

CREATE MACRO MY_MACRO AS
(
SELECT *  FROM PROD.EMPLOYEE;
);

EXECUTE MY_MACRO;

Create Macro in Teradata

A macro allows us to name a set of one or more statements and execute it as a group.

The syntax of creating Macro is:-

CREATE MACRO MACRO_NAME AS
(
 SQL_STATEMENTS;
) ;

Sample Macro is:-

CREATE MACRO MY_MACRO AS
(
SELECT * FROM PROD.EMPLOYEE;
) ;


Tuesday, 4 November 2014

Executing procedure in Teradata

We can execute procedure in Teradata as shown below:-

CALL PROCEDURE PROCEDURE_NAME;

If you have procedure called PROC_UPSERT then:-

CALL PROCEDURE PROC_UPSERT;

If your procedure is parameterize then:-

CALL PROCEDURE PROCEDURE_NAME(PARAMETER (S)) ;


Truncate in Teradata

In teradata, we do not have Truncate command as such but below is the command which work similar to the Truncate command:-

DELETE FROM DATABASE_NAME.TABLE_NAME ALL;

If you have HR database and Employee table then:-

DELETE FROM HR.EMPLOYEE ALL;




Please provide your feedback in the comments section above. Please don't forget to follow.