GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Oracle  >  PL/SQL
Go To First  |  Previous Question  |  Next Question 
 PL/SQL  |  Question 225 of 235    Print  
Writing Pl/SQL function
Write a PL/SQL fuction named say TRUN, which does the same work as the oracle predefined function "TRUNCATE".


  
Total Answers and Comments: 2 Last Update: July 09, 2008     Asked by: csprusty 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: sgbang
 
Hi,

Please check out this function:

create or replace function trun(p_table_name varchar2) return number as
begin
execute immediate ' truncate table '|| p_table_name;
return 0 ;
end;
 /

How to execute example:


declare
return_int number;
begin
return_int:=trun('emp');                                      --emp is a dummy table i used
dbms_output.put_line('return is :'||return_int);  --return_int should return 0
end;
/

Hope this is helpful

Above answer was rated as good by the following members:
ajaz_11i
July 07, 2008 01:01:14   #1  
sgbang Member Since: July 2008   Contribution: 2    

RE: Writing Pl/SQL function
Hi,

Please check out this function:

create or replace function trun(p_table_name varchar2) return number as
begin
execute immediate ' truncate table '|| p_table_name;
return 0 ;
end;
 /

How to execute example:


declare
return_int number;
begin
return_int:=trun('emp');                                      --emp is a dummy table i used
dbms_output.put_line('return is :'||return_int);  --return_int should return 0
end;
/

Hope this is helpful

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
July 09, 2008 00:48:30   #2  
ajaz_11i Member Since: June 2008   Contribution: 4    

RE: Writing Pl/SQL function
It will truncate/delete all the rows in the table emp very fast as compared of delete command, but the table must have no Foriegn key
Mr. Ajaz Ahmad Kumar

 
Is this answer useful? Yes | No

 Related Questions

 A  stored  procedure  is  a  sequence  of  statements that perform specific function. 
Latest Answer : A procedure is a named PL/SQL block that can accept parameters (sometimes referred to as arguments), and be invoked. Generally speaking, you use a procedure to perform an action. A procedure has a header, a declaration section, an executable section, ...

 A FUNCTION is always returns a value using the return statement.        A  PROCEDURE   may  return one or more values through parameters or 
Latest Answer : 1. Function is mainly used in the case where it must return a value. Where as a procedure may or may not return a value or may return more than one value using the OUT parameter. 2. Function can be called from SQL statements where as procedure can not ...

       FUNCTION name (argument list .....) Return datatype is     local variable declarations     Begin          
Latest Answer : create or replace function function_name(formal parameters list with only IN mode) return datatypeislocal variable declarationsbegin executable statments; return value;end function_name; ...

 Function is called as part of an expression.   sal := calculate_sal ('a822');   procedure is called as a PL/SQL statement   calculate_bonus ('A822'); 
Latest Answer : Procedure can be called in the following waysa) CALL direcb) EXCECUTE from calling environmentc) from other procedures or functions or packagesFunctions can be called in the following ...

     a. Stored procedure or anonymous block     b. an application program such a PRC *C, PRO* COBOL     c. SQL *PLUS      
Latest Answer : a. PACKAGE NAME.PROCEDURE NAME (parameters);     variable := PACKAGE NAME.FUNCTION NAME (arguments);        b.     BEGIN     PACKAGE NAME.PROCEDURE ...

How to return more than one value from a function?What are the types of triggers?What are the features of oracle 9i

What steps should a programmer should follow for better tunning of the PL/SQL blocks?Difference between procedure and function?What is the use of ref cursor return type?

What is a purity level? How it is should be taken into consideration when your writing any database objects i.e., trigger,function, procedure etc.,

View Question | Asked by : Nitina

What is difference b/w stored procedures and application procedures,stored function and application function..
Read Answers (5) | Asked by : rajanen


 Sponsored Links

 
Related Articles

Querying Data with Oracle XQuery

Querying Data with Oracle XQuery Starting with Oracle Database 10g Release 2 you can take advantage of a full featured native XQuery engine integrated with the database With Oracle XQuery you can accomplish various tasks involved in developing PHP Oracle XML applications operating on any kind of dat
 

Using Oracle XML DB Repository

Using Oracle XML DB Repository Another variation on accessing and manipulating XML content stored in Oracle database is provided by Oracle XML DB repository which is an essential component of Oracle XML DB mosgoogle NOTE Oracle XML DB repository also known as XML repository is a hierarchically organ
 

Using Oracle Database for Storing, Modifying, and Retrieving XML Data

Using Oracle Database for Storing Modifying and Retrieving XML Data With Oracle XML DB you have various XML storage and XML processing options allowing you to achieve the required level of performance and scalability One of the most interesting things about Oracle XML DB is that it allows you to per
 

XML Processing in PHP and Oracle Applications

Processing XML in PHP Oracle Applications As mentioned there are two alternatives when it comes to performing XML processing in your PHP Oracle application You can perform any required XML processing using either PHP s XML extensions or PEAR XML packages or Oracle s XML features mosgoogle In the fol
 

PHP Oracle Web Development

PHP Oracle Web Development Data processing Security Caching XML Web Services and Ajax The book is written by Yuli Vaseliev a well known author of different web development and programming books PHP Oracle Web Development Data processing Security Caching XML Web Services and Ajax is a good starting b
 

Getting Started with Oracle and ODP.NET

ODP NET Developer’ s Guide by Jagadish Chatarji Pulakhandam Sunitha Paruchuri A practical guide for developers working with the Oracle Data Provider for NET and the Oracle Developer Tools for Visual Studio 2005 Application development with ODP NET Dealing with XML DB using ODP NET Oracle
 

PHP Oracle Web Development Review

PHP Oracle Web Development Data processing Security Caching XML Web Services and Ajax The book is written by Yuli Vaseliev a well known author of different web development and programming books The author is also an expert in open source technologies and SOA Service Oriented Architecture But besides
 

Step by Step Oracle PL-SQL Tutorial

This introductory tutorial to PL SQL will help you to understand the basic concepts of PL SQL Please review the following tutorials and practice the sample SQL Statements on your local Oracle Database Please note that you must learn these basic things before we actually start getting in to Advanced
 

C++ Pure Virtual Function and Base Class

C Pure Virtual Function and Virtual Base Class In this C tutorial you will learn about pure virtual function declaration of pure virtual function and virtual base class virtual base class and how to implement a virtual base class explained with examples mosgoogle center What is Pure Virtual Function
 

C++ Function Passing Types

C Function Passing Types In this C tutorial you will learn about function passing types two types of arguments passing in functions passed by value  and  passed by reference are discussed here mosgoogle center The arguments passed to a function can be performed in two ways Passed
 

Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape