Skip to content

Commit 4398e32

Browse files
authored
Add files via upload
1 parent 83f5a6d commit 4398e32

File tree

6 files changed

+336
-4
lines changed

6 files changed

+336
-4
lines changed

dotnet/CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Copyright (c) Oracle and/or its affiliates. All rights reserved.
2+
3+
Oracle requires that contributors to all of its open-source projects sign the <a href="http://www.oracle.com/technetwork/community/oca-486395.html">Oracle Contributor Agreement (OCA)</a>.

dotnet/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Oracle
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

dotnet/README.md

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
1-
# .NET based examples
2-
This folder stores .NET based examples for Oracle Database.
1+
<H1>Oracle .NET Code Sample Respository</H1>
2+
<H2>About Oracle .NET</H2>
3+
This repository provides .NET code samples for Oracle developers, specifically for Oracle Data Provider for .NET (ODP.NET)
4+
and other Oracle .NET components. .NET products for Oracle Database are free of charge. They consist of:
5+
6+
<ul>
7+
<li>Oracle Data Provider for .NET (ODP.NET) - an optimized ADO.NET data access provider to the Oracle database. ODP.NET allows developers to take advantage of advanced Oracle database functionality, including Real Application Clusters, XML DB, and self-updating client caches.</li>
8+
<li>Oracle Developer Tools for Visual Studio - a tightly integrated design-time "Add-in" for Microsoft Visual Studio that provides full Oracle .NET application lifecycle management, including PL/SQL debugging and schema comparison tools.</li>
9+
<li>Oracle Providers for ASP.NET - a collection of ASP.NET providers that use Oracle Database as the data source. ASP.NET applications can store various types of website state in an Oracle database, which can then be shared across the application.</li>
10+
<li>Oracle Database Extensions for .NET - a feature of Oracle Database on Windows that makes it easy to develop, deploy, and run stored procedures and functions written in a .NET managed language</li>
11+
<li>Oracle TimesTen Data Provider for .NET - ODP.NET support for Oracle TimesTen In-Memory Database (TimesTen) provides fast and efficient ADO.NET data access from .NET client applications to TimesTen databases.</li>
12+
</ul>
13+
<H2>Geting Started</H2>
14+
Oracle .NET components are bundled together and installed as part of Oracle Data Access Components (ODAC). Downloads and installation instructions are available from the <a href="http://www.oracle.com/technetwork/topics/dotnet/downloads/index.html">OTN .NET Tech Center download page</a>. Beginners should download <a href="http://www.oracle.com/technetwork/topics/dotnet/utilsoft-086879.html">32-bit ODAC with Oracle Developer Tools for Visual Studio</a>, which will provide a guided, smoother installation experience. Installation instructions are available as part of each download page. The installation instructions list the software prerequisites for the version downloaded.
15+
16+
<H2>Tutorials</H2>
17+
For beginning Oracle .NET developers, these <a href="http://www.oracle.com/technetwork/topics/dotnet/for-beginners/index.html">tutorials and videos</a> will assist you in developing .NET applications for Oracle Database. Instructions for compiling, testing, deploying, and running Oracle .NET apps are part of the <a href="https://apex.oracle.com/pls/apex/f?p=44785:24:0::NO::P24_CONTENT_ID,P24_PREV_PAGE:10117,1">Oracle By Example tutorials</a>.
18+
19+
<H2>More Information</H2>
20+
<ul>
21+
<li><a href="http://docs.oracle.com/cd/E63277_01/index.htm">Documentation</a></li>
22+
<li>Code samples are included with the ODAC Oracle Universal Installation. You will find them in the "ODACSamples" directory in the Oracle Client installation home (e.g. d:\app\client\&lt;username&gt;\product\&lt;Oracle version&gt;\client_1\ODACsamples).</li>
23+
<li>Contibutions to code samples should review <a href="CONTRIBUTING.md">CONTRIBUTING</a> for more details.</li>
24+
<li>You may use files in this repository only if in compliance with the <a href="LICENSE">LICENSE</a>.</li>
25+
<li>More Oracle .NET development information can be found at the <a href="http://otn.oracle.com/dotnet">OTN .NET Developer Center</a>.</li>
26+
</ul>
327

