Oracle PL/SQL/Char Functions/Dump

Материал из SQL эксперт
Перейти к: навигация, поиск

dump(90101,16)

   
SQL>
SQL>
SQL> select 90101, dump(90101,16) from dual
  2  union all
  3  select 90102, dump(90102,16) from dual
  4  union all
  5  select 90103, dump(90103,16) from dual
  6  /
     90101 DUMP(90101,16)
---------- ---------------------
     90101 Typ=2 Len=4: c3,a,2,2
     90102 Typ=2 Len=4: c3,a,2,3
     90103 Typ=2 Len=4: c3,a,2,4



dump( ename, 16 )

  
SQL>
SQL> CREATE TABLE EMP
  2  (EMPNO NUMBER(4) NOT NULL,
  3   ENAME VARCHAR2(10),
  4   JOB VARCHAR2(9),
  5   MGR NUMBER(4),
  6   HIREDATE DATE,
  7   SAL NUMBER(7, 2),
  8   COMM NUMBER(7, 2),
  9   DEPTNO NUMBER(2)
 10  );
Table created.
SQL>
SQL> INSERT INTO EMP VALUES (7369, "SMITH",  "CLERK",     7902,TO_DATE("17-DEC-1980", "DD-MON-YYYY"),  800, NULL, 20);
1 row created.
SQL> INSERT INTO EMP VALUES (7499, "ALLEN",  "SALESMAN",  7698,TO_DATE("20-FEB-1981", "DD-MON-YYYY"), 1600,  300, 30);
1 row created.
SQL> INSERT INTO EMP VALUES (7521, "WARD",   "SALESMAN",  7698,TO_DATE("22-FEB-1981", "DD-MON-YYYY"), 1250,  500, 30);
1 row created.
SQL> INSERT INTO EMP VALUES (7566, "JONES",  "MANAGER",   7839,TO_DATE("2-APR-1981", "DD-MON-YYYY"),  2975, NULL, 20);
1 row created.
SQL> INSERT INTO EMP VALUES (7654, "MARTIN", "SALESMAN",  7698,TO_DATE("28-SEP-1981", "DD-MON-YYYY"), 1250, 1400, 30);
1 row created.
SQL> INSERT INTO EMP VALUES (7698, "BLAKE",  "MANAGER",   7839,TO_DATE("1-MAY-1981", "DD-MON-YYYY"),  2850, NULL, 30);
1 row created.
SQL> INSERT INTO EMP VALUES (7782, "CLARK",  "MANAGER",   7839,TO_DATE("9-JUN-1981", "DD-MON-YYYY"),  2450, NULL, 10);
1 row created.
SQL> INSERT INTO EMP VALUES (7788, "SCOTT",  "ANALYST",   7566,TO_DATE("09-DEC-1982", "DD-MON-YYYY"), 3000, NULL, 20);
1 row created.
SQL> INSERT INTO EMP VALUES (7839, "KING",   "PRESIDENT", NULL,TO_DATE("17-NOV-1981", "DD-MON-YYYY"), 5000, NULL, 10);
1 row created.
SQL> INSERT INTO EMP VALUES (7844, "TURNER", "SALESMAN",  7698,TO_DATE("8-SEP-1981", "DD-MON-YYYY"),  1500,    0, 30);
1 row created.
SQL> INSERT INTO EMP VALUES (7876, "ADAMS",  "CLERK",     7788,TO_DATE("12-JAN-1983", "DD-MON-YYYY"), 1100, NULL, 20);
1 row created.
SQL> INSERT INTO EMP VALUES (7900, "JAMES",  "CLERK",     7698,TO_DATE("3-DEC-1981", "DD-MON-YYYY"),   950, NULL, 30);
1 row created.
SQL> INSERT INTO EMP VALUES (7902, "FORD",   "ANALYST",   7566,TO_DATE("3-DEC-1981", "DD-MON-YYYY"),  3000, NULL, 20);
1 row created.
SQL> INSERT INTO EMP VALUES (7934, "MILLER", "CLERK",     7782,TO_DATE("23-JAN-1982", "DD-MON-YYYY"), 1300, NULL, 10);
1 row created.
SQL>
SQL> select * from emp;
     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
      7566 JONES      MANAGER         7839 02-APR-81       2975                    20
      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
      7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
      7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
      7788 SCOTT      ANALYST         7566 09-DEC-82       3000                    20
      7839 KING       PRESIDENT            17-NOV-81       5000                    10
      7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
      7876 ADAMS      CLERK           7788 12-JAN-83       1100                    20
      7900 JAMES      CLERK           7698 03-DEC-81        950                    30
      7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
      7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
