funny test of dual table

本文围绕Oracle数据库中的dual表展开,通过SQL*Plus进行了一系列操作,如插入、删除、查询等。同时探讨了dual表的用途、默认行数、列数据类型等问题,指出它是数据字典的一部分,不建议随意修改,还提及了优化器对其的特殊处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

funny test of dual table

C:/>sqlplus "/ as sysdba"

SQL*Plus: Release 9.0.1.0.1 - Production on Thu Aug 8 09:20:57 2002

(c) Copyright 2001 Oracle Corporation. All rights reserved.


Connected to:
Oracle9i Enterprise Edition Release 9.0.1.1.1 - Production
With the Partitioning option
JServer Release 9.0.1.1.1 - Production

SQL> select count(*) from dual;

COUNT(*)
----------
1

SQL> select * from dual;

D
-
X

SQL> insert into dual values ('Y');

1 row created.

SQL> commit;

Commit complete.

SQL> insert into dual values ('X');

1 row created.

SQL> insert into dual values ('Z');

1 row created.

SQL> commit;

Commit complete.

SQL> select count(*) from dual;

COUNT(*)
----------
4

SQL> select * from dual;

D
-
X

SQL> select sysdate from dual;

SYSDATE
---------
08-AUG-02

SQL> select count(*) from dual;

COUNT(*)
----------
4

SQL> truncate table dual;

Table truncated.

SQL> select count(*) from dual;

COUNT(*)
----------
0

SQL> select * from dual;

no rows selected

SQL> select sysdate from dual;

no rows selected

SQL> insert into dual values ('X');

1 row created.

SQL> commit;

Commit complete.

SQL> select * from dual;

D
-
X

SQL> select count(*) from dual;

COUNT(*)
----------
1

SQL> select sysdate from dual;

SYSDATE
---------
08-AUG-02

SQL>

***************************************

作者:4pal    时间:02-08-08 22:01

嘿嘿。snow知道dual到底是什么吗? 我还是不 清楚


作者:rejoice999    时间:02-08-08 23:55

DUAL就是个一行一列的表,如果你往里加一行,就会导致很多程序出问题。所以从ORACLE8开始,ORACLE加了代码对DUAL特殊照顾,才会有SNOW版主的FUNNY TEST RESULT。
http://www.itpub.net/showthread.php...&highlight=dual

quote:
最初由 4pal 发布
嘿嘿。snow知道dual到底是什么吗? 我还是不 清楚


作者:oldwain    时间:02-08-10 21:19

quote:
最初由 rejoice999 发布
所以从ORACLE8开始,ORACLE加了代码对DUAL特殊照顾,



NO! NO!

ORACLE没有对DUAL进行特殊照顾, 进行特殊照顾的是sql*plus.

使用其它工具(比如pl/sql dev等) 会发现select * from dual会得到真实的记录.

另外, 在sqlplus中执行create table .. as select * from dual , inset ..select * from dual的结果也是真实的.

个人认为sqlplus耍的这个小聪明, 是个很愚蠢的小聪明.


作者:Fenng    时间:02-08-10 23:24

跟着这个贴子看了看,随后到asktom上查了一下,发现还真有贴子关于它的.
You Asked
Hi Tom

Feels good to post a question after quite some time.
Look at the following :
SQL> desc dual
Name Null? Type
----------------------------------------- -------- ----------------------------
DUMMY VARCHAR2(1)

SQL> select * from dual;

D
-
X

SQL> select count(*) from dual;

COUNT(*)
----------
1

SQL> select 'sdfsdfsdfsdfsdfsdf' from dual;

'SDFSDFSDFSDFSDFSD
------------------
sdfsdfsdfsdfsdfsdf

SQL> select 3434334 from dual;

3434334
----------
3434334

SQL> truncate table dual;
truncate table dual
*
ERROR at line 1:
ORA-04020: deadlock detected while trying to lock object
3510531527724648449742036


SQL> delete from dual;
delete from dual
*
ERROR at line 1:
ORA-01031: insufficient privileges


