Pro * C basic tutorial-simplified version _ vol4 Login

Source: Internet
Author: User
Tags sql create database
Preface

You need to log on to the database for any operations on the database. This article describes how to connect the code to the Oracle database.

 

I. Several concept nodes in Communication

The communication point in the network is called a node. Generally, data is transmitted from one node to another.

 

Protocol

A group of rules stored on the network.

 

SQL * net connection syntax

The default database connection Syntax of SQL * NET through decnet (Protocol) is

D: Node

Default database connection

Each node has a default database. If you specify a node without a database in the connect statement, the database is connected to the default database of the node by default.

If connect does not have an AT clause, it is connected by default. Similarly, if it is pure in an AT clause, there are related operations.

 

2. Use the identified by clause in the default database of the logon Node

Exec SQL CONNECT: username identified by: Password

 

No identified by clause

Exec SQL CONNECT: user_pwd;

: User_pwd format: username/password

 

Automatic Logon

Use ops $ username, where username is the name or character name of the user currently logged on to the operating system, and is a valid Oracle user name, you only need
'/' Passed to the precompiled Program

Exec SQL declare begin section;

Char oracleid = '/';

Exec SQL declare end section;

Exec SQL CONNECT: oracleid

 

3. Single display Logon

 

Show that logon is a logon using the at clause

Varchar username [10];

Varchar password [10];

Varchar db_name [20];

Char db_link_name [10];

 

Strcpy (username. ATTR, "Scott ");

Username. Len = strlen (username. ATTR );

Strcpy (password. ATTR, "Tiger ");

Password. Len = strlen (password. ATTR );

Strcpy (db_name.attr, "orcl ");

Db_name.len = strlen (db_name.attr );

Exec SQL declare db_link_name database;

Exec SQL CONNECT: username identified by: Password

At db_link_name using: db_name;

 

Execute SQL statements on non-default connections

Exec SQL at db_link_name select...

Exec SQL at db_link_name insert

Exec SQL at db_link_name update

Exec SQL at db_link_name Delete

 

Cursor control

You cannot use at in a cursor control statement. The at clause must be used in the declare cursor statement.

Exec SQL at: db_link_name declare temp_cursor cursor...

Exec SQL open temp_cursor;

Exec SQL fetch temp_cursor;

Exec SQL close temp_cursor;

 

Db_link_name cannot be modified when the cursor is opened

 

Dynamic SQL

Dynamic Method 1: Use the at clause in the clause

Exec SQL at db_link_name execute immdeiate: SQL _statement

Dynamic methods 2, 3, and 4:

Use the at clause in declare statement

Dynamic Method 2:

Execsql at db_link_name declare SQL _stmt statememt

Execsql prepare SQL _stmt from: SQL _string

Execsql execute SQL _statement;

 

Dynamic Method 3:

Execsql at db_link_name declare SQL _stmt statememt;

Execsqll prepare SQL _stmt from: SQL _string;

Execsql declare temp_cursor cursor for SQL _stmt;

Execsql open temp_cursor;

Execsql fetch temp_cursor...

Execsql close emp_cursor;

 

4. Parallel logon multi-display Logon

Use the at clause to display logon information.

Exec SQL begin declare section;

Char username [10];

Char password [10];

Char db_name1 [20];

Char db_name2 [20];

Exec SQL end declare section;

 

Strcpy (db_name1, "D: newyork_nondef1 ");

Strcpy (db_name1, "D: newyork_nondef2 ");

/* Name a connection name for each database */

Exec SQL declare db_link_name1 database;

Exec SQL declare db_link_name2 database;

/* Connect to two databases */

Exec SQL CONNECT: username idendified by: Password

At db_link_name1 using: db_name1;

Exec SQL CONNECT: username idendified by: Password

At db_link_name2 using: db_name2;

Implicit Logon

Exec SQL CREATE DATABASE LINK db_link

Using 'd: newyork_nondef ';

 

Exec SQL select * into: XXX from EMP @ db_link
Where deptno =: dept_number;

 

From: http://akiraray.javaeye.com/blog/660767

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.