Sunday, 23 April 2017

How to Create String Function in PL/SQL Database Management System But not in SQL

--String Function-- 
 
DECLARE
   name varchar2(20);
   company varchar2(30);
   introduction clob;
   choice char(1);
BEGIN
   name := 'Ron Kennedy';
   company := 'Infotech';
   introduction := ' Hello! I''m Ron Kennedy from Yahoo.';
   choice := 'y';
   IF choice = 'y' THEN
      dbms_output.put_line(name);
      dbms_output.put_line(company);
      dbms_output.put_line(introduction);
   END IF;
END;

--String Functions
DECLARE
   greetings varchar2(11) := 'hello world';
BEGIN
   dbms_output.put_line(UPPER(greetings));
  
   dbms_output.put_line(LOWER(greetings));
  
   dbms_output.put_line(INITCAP(greetings));
  
   /* retrieve the first character in the string */
   dbms_output.put_line ( SUBSTR (greetings, 1, 1));
  
   /* retrieve the last character in the string */
   dbms_output.put_line ( SUBSTR (greetings, -1, 1));
  
   /* retrieve five characters,
      starting from the seventh position. */
   dbms_output.put_line ( SUBSTR (greetings, 7, 5));
  
   /* retrieve the remainder of the string,
      starting from the second position. */
   dbms_output.put_line ( SUBSTR (greetings, 2));
  
   /* find the location of the first "e" */
   dbms_output.put_line ( INSTR (greetings, 'e'));
END;

--String Functions more
DECLARE
   greetings varchar2(30) := '......Hello World.....';
BEGIN
   dbms_output.put_line(RTRIM(greetings,'.'));
   dbms_output.put_line(LTRIM(greetings, '.'));
   dbms_output.put_line(TRIM( '.' from greetings));
END;

0 comments:

Post a Comment