SQL> connect system/manager
Connected.
SQL> /

1 row deleted.

SQL> commit;

Commit complete.

SQL> select * from dua;
select * from dua
*
ERROR at line 1:
ORA-00942: table or view does not exist


SQL> select * from dual;

no rows selected



1.What is the dual table, what is its purpose.
2.Why does it contain only one column with datatype varchar2, why not
number .
3.Does it contain one row by default.
4.why do we
usually SELECT USER FROM DUAL,
why cant I do it like
SQL> select USER FROM EMP WHERE ROWNUM<2;

USER
------------------------------
SCOTT


5.Does this mean that we are using the dual table only for the convenience that
it has only one row, and it will return only one row back , when we give
queries like

SELECT USER FROM DUAL

6.SQL> SELECT COUNT(*) FROM DUAL;

COUNT(*)
----------
2

SQL> INSERT INTO DUAL VALUES ('X');

1 row created.

SQL> INSERT INTO DUAL VALUES ('X');

1 row created.

SQL> COMMIT;

Commit complete.

SQL> SELECT COUNT(*) FROM DUAL;

COUNT(*)
----------
4

SQL> SELECT * FROM DUAL;

D
-
X


Why is it returning only one row , it has to return 4 rows , when it has allowed
me to insert 4 rows.

7.SQL> delete from dual;

1 row deleted.

SQL> select * from dual;

D
-
X

SQL> select count(*) from dual;

COUNT(*)
----------
3


I want to delete all the rows , I do a delete from dual, and oooo mama
look at it , it deletes only one row, why?

8.SQL> delete from dual;

1 row deleted.

SQL> delete from dual;

1 row deleted.

SQL> select count(*) from dual;

COUNT(*)
----------
1

NOw we have only one row in dual.

lets create a example function.

SQL> create or replace function foo return number
2 as
3 x number;
4 begin
5 x:=1;
6 return 1;
7 end;
8 /

Function created.

SQL> select foo from dual;

FOO
----------
1

SQL> insert into dual values ('X');

1 row created.

SQL> COMMIT;

Commit complete.

SQL> SELECT COUNT(*) FROM DUAL;

COUNT(*)
----------
2

SQL> select foo from dual;

FOO
----------
1

shouldnt it return 2 rows of value 1?


because , look below , I have got 14 rows back , because I had 14 rows in the
table.

SQL> SELECT FOO FROM EMP;

FOO
----------
1
1
1
1
1
1
1
1
1
1
1

FOO
----------
1
1
1

14 rows selected.

SQL>

Kindly elucidate the concept of dual table, and if possible illustrate it.

Thank you

--------------------------------------------------------------------------------
and we said...

Let me just start by saying -- DUAL is owned by SYS. SYS owns the data dictionary, therefore DUAL is part of the data dictionary. You are not to modify the data dictionary via SQL ever -- wierd things can and will happen -- you are just demonstrating some of them. We can make many strange things happen in Oracle by updating the data dictionary. It is neither recommend, supported nor a very good idea.

1.What is the dual table, what is its purpose.

dual is just a convienence table. You don't need to use it, you can use anything you want. The advantage to dual is the optimizer understands dual is a special one row, one column table -- when you use it in queries, it uses this knowledge when developing the plan.


2.Why does it contain only one column with datatype varchar2, why not
number .

truly, why no. Why not a date you would ask then. The column, its name, its datatype and even its value are NOT relevant. DUAL exists solely as a means to have a 1 row table we can reliably select from. Thats all.


3.Does it contain one row by default.

yes, when we build the database, we build dual and put a single row in it.

4.why do we usually SELECT USER FROM DUAL,
why cant I do it like
SQL> select USER FROM EMP WHERE ROWNUM<2;


truly, why can't you? is something preventing you from doing so?? You can if you want. Me, I'll stick with "select user from dual". I know dual exists. I know it has at least 1 and at most 1 row. I know the optimizer knows all about dual and does the most efficient thing for me.

5) yes

