Oracle PL/SQL/Data Type/Integer

Материал из SQL эксперт
Версия от 09:58, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Define integer variables

SQL>
SQL> SET SERVEROUTPUT ON
SQL> DECLARE
  2      width INTEGER;
  3      height INTEGER := 2;
  4      area INTEGER;
  5  BEGIN
  6      area := 6;
  7      width := area / height;
  8      DBMS_OUTPUT.PUT_LINE("width = " || width);
  9  EXCEPTION
 10  WHEN ZERO_DIVIDE THEN
 11     DBMS_OUTPUT.PUT_LINE("Division by zero");
 12  END;
 13  /
width = 3
PL/SQL procedure successfully completed.
SQL>
SQL>
SQL>



Int value column

 
SQL>
SQL> create table t1
  2  (  x int primary key,
  3     y varchar2(25),
  4     z date
  5  )
  6  organization index;
Table created.
SQL>
SQL> drop table t1;
Table dropped.
SQL>
SQL>
SQL> --



Use ANSI Data Types when creating a table

 
SQL>
SQL> create table foo (
  2         a   integer,
  3         b   dec( 9, 2 ),
  4         c   character varying( 30 ),
  5         d   national char( 3 )
  6      );
Table created.

SQL>
SQL> drop table foo;
Table dropped.
SQL>



Use for loop statement to set value to an integer variable

 
SQL>
SQL> set echo on
SQL>
SQL> DECLARE
  2      v_MyChar VARCHAR2(20) := "test";
  3      v_NUMBER NUMBER;
  4      V_Date DATE := SYSDATE;
  5      v_counter INTEGER;
  6  BEGIN
  7      DBMS_OUTPUT.PUT_LINE("This is a Test");
  8      DBMS_OUTPUT.PUT_LINE("Of Syntax Error Debugging");
  9      For v_COUNTER IN 1..5 LOOP
 10          DBMS_OUTPUT.PUT_LINE("You are in loop:" || v_counter);
 11      END LOOP;
 12  END;
 13  /
This is a Test
Of Syntax Error Debugging
You are in loop:1
You are in loop:2
You are in loop:3
You are in loop:4
You are in loop:5
PL/SQL procedure successfully completed.
SQL>
SQL>
SQL>
SQL> --