4-
## dotnet-db-samples
5-
Legacy repository of .NET based examples.

dotnet/samples/selectjson.cs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
2+
3+
/******************************************************************************
4+
*
5+
* You may not use the identified files except in compliance with The MIT
6+
* License (the "License.")
7+
*
8+
* You may obtain a copy of the License at
9+
* https://github.com/oracle/Oracle.NET/blob/master/LICENSE
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
*
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* NAME
19+
* oraclejson.cs
20+
*
21+
* DESCRIPTION
22+
* Inserts one row into a JSON table.
23+
* Executes a query against a JSON table.
24+
* This sample works with either ODP.NET, Managed Driver or
25+
* ODP.NET, Unmanaged Driver.
26+
*
27+
* Requires Oracle Database 12.1.0.2 or higher, which has JSON datatype support.
28+
* See http://docs.oracle.com/database/121/ADXDB/json.htm#CACGCBEG
29+
* Use SQL below to create the required table or do:
30+
*
31+
* DROP TABLE j_purchaseorder;
32+
* CREATE TABLE j_purchaseorder
33+
* (po_document VARCHAR2(4000) CONSTRAINT ensure_json CHECK (po_document IS JSON));
34+
*
35+
*
36+
*****************************************************************************/
37+
38+
using System;
39+
using Oracle.ManagedDataAccess.Client;
40+
//using Oracle.DataAccess.Client;
41+
42+
namespace JsonSample
43+
{
44+
class Program
45+
{
46+
static void Main(string[] args)
47+
{
48+
try
49+
{
50+
// Add your user id, password, and data source
51+
string conString = "User Id=<user>;Password=<password>;Data Source=<data source>;";
52+
53+
// Connect and open a database connection
54+
OracleConnection con = new OracleConnection();
55+
con.ConnectionString = conString;
56+
con.Open();
57+
58+
// Insert JSON data into database
59+
OracleCommand cmd = con.CreateCommand();
60+
cmd.CommandText = "INSERT INTO j_purchaseorder (po_document) VALUES (:1)";
61+
62+
OracleParameter param = new OracleParameter();
63+
param.OracleDbType = OracleDbType.Varchar2;
64+
param.Value = @"{'id': 1,'name': 'Alex', 'location': 'USA'}";
65+
cmd.Parameters.Add(param);
66+
67+
cmd.ExecuteNonQuery();
68+
69+
Console.WriteLine("JSON inserted.");
70+
Console.WriteLine();
71+
72+
// Query JSON from database
73+
cmd.CommandText = "SELECT po_document FROM j_purchaseorder WHERE JSON_EXISTS (po_document, '$.location')";
74+
OracleDataReader rdr = cmd.ExecuteReader();
75+
76+
rdr.Read();
77+
Console.WriteLine(rdr.GetOracleValue(0));
78+
79+
}
80+
catch (Exception ex)
81+
{
82+
Console.WriteLine(ex.Message);
83+
Console.WriteLine(ex.InnerException);
84+
}
85+
86+
}
87+
}
88+
}