6) the optimizer understands dual is a magic, special 1 row table. It stopped on the select * because there is to be one row in there. Its just the way it works. Hopefully you reset dual back to 1 row after your testing or you just totally broke your database!

7) like I said, duals magic, the optimizer knows all about what DUAL should be and does things based on that.

8) dual = magic. dual is a one row table however having more then 1 or less then one is dangerous. You are updating the data dictionary. You should naturally expect very bad things to happen.


Ok, here is some trivia for you out there. How did I do this:

SVRMGR> select * from dual;
D
-
X
1 row selected.

SVRMGR> ????????????????????;
Statement processed.

SVRMGR> select * from dual;
ADDR INDX INST_ID D
-------- ---------- ---------- -
01680288 0 1 X
1 row selected.


What was that magic command?


作者:Fenng    时间:02-08-10 23:26

http://asktom.oracle.com/pls/ask/f?...6388,%7Bdual%7D

这是Tom上的连接


作者:biti_rainy    时间:02-08-11 09:49

hehe

看了 关于定义者权限和调用者权限 部分,结合oracle的关于所谓“精细存取控制”
在使用 sys_context() 函数的基础上

自己都可以做这么一个表出来

并且可以做一个满足你的需要的比dual更让你满意的表

<think>好的,用户想部署remix-words-funny项目,但找不到教程。我需要先理解这个项目是什么,可能是一个基于Remix框架开发的文字游戏或应用。Remix是一个全栈Web框架,使用React和Node.js,所以部署可能涉及构建步骤和服务器配置。 首先,用户可能需要基本的部署步骤,比如安装依赖、环境变量设置、构建和启动服务器。常见部署平台有Vercel、Netlify、Fly.io或者自己的服务器。不过用户提供的引用中提到Spruce Campbell使用Unity,这和Remix项目无关,可能需要忽略这个引用,除非有间接联系。 然后,检查是否需要数据库或其他服务,比如Prisma或PostgreSQL,这可能影响部署步骤。比如,如果项目使用数据库,用户需要设置数据库连接字符串。可能还需要配置生产环境变量,比如NODE_ENV=production。 另外,用户可能遇到常见错误,比如构建失败、环境变量缺失或服务器配置问题,需要给出排查建议。比如检查控制台输出,查看日志,确保端口正确开放等。 最后,生成相关问题,帮助用户深入理解部署流程和相关技术,比如Remix框架特性、环境变量管理、数据库集成和性能优化。确保回答结构清晰,步骤详细,适合不同部署平台的情况。</think>### 部署 remix-words-funny 项目的通用步骤 #### 1. 环境准备 - **安装 Node.js**:确保版本符合项目要求(通常 >= v16.13) ```bash curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash nvm install 18 ``` - **克隆仓库**: ```bash git clone https://github.com/[用户名]/remix-words-funny.git cd remix-words-funny ``` #### 2. 配置环境变量 - 创建 `.env` 文件并填写必要参数(参考项目文档): ```env DATABASE_URL="postgresql://user:password@localhost:5432/dbname" SESSION_SECRET="your_random_string_here" ``` #### 3. 依赖安装与构建 - 安装依赖并构建生产版本: ```bash npm install npm run build ``` #### 4. 部署到常见平台 - **Vercel**: - 通过网页控制台导入仓库 - 设置构建命令 `npm run build` - 输出目录选择 `/build` - **Fly.io**: ```bash fly launch fly deploy ``` - **自有服务器**: ```bash npm run start # 或使用进程管理工具 pm2 start npm --name "remix-app" -- start ``` #### 5. 数据库配置 若项目包含数据库(如 PostgreSQL): ```bash # 安装 PostgreSQL sudo apt install postgresql postgresql-contrib # 创建数据库(根据 .env 配置) sudo -u postgres psql -c "CREATE DATABASE dbname;" npx prisma migrate deploy ``` ### 常见问题排查 - **构建失败**:检查 `package.json` 中引擎版本限制 - **空白页面**:确认路由配置与服务器路径匹配 - **数据库连接超时**:检查防火墙设置和连接字符串格式
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值