我正在尝试编写一个查询,它将向我显示包含以下列的表:ProductGroup、ProductClass和ProductID。
但我在这方面不是很成功。有人可以帮我吗?
我正在尝试编写一个查询,它将向我显示包含以下列的表:ProductGroup、ProductClass和ProductID。
但我在这方面不是很成功。有人可以帮我吗?
关于 Oracle 的SQL Developer工具:
有没有办法要求 Oracle 对该工具进行增强?
例如,我想要求Oracle添加这个功能:Generate WITH clause from resultset using SQL Developer
我正在准备 SQL 脚本,它可以将一组代码部署到目标环境中,而无需大惊小怪。我希望执行 DBA 只需登录到目标数据库并执行“install_release.sql”。该文件“包含”(通过SQL Developer 支持的“@”命令)其他脚本:
PROMPT Compile package specs...
PROMPT ...package A
@../../../path/to/packageA/spec.sql
PROMPT ...package B
@../../../path/to/packageB/spec.sql
PROMPT Compile package bodies...
PROMPT ...package A
@../../../path/to/packageA/body.sql
PROMPT ...package B
@../../../path/to/packageB/body.sql
该过程的这一部分似乎效果很好。
但是,每个包主体都试图包含要包含在包定义中的常见、重复的 SQL 片段(例如,标准EXCEPTION
声明)。例如,“exception_declarations.sql”包含如下代码:
EMPTY_PARAMTER EXCEPTION
INSUFFICIENT_ACCESS EXCEPTION
而“packageA/body.sql”包含如下代码:
CREATE OR REPLACE PACKAGE BODY My_Schema.PackageA AS
@../../../path/to/exception_declarations.sql
FUNCTION ETC(...etc...
当我尝试从 SQL Developer 作为脚本执行“install_release.sql”时,我可以从生成的日志中看到编译器遵循编译规范的路径(没问题),并进入包体......但一旦进入包体,它在尝试执行时抛出此错误@../../../path/to/exception_declarations.sql
:
在预期以下内容时遇到符号“@”:begin end function pragma procedure subtype type current cursor delete exists prior
更神秘的是,当通过 SQL Plus 执行时,这个完全相同的代码可以按预期编译(没有错误)(我只是使用 SQL Plus,但我正在通过一个相当锁定的虚拟机远程工作,它不会让我安装 SQL另外......但确实让我“安装”SQL Developer......它很复杂......我不喜欢谈论它,因为那时恶魔开始嘲笑我)。
我在这里做错了什么?为什么编译器会遵循一组脚本中的路径,而不是包体代码中的路径?我认为这是因为@
命令嵌入在 DDL 中......所以......我怎样才能让 SQL Developer 编译包含 DDL 中的代码的代码?
在 Oracle DB 中有一个包含数据的表"YEARS"
,请参见下面的表/图像
+-----+-----------+------------------+
| FID | I0 | BJA |
+-----+-----------+------------------+
| 1 | 0 | 1949 |
| 2 | 0 | 1996 |
| 3 | 0 | 1970 |
| 4 | 1 | 1871 |
| 4 | 0 | 1975 |
| 5 | 0 | 1967 |
| 6 | 0 | 1968 |
| 7 | 0 | 1926 |
| 7 | 1 | 2009 |
| 7 | 2 | 2012 |
| 7 | 3 | 2018 |
| 8 | 0 | 1956 |
| 9 | 0 | 1990 |
| 10 | 0 | 1953 |
| 10 | 1 | 1904 |
| ... | ... | ... |
+-----+-----------+------------------+
我试图创建一个小提琴(在这里),但它没有用......
CREATE TABLE YEARS (
"FID" NUMBER(10,0) NOT NULL,
"I0" NUMBER(10,0) NOT NULL,
"BJA" NUMBER(10,0)
);
INSERT ALL
INTO YEARS ("FID","I0","BJA") VALUES (1,0,1949)
INTO YEARS ("FID","I0","BJA") VALUES (2,0,1996)
INTO YEARS ("FID","I0","BJA") VALUES (3,0,1970)
INTO YEARS ("FID","I0","BJA") VALUES (4,1,1871)
INTO YEARS ("FID","I0","BJA") VALUES (4,0,1975)
INTO YEARS ("FID","I0","BJA") VALUES (5,0,1967)
INTO YEARS ("FID","I0","BJA") VALUES (6,0,1968)
INTO YEARS ("FID","I0","BJA") VALUES (7,0,1926)
INTO YEARS ("FID","I0","BJA") VALUES (7,1,2009)
INTO YEARS ("FID","I0","BJA") VALUES (7,2,2012)
INTO YEARS ("FID","I0","BJA") VALUES (7,3,2018)
INTO YEARS ("FID","I0","BJA") VALUES (8,0,1956)
INTO YEARS ("FID","I0","BJA") VALUES (9,0,1990)
INTO YEARS ("FID","I0","BJA") VALUES (10,0,1953)
INTO YEARS ("FID","I0","BJA") VALUES (10,1,1904)
SELECT 1 FROM dual;
我正在尝试执行以下查询:
SELECT YEARS.FID,
MIN(YEARS.BJA) AS "CONSTRYEAR",
LISTAGG(YEARS.BJA, ', ') WITHIN GROUP (ORDER BY YEARS.BJA ASC) AS "RECONSTRYEAR"
FROM DB.YEARS YEARS
GROUP BY YEARS.FID;
以及上述查询的输出:
但是,这不是我想要的结果……是的,我正在阅读文档source 1、source 2和source 3;并且我也看到了相关的线程如何一起使用 LISTAGG 和 WHERE以及如何使用带有唯一过滤器的 Oracle 的 LISTAGG 函数?.
我怎样才能得到这样的结果:
+-----+-----------+------------------+
| FID | CONSTRUCT | RECONSTRYEAR |
+-----+-----------+------------------+
| 1 | 1949 | |
| 2 | 1996 | |
| 3 | 1970 | |
| 4 | 1871 | 1975 |
| 5 | 1967 | |
| 6 | 1968 | |
| 7 | 1926 | 2009, 2012, 2018 |
| 8 | 1956 | |
| 9 | 1990 | |
| 10 | 1904 | 1953 |
+-----+-----------+------------------+
您看到"CONSTRUCT"
列中的值被排除在"RECONSTRYEAR"
. 我不明白我需要在哪里放置一个WHERE YEARS.IO != 0
子句LISTAGG
,所以不会包括最低年份。
我刚刚安装了 Oracle 19c 和 SQL Developer。我打开 SQL Developer 并尝试建立一个新连接,但我得到了
“侦听器拒绝连接并出现以下错误:ORA-12505,TNS:侦听器当前不知道连接描述符中给出的 SID (CONNECTION_ID=HYjeJ...==)”。
我正在尝试与
Username: SYS
Role: SYSDBA
Hostname: localhost
SID: xe (this is the default, I know nothing about it)
我尝试使用“ALTER USER SYS IDENTIFIED BY oracle ACCOUNT UNLOCK;”更改 SYS 用户密码 正如这里推荐的那样。我只能使用 SYS 作为 SYSDBA 登录 SQL Plus,并且没有密码。我试图创建一个用户并设置他们的个人资料以允许登录,但这样做会出错。
编辑:
lsnrctl status
LSNRCTL for 64-bit Windows: Version 19.0.0.0.0 - Production on 08-MAR-2021 19:39:44
Copyright (c) 1991, 2019, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for 64-bit Windows: Version 19.0.0.0.0 - Production
Start Date 04-MAR-2021 07:42:09
Uptime 4 days 11 hr. 57 min. 52 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File C:\Desktop\Drawer\Tutorials\Oracle\WINDOWS.X64_193000_db_home\network\admin\listener.ora
Listener Log File C:\Desktop\Drawer\Tutorials\Oracle\diag\tnslsnr\AlbuGierke\listener\alert\log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1521)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(PIPENAME=\\.\pipe\EXTPROC1521ipc)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcps)(HOST=AlbuGierke)(PORT=5500))(Security=(my_wallet_directory=C:\DESKTOP\DRAWER\TUTORIALS\ORACLE\admin\orcl\xdb_wallet))(Presentation=HTTP)(Session=RAW))
Services Summary...
Service "0154b89e82cd4245957cd2ed1b57502d" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "52448234712340b69f274bcc790ecfe0" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "CLRExtProc" has 1 instance(s).
Instance "CLRExtProc", status UNKNOWN, has 1 handler(s) for this service...
Service "orcl" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclpdb" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully
编辑二:
将@EdStevens 解决方案更进一步,我通过SELECT * FROM all_users ORDER BY CREATED;
在 SQL Plus 中运行命令来识别可用用户。然后,我使用安装时创建的 PDBADMIN 用户(在 19c 发布时似乎已经创建了几个用户)来完成连接。
我有一个在 AWS ec2 的 Linux 实例上运行的 Oracle 数据库 12c 标准版版本 12.2.0.1.0。当我尝试使用 SQL Developer 从我的机器 (macOS) 远程连接到它时,我收到一个IO Error: The Network Adapter could not establish the connection
Vendor Code 17002
错误。
sqlplus cd2/ @ec2-publicIp.myCloud.compute.amazonaws.com:1522/orcl
SQL*Plus: Release 19.0.0.0.0 - Production on Mon Aug 3 15:30:56 2020
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
ERROR:
ORA-12541: TNS:no listener
telnet ec2-pubIp.compute.amazonaws.com 1522
Trying pubIp...
telnet: connect to address pubIp: Connection refused
telnet: Unable to connect to remote host
hostname
命令)与从lsnrctl status
. 输出显示localhost
而不是ip-localIp.myCloud.compute.internal
。$ hostname
ip-localIp.myCloud.compute.internal
$ lsnrctl status
LSNRCTL for Linux: Version 12.2.0.1.0 - Production on 03-AUG-2020 15:20:44
Copyright (c) 1991, 2016, Oracle. All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=ip-localIp.myCloud.compute.internal)(PORT=1522)))
STATUS of the LISTENER
------------------------
Alias LISTENER
Version TNSLSNR for Linux: Version 12.2.0.1.0 - Production
Start Date 03-AUG-2020 13:30:22
Uptime 0 days 1 hr. 50 min. 22 sec
Trace Level off
Security ON: Local OS Authentication
SNMP OFF
Listener Parameter File /u01/app/centos/product/12.2.0/dbhome_1/network/admin/listener.ora
Listener Log File /u01/app/centos/diag/tnslsnr/ip-localIp/listener/alert/log.xml
Listening Endpoints Summary...
(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1522)))
(DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC1522)))
Services Summary...
Service "orcl.myCloud.compute.internal" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
Service "orclXDB.myCloud.compute.internal" has 1 instance(s).
Instance "orcl", status READY, has 1 handler(s) for this service...
The command completed successfully
listener.ora
:cat /u01/app/centos/product/12.2.0/dbhome_1/network/admin/listener.ora
# listener.ora Network Configuration File: /u01/app/centos/product/12.2.0/dbhome_1/network/admin/listener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = ip-localIp.myCloud.compute.internal)(PORT = 1522))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1522))
)
)
SQL> show parameter listener_networks
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
listener_networks string
SQL> show parameter local_listener
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
local_listener string (ADDRESS=(PROTOCOL=TCP)(HOST =
ip-localIp.myCloud
.compute.internal)(PORT = 1522
))
SQL> show parameter remote_listener
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
remote_listener string
sqlplus / as sysdba
sqlplus cd2/ @orcl
SQL*Plus: Release 12.2.0.1.0 Production on Mon Aug 3 18:04:13 2020
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Enter password:
Last Successful login time: Mon Aug 03 2020 18:03:52 +00:00
Connected to:
Oracle Database 12c Standard Edition Release 12.2.0.1.0 - 64bit Production
SP2-0310: unable to open file "orcl.sql"
SQL> select 1 from dual;
1
----------
1
SQL>
listener.ora
通过将HOST
值设置为更新0.0.0.0
,重新启动lsnrctl
但结果相同:LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 0.0.0.0)(PORT = 1522))
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1522))
)
)
/etc/hosts
内容:127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ip-localIp.myCloud.compute.internal
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
是否可以从 SQL Developer 导出/导入 ssh 主机?主机列在 C:\Users\name\AppData\Roaming\SQL Developer\system17.4.0.355.2349\o.sqldeveloper.ssh 下,但我找不到将它们导出/导入到 SQL Developer 的方法。
默认情况下,使用 SQL Developer 导入或导出 oracle 数据转储时,它使用impdp
命令进行导入和expdp
命令进行导出。但是我想导入一个使用exp
命令导出的转储,为此我需要强制 SQL 开发人员使用imp
命令而不是impdp
命令。出口也一样。
如果有人知道如何强制 SQL 开发人员使用imp
导入而不是impdp
导出exp
,请帮助我expdp
我安装了 Oracle 18c XE 和 SQL Developer 18.4,都是最新的。
vbk
使用 SYSTEM 登录并在 SQL Developer 中创建用户。
我看到用户正在运行select * from dba_users
,但是当我尝试在 SQL Developer 中连接时,它说
ORA-01017 Invalid Username/Password
我尝试使用 SYSTEM 用户重置密码:
ALTER USER vbk IDENTIFIED BY xxx;
我得到
ORA-01918: user 'VBK' does not exist
我在消息中看到用户名是大写的,即使用户是用小写创建的。
如何与用户建立联系?
我想将 Oracle 数据库导出到一个文件中,为此我在 Windows 上使用 SQLDeveloper(生成的 SQL 文本文件大约为 35MB)。这导致很长的行。
在 linux 上使用 sqlplus 导入文件时遇到了问题:
SP2-0341: line overflow during variable substitution (>3000 characters at line 1)
这发生在多行上。
我看不到有关如何在导出时限制行长的选项。我试图设置线条大小然后导出,但无济于事。我也尝试过编辑该文件,但我使用的 vim 工具专注于显式行长而不是 SQL 的语义(它们会破坏字符串)。此外,我的 regex-fu 只能VALUES
用换行符包围关键字,但即便如此,行数仍然比 3000 长得多。此外,35MB 需要手动编辑。
我仅限于这些工具和 RDBMS,但我愿意接受建议。