set lines 400 set pages 9999 set long 400 select 'create synonym ' || decode(owner,'LS6_ACCT_WH','LS6_HIST_WH', replace(owner, 'LS65_ACCT', 'LS6_HIST')) || '.' || table_name || ' for ' || decode(owner,'LS6_ACCT_WH','LS6_HIST_WH', replace(owner, 'LS65_ACCT', 'LS6_HIST')) || '.' || table_name || '@newhtls1;' as text from dba_tables where owner in('LS65_ACCT2','LS6_ACCT_WH', 'LS65_ACCT_YC','LS65_ACCT_EZ','LS65_ACCT_SZ','LS65_ACCT_XG', 'LS65_ACCT_SY','LS65_ACCT_XF','LS65_ACCT_ES','LS65_ACCT_SNJ', 'LS65_ACCT_JZ','LS65_ACCT_HG','LS65_ACCT_XN','LS65_ACCT_JM', 'LS65_ACCT_HS','LS65_ACCT_XT','LS65_ACCT_TM','LS65_ACCT_QJ', 'LS65_ACCTM_MVNO') and table_name like '%202303%_T' and table_name not like 'BILL%_T' and table_name not like 'ERROR%_T' and table_name not like 'RB%_T' and table_name not like 'A0%' and table_name not like 'A1%' and table_name not like 'BIN%' order by 1;
时间: 2023-10-18 15:04:34 浏览: 164
这段代码是一个 SQL 查询语句,用于生成一组创建同义词的 SQL 语句,并将结果按照 text 列进行排序。具体操作为:
- 设置 SQL*Plus 的输出格式:每行最多显示 400 个字符,总共显示 9999 行,将 LONG 类型的字段最多显示 400 个字符。
- 查询 dba_tables 视图,获取表所属的 owner、表名以及符合一定条件的表,生成创建同义词的 SQL 语句。
- decode 函数用于根据 owner 的值进行判断,如果 owner 是 LS6_ACCT_WH,则将其替换成 LS6_HIST_WH,如果 owner 是 LS65_ACCT,则将其替换成 LS6_HIST。
- 使用 replace 函数将 owner 中的 LS65_ACCT 替换成 LS6_HIST。
- 将查询结果拼接成一个 SQL 语句,格式为:create synonym owner.table_name for owner.table_name@newhtls1;,其中 owner 和 table_name 是查询结果中的值。
- 最后将查询结果按照 text 列进行排序。
相关问题
SELECT MIN( id ) AS id, max( stand_id ) AS stand_id, max( edds_stand_id ) AS edds_stand_id, MAX( stand_id ) AS d FROM pz_item_synonym GROUP BY item_code, item_name, subgroup_type 根据id将原表数据更新
你可以使用以下 SQL 语句来更新原表数据:
```
UPDATE pz_item_synonym t1
INNER JOIN (
SELECT MIN(id) AS id, MAX(stand_id) AS stand_id, MAX(edds_stand_id) AS edds_stand_id, MAX(stand_id) AS d
FROM pz_item_synonym
GROUP BY item_code, item_name, subgroup_type
) t2
ON t1.id = t2.id
SET t1.stand_id = t2.stand_id,
t1.edds_stand_id = t2.edds_stand_id,
t1.d = t2.d;
```
这条 SQL 语句会按照 `item_code`、`item_name` 和 `subgroup_type` 进行分组,并选取每组中的最小 `id`,以及最大的 `stand_id`、`edds_stand_id` 和 `d`。然后将选取出来的这些字段的值更新到原表中对应的记录上。
CREATE USER cedar IDENTIFIED BY cedar DEFAULT TABLESPACE CEDAR_DATA TEMPORARY TABLESPACE TEMP PROFILE DEFAULT ACCOUNT UNLOCK; -- 5 Roles for cedar GRANT DBA TO cedar; GRANT RESOURCE TO cedar WITH ADMIN OPTION; GRANT AQ_ADMINISTRATOR_ROLE TO cedar; GRANT CONNECT TO cedar WITH ADMIN OPTION; GRANT AQ_USER_ROLE TO cedar; ALTER USER cedar DEFAULT ROLE ALL; -- 44 System Privileges for cedar GRANT CREATE ANY DIRECTORY TO cedar WITH ADMIN OPTION; GRANT CREATE PUBLIC SYNONYM TO cedar WITH ADMIN OPTION; GRANT EXECUTE ANY CLASS TO cedar WITH ADMIN OPTION; GRANT DROP ANY VIEW TO cedar WITH ADMIN OPTION; GRANT CREATE CLUSTER TO cedar; GRANT ALTER SYSTEM TO cedar; GRANT UPDATE ANY TABLE TO cedar; GRANT INSERT ANY TABLE TO cedar; GRANT LOCK ANY TABLE TO cedar; GRANT CREATE EXTERNAL JOB TO cedar WITH ADMIN OPTION; GRANT EXECUTE ANY PROGRAM TO cedar WITH ADMIN OPTION; GRANT CREATE JOB TO cedar WITH ADMIN OPTION; GRANT DROP ANY DIRECTORY TO cedar WITH ADMIN OPTION; GRANT ALTER ANY TRIGGER TO cedar; GRANT CREATE DATABASE LINK TO cedar; GRANT DROP ANY TABLE TO cedar WITH ADMIN OPTION; GRANT CREATE TABLE TO cedar WITH ADMIN OPTION; GRANT QUERY REWRITE TO cedar; GRANT ANALYZE ANY TO cedar; GRANT DROP ANY TRIGGER TO cedar; GRANT EXECUTE ANY PROCEDURE TO cedar; GRANT SELECT ANY TABLE TO cedar WITH ADMIN OPTION; GRANT ALTER ANY TABLE TO cedar; GRANT UNLIMITED TABLESPACE TO cedar WITH ADMIN OPTION; GRANT CREATE SESSION TO cedar; GRANT CREATE ANY TRIGGER TO cedar; GRANT DROP ANY PROCEDURE TO cedar WITH ADMIN OPTION; GRANT ALTER ANY PROCEDURE TO cedar; GRANT DROP PUBLIC SYNONYM TO cedar WITH ADMIN OPTION; GRANT DROP ANY SYNONYM TO cedar WITH ADMIN OPTION; GRANT MANAGE SCHEDULER TO cedar WITH ADMIN OPTION; GRANT CREATE ANY PROCEDURE TO cedar; GRANT CREATE PROCEDURE TO cedar WITH ADMIN OPTION; GRANT CREATE SEQUENCE TO cedar; GRANT CREATE VIEW TO cedar WITH ADMIN OPTION; GRANT CREATE SYNONYM TO cedar; GRANT DROP ANY INDEX TO cedar; GRANT DELETE ANY TABLE TO cedar; GRANT CREATE ANY TABLE TO cedar; GRANT CREATE ANY JOB TO cedar WITH ADMIN OPTION; GRANT SELECT ANY DICTIONARY TO cedar WITH ADMIN OPTION; GRANT CREATE ROLE TO cedar; GRANT CREATE ANY SYNONYM TO cedar WITH ADMIN OPTION; GRANT ALTER SESSION TO cedar WITH ADMIN OPTION; GRANT EXECUTE ON sys.dbms_aq TO cedar; GRANT EXECUTE ON sys.dbms_aqadm TO cedar; GRANT EXECUTE ON sys.dbms_network_acl_admin TO cedar; GRANT ALL ON sys.DBMS_LOCK TO cedar; 这个SQL在oracle 能用吗
这个 SQL 语句应该是可以在 Oracle 环境中执行的。它的作用是创建一个名为 cedar 的用户,并指定了该用户的默认表空间、临时表空间、角色和权限等信息。其中,该用户被授予了 DBA、RESOURCE、AQ_ADMINISTRATOR_ROLE、CONNECT、AQ_USER_ROLE 等角色,也被授予了 44 个系统权限(如 CREATE ANY DIRECTORY、EXECUTE ANY CLASS、CREATE TABLE 等)。此外,该用户还被授予了一些特殊的权限,如 EXECUTE ON sys.dbms_aq、EXECUTE ON sys.dbms_aqadm、EXECUTE ON sys.dbms_network_acl_admin 等。这些权限和角色的授予将使得该用户具有较高的系统权限,需要谨慎使用。
阅读全文