我的编程空间,编程开发者的网络收藏夹
学习永远不晚

如何使用PL/SQL来创建RESTful Web Services

短信预约 -IT技能 免费直播动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

如何使用PL/SQL来创建RESTful Web Services

这篇文章主要介绍如何使用PL/SQL来创建RESTful Web Services,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

Version:

ords.18.1.1.95.1251

jdk1.8.0_171

设置JDK

export JAVA_HOME=/u/dba/oracle/frank/jdk1.8.0_171
export PATH=$JAVA_HOME/bin:$PATH

设置ORDS

bash-4.1$ java -jar ords.war install advanced
This Oracle REST Data Services instance has not yet been configured.
Please complete the following prompts

Enter the location to store configuration data:/lv01/apache-tomcat-8.5.31/ords/config
Enter the name of the database server [localhost]:<host name>
Enter the database listen port [1521]:152X
Enter 1 to specify the database service name, or 2 to specify the database SID [1]:2
Enter the database SID [xe]:<sid>
Enter 1 if you want to verify/install Oracle REST Data Services schema or 2 to skip this step [1]:
Enter the database password for ORDS_PUBLIC_USER:
Confirm password:
Requires SYS AS SYSDBA to verify Oracle REST Data Services schema.

Enter the database password for SYS AS SYSDBA:
Confirm password:

Retrieving information.
Enter the default tablespace for ORDS_METADATA [SYSAUX]:
Enter the temporary tablespace for ORDS_METADATA [TEMP]:
Enter the default tablespace for ORDS_PUBLIC_USER [USERS]:
Enter the temporary tablespace for ORDS_PUBLIC_USER [TEMP]:
Enter 1 if you want to use PL/SQL Gateway or 2 to skip this step.
If using Oracle Application Express or migrating from mod_plsql then you must enter 1 [1]:2
Jul 04, 2018 7:07:23 PM  
INFO: Updated configurations: defaults, apex_pu
Installing Oracle REST Data Services version 18.1.1.95.1251
... Log file written to /web01/apache-tomcat-8.5.31/ords/logs/ords_install_core_2018-07-04_190723_00459.log
... Verified database prerequisites
... Created Oracle REST Data Services schema
... Created Oracle REST Data Services proxy user
... Granted privileges to Oracle REST Data Services
... Created Oracle REST Data Services database objects
... Log file written to /web01/apache-tomcat-8.5.31/ords/logs/ords_install_datamodel_2018-07-04_190806_00041.log
... Log file written to /web01/apache-tomcat-8.5.31/ords/logs/ords_install_apex_2018-07-04_190807_00872.log
Completed installation for Oracle REST Data Services version 18.1.1.95.1251. Elapsed time: 00:00:45.790

Enter 1 if you wish to start in standalone mode or 2 to exit [1]:2

在安装完成以后验证数据库对象

bash-4.1$ java -jar ords.war validate <sid>
Requires SYS AS SYSDBA to verify Oracle REST Data Services schema.

Enter the database password for SYS AS SYSDBA:
Confirm password:

Retrieving information.

Oracle REST Data Services will be validated.
Validating Oracle REST Data Services schema version 18.1.1.95.1251
... Log file written to /web01/apache-tomcat-8.5.31/ords/logs/ords_validate_core_2018-07-04_191324_00217.log
Completed validating Oracle REST Data Services version 18.1.1.95.1251.  Elapsed time: 00:00:12.509

view /web01/apache-tomcat-8.5.31/ords/logs/ords_validate_core_2018-07-04_191324_00217.log
[*** script: ords_validate_objects.sql]

Session altered.

INFO: 19:13:27 Validating objects for Oracle REST Data Services.
VALIDATION: 19:13:27 Starting validation for schema: ORDS_METADATA
VALIDATION: 19:13:27 Validating objects
VALIDATION: 19:13:35 Validating ORDS Public Synonyms
VALIDATION: 19:13:36 Total objects: 244, invalid objects: 0
VALIDATION: 19:13:36     72  INDEX
VALIDATION: 19:13:36      1  JOB
VALIDATION: 19:13:36     11  PACKAGE
VALIDATION: 19:13:36     11  PACKAGE BODY
VALIDATION: 19:13:36     43  PUBLIC SYNONYM
VALIDATION: 19:13:36      1  SEQUENCE
VALIDATION: 19:13:36     27  TABLE
VALIDATION: 19:13:36     26  TRIGGER
VALIDATION: 19:13:36     19  TYPE
VALIDATION: 19:13:36      6  TYPE BODY
VALIDATION: 19:13:36     27  VIEW
VALIDATION: 19:13:36 Validation completed.
INFO: 19:13:36 Completed validating objects for Oracle REST Data Services. PL/SQL procedure successfully completed.

添加一个数据库map

export JAVA_HOME=/u/dba/oracle/frank/jdk1.8.0_171
export PATH=$JAVA_HOME/bin:$PATH

java -jar ords.war map-url --type base-path /<sid> <sid>
Jul 11, 2018 6:40:33 PM  
INFO: Creating new mapping from: [base-path,/<sid>] to map to: [<sid>,,]

在数据库里建立做一个简单测试

