Home > Database > Mysql Tutorial > What is the difference in syntax between sql and oracle?

What is the difference in syntax between sql and oracle?

清浅
Release: 2020-09-14 15:21:15
Original
11947 people have browsed it

The differences between SQL and Oracle syntax are: 1. Different data types; 2. Different functions to obtain the current system time; 3. Different ways of creating users; 4. Different ways of connecting variables and strings ;5. The syntax of the conditional statement "if...else..." is different, etc.

What is the difference in syntax between sql and oracle?

The syntax differences between SQL and Oracle include different data types, different functions to obtain the current system time, no default constraints in Oracle, and the way to connect variables and strings Different, the case statement is different, etc.

The data types are different

SQL server data types: int, smallint, char, varchar, nchar, nvarchar, ntext,datetime,smalldatetime,money,decima,float,bit

Oracle data type: number(p,s),char,varchar2,Date,LOB

Get the current system The functions of time are different

sql server: getdate()

oracle: sysdate

For example: function to set date format

to_char(sysdate,'yyy-mm-dd');
Copy after login

There is no default constraint in oracle

Add default constraint in sql server:

alter table talbe_name add DF_table_name default('男') for sex;
Copy after login

Add default value in oracle:

alter table table_name modify(sex default('男'));
Copy after login

The methods of connecting variables and strings are different

sql server medium connection: use " " connection, for example:

print 'aaaa'+@name;
Copy after login

oracle medium connection: use "|| "Connection, for example:

dbms_output.put_line('aaa'||name);//name为变量
Copy after login

oracle does not have an identity automatic growth column, but uses a sequence to achieve growth

sql server automatic growth: identity (1,1 can be used directly in the primary key column of the table )Achieve growth

oracle Use the sequence to automatically grow:

create sequence se_id 
start with 1
increment by 1
Copy after login

Use the sequence to realize automatic growth: se_id.nextval

The syntax of the conditional statement if...else... Different

sql server:

  if 条件
            begin
              …………
            end
            else
            begin
              …………
            end
Copy after login

oracle:

  if 条件1 then
               …………;
            elsif 条件2 then
               …………;
            else
              …………;
            end if;
Copy after login

The syntax of case statement is different

sql server In:

select ....case.....(else)....end....语句
            select stuno '学号',case
            when grade>=90 and grade<=100 then &#39;★★★★&#39;
            when grade>=80 and grade<90 then &#39;★★★&#39;
         when grade>=70 and grade<80 then &#39;★★&#39;
         when grade>=60 and grade<70  then &#39;★&#39;
            else &#39;差&#39;
            end as &#39;等级&#39; from score
            go
Copy after login

oracle:

  declare
        nums number:=&nos;--&nos表示提示传入值
            begin
              case nums
                when 100 then
                  dbms_output.put_line(&#39;满分也,不错&#39;);
                when 90 then
                  dbms_output.put_line(&#39;90分页很不错了&#39;);
                end case;
            end;
Copy after login

The way to create users is different

sql server

Create login Account: sa-----123456

create Login 登陆名称 with password=&#39;登陆密码&#39;
Copy after login

Modify login account:

alter Login 登陆名称 with name=&#39;新登录名称&#39; and password=&#39;新登录密码&#39;
Copy after login

Disable/enable login account

alter Login 登录名称 disable(禁用)/enable(启用)
Copy after login

Delete login account

drop Login 登录名称
Copy after login

Create user:

create user 用户名 for/from Login 登陆名称
Copy after login

Modify user name

alter user 用户名 with name=&#39;新用户名&#39;
Copy after login

Delete user name

drop user 用户名
Copy after login

Authorization limit

grant select/update/delete/insert on 表名 to 用户名
Copy after login

oracle:

Create user syntax

create user 用户名
identified by 密码
default tablespace users
temporary tablespace temp
quota 10M on users
Copy after login

Modify password

alter user 用户名 identified by 新密码
Copy after login

Grant permission

grant create session to 用户名
Copy after login

Delete User

drop user 用户名 cascade;
Copy after login

The above is the detailed content of What is the difference in syntax between sql and oracle?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template