Oracle PL/SQL Tutorial/System Packages/utl raw

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

Difference between utl_raw.length and length

   <source lang="sql">

SQL> SQL> create table t ( r raw(10) ); Table created. SQL> SQL> SQL> insert into t values ( utl_raw.cast_to_raw("helloWorld" ) ); 1 row created. SQL> SQL> select utl_raw.length(r), length(r)/2 from t; UTL_RAW.LENGTH(R) LENGTH(R)/2


-----------
              10          10

SQL> SQL> SQL> drop table t; Table dropped. SQL></source>


select utl_raw.cast_to_varchar2(hextoraw("534d495448")) from dual

   <source lang="sql">

SQL> SQL> SQL> select utl_raw.cast_to_varchar2(hextoraw("534d495448")) from dual; UTL_RAW.CAST_TO_VARCHAR2(HEXTORAW("534D495448"))



SMITH SQL></source>


select utl_raw.cast_to_varchar2(hextoraw("787878")) from dual

   <source lang="sql">

SQL> SQL> SQL> select utl_raw.cast_to_varchar2(hextoraw("787878")) from dual; UTL_RAW.CAST_TO_VARCHAR2(HEXTORAW("787878"))



xxx SQL></source>


Use utl_raw.cast_to_raw to convert string to raw

   <source lang="sql">

SQL> SQL> SQL> select utl_raw.cast_to_raw( "Hello World!" ) data

 2    from dual;

DATA


48656C6C6F20576F726C6421 SQL></source>


Use utl_raw.substr

   <source lang="sql">

SQL> SQL> create table t ( r raw(10) ); Table created. SQL> SQL> insert into t values ( utl_raw.cast_to_raw("helloWorld" ) ); 1 row created. SQL> SQL> select utl_raw.substr(r,2,3) r1, hextoraw(substr(r,3,6)) r2 from t

 2

SQL> drop table t; Table dropped. SQL></source>


utl_raw.cast_to_raw

   <source lang="sql">

SQL> SQL> create table demo

 2  ( id           int primary key,
 3    theBlob      blob
 4  )
 5  /

Table created. SQL> update demo set theBlob = utl_raw.cast_to_raw("Hello World") where id = 1

 2  /

0 rows updated. SQL> drop table demo; Table dropped.</source>