sqlplus testuser1/testuser1@<sid> CREATE TABLE EMP (
  EMPNO NUMBER(4,0),
  ENAME VARCHAR2(10 BYTE),
  JOB VARCHAR2(9 BYTE),
  MGR NUMBER(4,0),
  HIREDATE DATE,
  SAL NUMBER(7,2),
  COMM NUMBER(7,2),
  DEPTNO NUMBER(2,0),
  CONSTRAINT PK_EMP PRIMARY KEY (EMPNO)
  );
 
insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7369,'SMITH','CLERK',7902,to_date('17-DEC-80','DD-MON-RR'),800,null,20);
insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7499,'ALLEN','SALESMAN',7698,to_date('20-FEB-81','DD-MON-RR'),1600,300,30);
insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7521,'WARD','SALESMAN',7698,to_date('22-FEB-81','DD-MON-RR'),1250,500,30);
insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7566,'JONES','MANAGER',7839,to_date('02-APR-81','DD-MON-RR'),2975,null,20);
insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7654,'MARTIN','SALESMAN',7698,to_date('28-SEP-81','DD-MON-RR'),1250,1400,30);
insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7698,'BLAKE','MANAGER',7839,to_date('01-MAY-81','DD-MON-RR'),2850,null,30);
insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7782,'CLARK','MANAGER',7839,to_date('09-JUN-81','DD-MON-RR'),2450,null,10);
insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7788,'SCOTT','ANALYST',7566,to_date('19-APR-87','DD-MON-RR'),3000,null,20);
insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7839,'KING','PRESIDENT',null,to_date('17-NOV-81','DD-MON-RR'),5000,null,10);
insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7844,'TURNER','SALESMAN',7698,to_date('08-SEP-81','DD-MON-RR'),1500,0,30);
insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7876,'ADAMS','CLERK',7788,to_date('23-MAY-87','DD-MON-RR'),1100,null,20);
insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7900,'JAMES','CLERK',7698,to_date('03-DEC-81','DD-MON-RR'),950,null,30);
insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7902,'FORD','ANALYST',7566,to_date('03-DEC-81','DD-MON-RR'),3000,null,20);
insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7934,'MILLER','CLERK',7782,to_date('23-JAN-82','DD-MON-RR'),1300,null,10);
commit;

#enable schema
CONN testuser1/testuser1@<sid>

BEGIN
  ORDS.enable_schema(
    p_enabled             => TRUE,
    p_schema              => 'TESTUSER1',
    p_url_mapping_type    => 'BASE_PATH',
    p_url_mapping_pattern => 'testuser1',
    p_auto_rest_auth      => FALSE
  );
    
  COMMIT;
END;
/ ase ORDS URL : http://<host>:8080/ords/<host>/
Schema (alias): http://<host>.bv.tek.com:8080/ords/<host>/testuser1/
Module        : http://<host>.bv.tek.com:8080/ords/<host>/testuser1/testmodule1/
Template      : http://<host>.bv.tek.com:8080/ords/<host>/testuser1/testmodule1/emp/ BEGIN
  ORDS.define_module(
    p_module_name    => 'testmodule2',
    p_base_path      => 'testmodule2/',
    p_items_per_page => 0);
 
  ORDS.define_template(
   p_module_name    => 'testmodule2',
   p_pattern        => 'emp/');

  ORDS.define_handler(
    p_module_name    => 'testmodule2',
    p_pattern        => 'emp/',
    p_method         => 'GET',
    p_source_type    => ORDS.source_type_collection_feed,
    p_source         => 'SELECT * FROM emp',
    p_items_per_page => 0);
    
  COMMIT;
END;

以上是“如何使用PL/SQL来创建RESTful Web Services”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

如何使用PL/SQL来创建RESTful Web Services

下载Word文档到电脑,方便收藏和打印~

下载Word文档

猜你喜欢

如何使用new来创建对象

本篇内容主要讲解“如何使用new来创建对象”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何使用new来创建对象”吧!使用 new 来创建对象使用 new 来创建对象是最简单的一种方式了,new
2023-06-15

如何使用Visual Studio 2008 WEB创建网站

这篇文章主要为大家展示了“如何使用Visual Studio 2008 WEB创建网站”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“如何使用Visual Studio 2008 WEB创建网站”
2023-06-17

如何使用GitHub来创建和展示demo

GitHub是一个非常流行的开源代码托管平台,它可以让开发者们共享和协作,以帮助加速软件的开发过程。在GitHub上,你可以找到大量开源项目,可以学习和探索其他开发者的代码,并且可以创建自己的项目并与其他人合作。在这篇文章中,我们将讨论如何
2023-10-22

Eclipse中如何使用Maven创建Java Web工程

这篇文章主要介绍Eclipse中如何使用Maven创建Java Web工程,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!Eclipse中使用Maven创建Java Web工程的实现方式1)在Eclipse项目栏中右键
2023-05-30

Web应用程序如何使用C#进行创建

本篇文章为大家展示了Web应用程序如何使用C#进行创建,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。使用微软正在推行的.NET技术和C#语言可以快速建立Web应用程序,其安全性和可升级性都大大胜过普
2023-05-31

Linux系统如何使用nmcli来创建/添加网桥

小编给大家分享一下Linux系统如何使用nmcli来创建/添加网桥,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!如何使用 nmcli 来创建/添加网桥使用 NetworkManager 在 Linux 上添加网桥接口的步骤
2023-06-28

编程热搜

目录