連½ÓOracle數據庫
֮ǰÎÒÒ²ÓÐ談論過.netÖÐ對²»Í¬數據庫µÄ連½Ó²Ù×÷£¬這´Î單談談Oracle£¬Æä實ÄãÒª連½Óµ½Oracle數據庫ÊÇÒªÒªÇóÓÐ個Oracle.DataAccess.dll¡£¿ÉÒÔµ½Oracle網Õ¾ÏÂ載¡£Èç¹ûÄã°²裝ÁËOracleÁË£¬Ò²會ÓÐ這個dllÁË¡£ÒýÈë¾ÍOK
Òò為ÊÇ測試£¬學習¡£ËùÒÔ´ú碼Ò²簡單¡£
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using Oracle.DataAccess.Client;
using System.Windows.Forms;
namespace OraWinApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string oradb = "Data Source=(DESCRIPTION=" + "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=10.1.3.14)(PORT=1521)))" + "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=lab)));" + "User Id=adte;Password=adte123;";
OracleConnection conn = new OracleConnection(oradb);
try
{
conn.Open();
string sql = "select * from TB_ZCTYPE";
OracleCommand cmd = new OracleCommand(sql, conn);
cmd.CommandType = CommandType.Text;
OracleDataAdapter oda = new OracleDataAdapter();
oda.SelectCommand = cmd;
DataSet ds = new DataSet();
oda.Fill(ds);
dataGridView1.DataSource = ds.Tables[0].DefaultView;
}
catch (Exception ex) // catches any error
{
MessageBox.Show(ex.Message.ToString());
}
finally
{
conn.Close();
}
}
}
}
Æä實ºÜ¶à¶¼ÊǸúsqlÊÇÒ»樣µÄģʽ¡£ÎÒÒ²ÊÇ學Ň
Ïà¹ØÎĵµ£º
sqlserverºÍoracle³£Óú¯Êý¶Ô±È
Êýѧº¯Êý
¡¡¡¡1.¾ø¶ÔÖµ
¡¡¡¡S:select abs(-1) value
¡¡¡¡O:select abs(-1) value from dual
¡¡¡¡2.È¡Õû(´ó)
¡¡¡¡S:select ceiling(-1.001) value
¡¡¡¡O:select ceil(-1.001) value from dual
¡¡¡¡3.È¡Õû£¨Ð¡£©
¡¡¡¡S:select floor(-1.001) value
¡¡¡¡O:select floor(-1.0 ......
Æô¶¯“OracleDBConsole”ʱ£££³öÏÖ“Agent process exited abnormally during initialization.”
ÔÚÔËÐÐ"emctl start dbconsole "¡¡·¢ÏÖÊÇÕÒ²»µ½Ö¸¶¨Îļþ,ÔÚÍøÉÏÕÒÁËÒ»ÏÂÔÒò, ¸ü¸ÄµÄÖ¸¶¨Îļþ¼ÐµÄÃû³Æ£¬µ«»¹ÊDz»ÄÜÆô¶¯·þÎñ£¬½á¹ûÈÏÕæ¿´ÁËһϣ¬ÊÇCTRL+C,CTRL+V È»ºó²ÅÆô¶¯³É¹¦£¬ËùÒÔÌØ¶¨Ð´ÏÂÀ´£¬¼Ç ......
×î½ü×ܽáÁËÒ»ÏÂoracleÖ÷¼üµÄÉèÖ÷½·¨£¬Ìùµ½Õâ±£´æÒ»Ï°ɡ£ ÓÐÁ½ÖÖ·½·¨¿ÉÒÔÉèÖÃÖ÷¼ü£¬Ò»ÖÖÊÇ×ÔÔö³¤Ö÷¼ü£¬ÁíÒ»ÖÖ¾ÍÊÇÉú³ÉΨһÐòÁС£ Ò»¡¢×ÔÔö³¤Ö÷¼ü --Ê×ÏȽ¨Ò»¸ö±íTEST
create tableTEST (
NID int PRIMARY KEY,
test1 varchar2(20),
test2 varchar2(20),
test3 ......
Select to_char(sysdate,'ss') from dual;--È¡µ±Ç°Ê±¼äÃ벿·Ö
Select to_char(sysdate,'mi') from dual;--È¡µ±Ç°Ê±¼ä·ÖÖÓ²¿·Ö
Select to_char(sysdate,'HH24') from dual;--È¡µ±Ç°Ê±¼äÃëСʱ²¿·Ö
Select to_char(sysdate,'DD') from dual;--È¡µ±Ç°Ê±¼äÈÕÆÚ²¿·Ö
Select to_char(sysdate,'MM') from dual;--È¡µ±Ç°Ê±¼ ......
ÎÊÌâÌá³ö£º
Ò»¸ö¸ß¼¶SQLÓï¾äÎÊÌâ
¼ÙÉèÓÐÒ»ÕÅ±í£¬ÓÐÕâÑùһЩÊý¾Ý
a b
1 2
0 2
2 3
3 4
4
5 6
6 7
12 7
7
aÊÇ×Ó½Úµã bÊǸ¸½Úµã ,Èç¹ûbΪnull ÔòΪһ¿ÃÊ÷µÄ¸ù½Úµã
¸ù¾ÝAÓëBµÄÕâ¸ö¹ØÏµ ÕÒ³öÒ»¿ÃÊ÷µÄ½á¹¹ÏÔʾ³öÀ´ £¬²¢ÏÔʾ³öÿ¸ö½ÚµãÔÚÊéÖеIJ㼶£¬½«Ê÷µÄ½á¹¹´ò ......