dotnet/samples/selectjsonclob.cs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
2+
3+
/******************************************************************************
4+
*
5+
* You may not use the identified files except in compliance with The MIT
6+
* License, Version 2.0 (the "License.")
7+
*
8+
* You may obtain a copy of the License at
9+
* https://github.com/oracle/Oracle.NET/blob/master/LICENSE
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
*
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* NAME
19+
* oraclejsonclob.cs
20+
*
21+
* DESCRIPTION
22+
* Inserts one row into a JSON table using CLOB storage.
23+
* Executes a query against a JSON table using CLOB storage.
24+
* This sample works with either ODP.NET, Managed Driver or
25+
* ODP.NET, Unmanaged Driver.
26+
*
27+
* Requires Oracle Database 12.1.0.2 or higher, which has JSON datatype support.
28+
* See http://docs.oracle.com/database/121/ADXDB/json.htm#CACGCBEG
29+
* Use SQL below to create the required table or do:
30+
*
31+
DROP TABLE j_purchaseorder_c;
32+
-- The extra CHECK clause 'or length(po_document) = 0' clause allows
33+
-- EMPTY_CLOB() to be inserted into the table. The extra clause is
34+
-- not needed if you have a database patch for bug 21636362. The
35+
-- extra 'or' clause will stop the table appearing in
36+
-- USER_JSON_COLUMNS. EMPTY_CLOB() is currently needed by
37+
-- node-oracledb for inserting CLOB data.
38+
CREATE TABLE j_purchaseorder_c (po_document CLOB CHECK (po_document IS JSON or length(po_document) = 0));
39+
COMMIT;
40+
*
41+
*
42+
*****************************************************************************/
43+
44+
using System;
45+
using Oracle.ManagedDataAccess.Client;
46+
// using Oracle.DataAccess.Client;
47+
48+
namespace JsonClobSample
49+
{
50+
class Program
51+
{
52+
static void Main(string[] args)
53+
{
54+
try
55+
{
56+
// Add your user id, password, and data source
57+
string conString = "User Id=<user>;Password=<password>;Data Source=<data source>;";
58+
59+
// Connect and open a database connection
60+
OracleConnection con = new OracleConnection();
61+
con.ConnectionString = conString;
62+
con.Open();
63+
64+
// Insert JSON data into database using a CLOB
65+
OracleCommand cmd = con.CreateCommand();
66+
cmd.CommandText = "INSERT INTO j_purchaseorder_c (po_document) VALUES (:1)";
67+
68+
OracleParameter param = new OracleParameter();
69+
param.OracleDbType = OracleDbType.Clob;
70+
param.Value = @"{'id': 1,'name': 'Alex', 'location': 'USA'}";
71+
cmd.Parameters.Add(param);
72+
73+
cmd.ExecuteNonQuery();
74+
75+
Console.WriteLine("JSON inserted.");
76+
Console.WriteLine();
77+
78+
// Query JSON from database
79+
cmd.CommandText = "SELECT po_document FROM j_purchaseorder_c WHERE JSON_EXISTS (po_document, '$.location')";
80+
OracleDataReader rdr = cmd.ExecuteReader();
81+
82+
rdr.Read();
83+
Console.WriteLine(rdr.GetString(0));
84+
85+
}
86+
catch (Exception ex)
87+
{
88+
Console.WriteLine(ex.Message);
89+
Console.WriteLine(ex.InnerException);
90+
}
91+
92+
}
93+
}
94+
}