14 rows selected.
SQL>
SQL>
SQL> select dump( ename, 16 ) from emp;
DUMP(ENAME,16)
----------------------------------------------------------------------------------------------------
Typ=1 Len=5: 53,4d,49,54,48
Typ=1 Len=5: 41,4c,4c,45,4e
Typ=1 Len=4: 57,41,52,44
Typ=1 Len=5: 4a,4f,4e,45,53
Typ=1 Len=6: 4d,41,52,54,49,4e
Typ=1 Len=5: 42,4c,41,4b,45
Typ=1 Len=5: 43,4c,41,52,4b
Typ=1 Len=5: 53,43,4f,54,54
Typ=1 Len=4: 4b,49,4e,47
Typ=1 Len=6: 54,55,52,4e,45,52
Typ=1 Len=5: 41,44,41,4d,53
Typ=1 Len=5: 4a,41,4d,45,53
Typ=1 Len=4: 46,4f,52,44
Typ=1 Len=6: 4d,49,4c,4c,45,52
14 rows selected.
SQL>
SQL> drop table emp;
Table dropped.
SQL> --



dump(reverse(90101),16)

   
SQL>
SQL>
SQL> select 90101, dump(reverse(90101),16) from dual
  2  union all
  3  select 90102, dump(reverse(90102),16) from dual
  4  union all
  5  select 90103, dump(reverse(90103),16) from dual
  6  /
     90101 DUMP(REVERSE(90101),1
---------- ---------------------
     90101 Typ=2 Len=4: 2,2,a,c3
     90102 Typ=2 Len=4: 3,2,a,c3
     90103 Typ=2 Len=4: 4,2,a,c3
SQL>
SQL>



dump table column

  
SQL>
SQL> CREATE TABLE EMP
  2  (EMPNO NUMBER(4) NOT NULL,
  3   ENAME VARCHAR2(10),
  4   JOB VARCHAR2(9),
  5   MGR NUMBER(4),
  6   HIREDATE DATE,
  7   SAL NUMBER(7, 2),
  8   COMM NUMBER(7, 2),
  9   DEPTNO NUMBER(2)
 10  );
Table created.
SQL>
SQL> INSERT INTO EMP VALUES (7369, "SMITH",  "CLERK",     7902,TO_DATE("17-DEC-1980", "DD-MON-YYYY"),  800, NULL, 20);
1 row created.
SQL> INSERT INTO EMP VALUES (7499, "ALLEN",  "SALESMAN",  7698,TO_DATE("20-FEB-1981", "DD-MON-YYYY"), 1600,  300, 30);
1 row created.
SQL> INSERT INTO EMP VALUES (7521, "WARD",   "SALESMAN",  7698,TO_DATE("22-FEB-1981", "DD-MON-YYYY"), 1250,  500, 30);
1 row created.
SQL> INSERT INTO EMP VALUES (7566, "JONES",  "MANAGER",   7839,TO_DATE("2-APR-1981", "DD-MON-YYYY"),  2975, NULL, 20);
1 row created.
SQL> INSERT INTO EMP VALUES (7654, "MARTIN", "SALESMAN",  7698,TO_DATE("28-SEP-1981", "DD-MON-YYYY"), 1250, 1400, 30);
1 row created.
SQL> INSERT INTO EMP VALUES (7698, "BLAKE",  "MANAGER",   7839,TO_DATE("1-MAY-1981", "DD-MON-YYYY"),  2850, NULL, 30);
1 row created.
SQL> INSERT INTO EMP VALUES (7782, "CLARK",  "MANAGER",   7839,TO_DATE("9-JUN-1981", "DD-MON-YYYY"),  2450, NULL, 10);
1 row created.
SQL> INSERT INTO EMP VALUES (7788, "SCOTT",  "ANALYST",   7566,TO_DATE("09-DEC-1982", "DD-MON-YYYY"), 3000, NULL, 20);
1 row created.
SQL> INSERT INTO EMP VALUES (7839, "KING",   "PRESIDENT", NULL,TO_DATE("17-NOV-1981", "DD-MON-YYYY"), 5000, NULL, 10);
1 row created.
SQL> INSERT INTO EMP VALUES (7844, "TURNER", "SALESMAN",  7698,TO_DATE("8-SEP-1981", "DD-MON-YYYY"),  1500,    0, 30);
1 row created.
SQL> INSERT INTO EMP VALUES (7876, "ADAMS",  "CLERK",     7788,TO_DATE("12-JAN-1983", "DD-MON-YYYY"), 1100, NULL, 20);
1 row created.
SQL> INSERT INTO EMP VALUES (7900, "JAMES",  "CLERK",     7698,TO_DATE("3-DEC-1981", "DD-MON-YYYY"),   950, NULL, 30);
1 row created.
SQL> INSERT INTO EMP VALUES (7902, "FORD",   "ANALYST",   7566,TO_DATE("3-DEC-1981", "DD-MON-YYYY"),  3000, NULL, 20);
1 row created.
SQL> INSERT INTO EMP VALUES (7934, "MILLER", "CLERK",     7782,TO_DATE("23-JAN-1982", "DD-MON-YYYY"), 1300, NULL, 10);
1 row created.
SQL>
SQL> select * from emp;
     EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
      7369 SMITH      CLERK           7902 17-DEC-80        800                    20
      7499 ALLEN      SALESMAN        7698 20-FEB-81       1600        300         30
      7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
      7566 JONES      MANAGER         7839 02-APR-81       2975                    20
      7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
      7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
      7782 CLARK      MANAGER         7839 09-JUN-81       2450                    10
      7788 SCOTT      ANALYST         7566 09-DEC-82       3000                    20
      7839 KING       PRESIDENT            17-NOV-81       5000                    10
      7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
      7876 ADAMS      CLERK           7788 12-JAN-83       1100                    20
      7900 JAMES      CLERK           7698 03-DEC-81        950                    30
      7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
      7934 MILLER     CLERK           7782 23-JAN-82       1300                    10
14 rows selected.
SQL>
SQL> select dump( ename, 8 ) from emp;
DUMP(ENAME,8)
----------------------------------------------------------------------------------------------------
Typ=1 Len=5: 123,115,111,124,110
Typ=1 Len=5: 101,114,114,105,116
Typ=1 Len=4: 127,101,122,104
Typ=1 Len=5: 112,117,116,105,123
Typ=1 Len=6: 115,101,122,124,111,116
Typ=1 Len=5: 102,114,101,113,105
Typ=1 Len=5: 103,114,101,122,113
Typ=1 Len=5: 123,103,117,124,124
Typ=1 Len=4: 113,111,116,107
Typ=1 Len=6: 124,125,122,116,105,122
Typ=1 Len=5: 101,104,101,115,123
Typ=1 Len=5: 112,101,115,105,123
Typ=1 Len=4: 106,117,122,104
Typ=1 Len=6: 115,111,114,114,105,122
14 rows selected.
SQL>
SQL> drop table emp;
Table dropped.
SQL> --



START_POSITION specifies which character in the supplied string to start with, and the optional length specifies how many characters to consider.

  
SQL>
SQL> SELECT
  2     DUMP("ABC",1010,1)  type_info
  3  FROM dual;
TYPE_INFO
------------------------------------------------
Typ=96 Len=3 CharacterSet=WE8MSWIN1252: 65,66,67



Syntax: DUMP(expression [,RETURN_FORMAT [START_POSITION] [LENGTH]])

  
SQL>
SQL> SELECT
  2     DUMP("ABC",1010)  type_info
  3  FROM dual;
TYPE_INFO
------------------------------------------------
Typ=96 Len=3 CharacterSet=WE8MSWIN1252: 65,66,67



Union all with dump reverse

  
SQL>
SQL>
SQL> select 90101, dump(reverse(90101),16) from dual
  2  union all
  3  select 90102, dump(reverse(90102),16) from dual
  4  union all
  5  select 90103, dump(reverse(90103),16) from dual
  6  /
     90101 DUMP(REVERSE(90101),1
---------- ---------------------
     90101 Typ=2 Len=4: 2,2,a,c3
     90102 Typ=2 Len=4: 3,2,a,c3
     90103 Typ=2 Len=4: 4,2,a,c3
3 rows selected.
SQL>
SQL> --