dotnet/schemas/scott.sql

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
Rem Copyright (c) 2016 by Oracle Corporation
2+
Rem
3+
Rem You may not use the identified files except in compliance with The MIT
4+
Rem License (the "License.")
5+
Rem
6+
Rem You may obtain a copy of the License at
7+
Rem https://github.com/oracle/Oracle.NET/blob/master/LICENSE
8+
Rem
9+
Rem Unless required by applicable law or agreed to in writing, software
10+
Rem distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
Rem WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
Rem
13+
Rem See the License for the specific language governing permissions and
14+
Rem limitations under the License.
15+
Rem
16+
Rem NAME
17+
REM scott.sql
18+
Rem
19+
Rem DESCRIPTION
20+
Rem SCOTT is a database user whose schema is used for Oracle code demonstrations
21+
22+
23+
SET TERMOUT OFF
24+
SET ECHO OFF
25+
26+
rem CONGDON Invoked in RDBMS at build time. 29-DEC-1988
27+
rem OATES: Created: 16-Feb-83
28+
29+
GRANT CONNECT,RESOURCE,UNLIMITED TABLESPACE TO SCOTT IDENTIFIED BY TIGER;
30+
ALTER USER SCOTT DEFAULT TABLESPACE USERS;
31+
ALTER USER SCOTT TEMPORARY TABLESPACE TEMP;
32+
CONNECT SCOTT/TIGER
33+
DROP TABLE DEPT;
34+
CREATE TABLE DEPT
35+
(DEPTNO NUMBER(2) CONSTRAINT PK_DEPT PRIMARY KEY,
36+
DNAME VARCHAR2(14) ,
37+
LOC VARCHAR2(13) ) ;
38+
DROP TABLE EMP;
39+
CREATE TABLE EMP
40+
(EMPNO NUMBER(4) CONSTRAINT PK_EMP PRIMARY KEY,
41+
ENAME VARCHAR2(10),
42+
JOB VARCHAR2(9),
43+
MGR NUMBER(4),
44+
HIREDATE DATE,
45+
SAL NUMBER(7,2),
46+
COMM NUMBER(7,2),
47+
DEPTNO NUMBER(2) CONSTRAINT FK_DEPTNO REFERENCES DEPT);
48+
INSERT INTO DEPT VALUES
49+
(10,'ACCOUNTING','NEW YORK');
50+
INSERT INTO DEPT VALUES (20,'RESEARCH','DALLAS');
51+
INSERT INTO DEPT VALUES
52+
(30,'SALES','CHICAGO');
53+
INSERT INTO DEPT VALUES
54+
(40,'OPERATIONS','BOSTON');
55+
INSERT INTO EMP VALUES
56+
(7369,'SMITH','CLERK',7902,to_date('17-12-1980','dd-mm-yyyy'),800,NULL,20);
57+
INSERT INTO EMP VALUES
58+
(7499,'ALLEN','SALESMAN',7698,to_date('20-2-1981','dd-mm-yyyy'),1600,300,30);
59+
INSERT INTO EMP VALUES
60+
(7521,'WARD','SALESMAN',7698,to_date('22-2-1981','dd-mm-yyyy'),1250,500,30);
61+
INSERT INTO EMP VALUES
62+
(7566,'JONES','MANAGER',7839,to_date('2-4-1981','dd-mm-yyyy'),2975,NULL,20);
63+
INSERT INTO EMP VALUES
64+
(7654,'MARTIN','SALESMAN',7698,to_date('28-9-1981','dd-mm-yyyy'),1250,1400,30);
65+
INSERT INTO EMP VALUES
66+
(7698,'BLAKE','MANAGER',7839,to_date('1-5-1981','dd-mm-yyyy'),2850,NULL,30);
67+
INSERT INTO EMP VALUES
68+
(7782,'CLARK','MANAGER',7839,to_date('9-6-1981','dd-mm-yyyy'),2450,NULL,10);
69+
INSERT INTO EMP VALUES
70+
(7788,'SCOTT','ANALYST',7566,to_date('13-JUL-87')-85,3000,NULL,20);
71+
INSERT INTO EMP VALUES
72+
(7839,'KING','PRESIDENT',NULL,to_date('17-11-1981','dd-mm-yyyy'),5000,NULL,10);
73+
INSERT INTO EMP VALUES
74+
(7844,'TURNER','SALESMAN',7698,to_date('8-9-1981','dd-mm-yyyy'),1500,0,30);
75+
INSERT INTO EMP VALUES
76+
(7876,'ADAMS','CLERK',7788,to_date('13-JUL-87')-51,1100,NULL,20);
77+
INSERT INTO EMP VALUES
78+
(7900,'JAMES','CLERK',7698,to_date('3-12-1981','dd-mm-yyyy'),950,NULL,30);
79+
INSERT INTO EMP VALUES
80+
(7902,'FORD','ANALYST',7566,to_date('3-12-1981','dd-mm-yyyy'),3000,NULL,20);
81+
INSERT INTO EMP VALUES
82+
(7934,'MILLER','CLERK',7782,to_date('23-1-1982','dd-mm-yyyy'),1300,NULL,10);
83+
DROP TABLE BONUS;
84+
CREATE TABLE BONUS
85+
(
86+
ENAME VARCHAR2(10) ,
87+
JOB VARCHAR2(9) ,
88+
SAL NUMBER,
89+
COMM NUMBER
90+
) ;
91+
DROP TABLE SALGRADE;
92+
CREATE TABLE SALGRADE
93+
( GRADE NUMBER,
94+
LOSAL NUMBER,
95+
HISAL NUMBER );
96+
INSERT INTO SALGRADE VALUES (1,700,1200);
97+
INSERT INTO SALGRADE VALUES (2,1201,1400);
98+
INSERT INTO SALGRADE VALUES (3,1401,2000);
99+
INSERT INTO SALGRADE VALUES (4,2001,3000);
100+
INSERT INTO SALGRADE VALUES (5,3001,9999);
101+
COMMIT;
102+
103+
SET TERMOUT ON
104+
SET ECHO ON

0 commit comments

Comments
 (0)