oracle 我怎么才能知道这段代码有什么问题呢?

vc6uscn9  于 2023-10-16  发布在  Oracle
关注(0)|答案(1)|浏览(130)

我无法让这段代码正常工作,即使它与示例中所写的完全相同。

UPDATE
    (
            SELECT p.product_id,
                    p.product_name,
                    p.clothing,
                    p.color,
                    p.department,
                    p.product_details
            FROM    products p ) p
 SET    p.clothing = Substr(product_name, Instr(product_name, ' ',1,1)+1, Instr(product_name, ' ',1, 2)+1 - Instr(product_name, ' ',1,1)- 2),
    p.color =
    (
            SELECT  c.color
            FROM    json_table (p.product_details, '$' COLUMNS ( color VARCHAR2(4000) path '$.color') ) c),
    p.department =
    (
            SELECT  g.department =
            FROM    json_table (p.product_details, '$' COLUMNS (department VARCHAR2(4000) path '$.gender') ) g);*

尝试运行代码返回以下内容:

Error at line 17/34: ORA-00923: FROM keyword not found where expected ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_230100", line 797 ORA-06512: at "SYS.DBMS_SYS_SQL", line 1658 ORA-06512: at "SYS.WWV_DBMS_SQL_APEX_230100", line 782 ORA-06512: at "APEX_230100.WWV_FLOW_DYNAMIC_EXEC", line 2035

我试过研究所有不同的奥拉斯的意思和解决他们,但似乎没有工作。

mrfwxfqh

mrfwxfqh1#

您的查询有各种语法错误,可以简化为:

UPDATE products
SET    clothing   = Substr(
                      product_name,
                      Instr(product_name, ' ', 1, 1) + 1,
                      Instr(product_name, ' ', 1, 2)
                        - Instr(product_name, ' ', 1, 1) - 1
                    ),
       color      = JSON_VALUE(product_details, '$.color'),
       department = JSON_VALUE(product_details, '$.gender')

其中,对于样本数据:

CREATE TABLE products(
  product_name    VARCHAR2(50),
  product_details CLOB CHECK (product_details IS JSON),
  clothing        VARCHAR2(20),
  color           VARCHAR2(20),
  department      VARCHAR2(20)
);

INSERT INTO products (product_name, product_details)
VALUES ('ABC Shirt DEF', '{"color":"Red", "gender": "Female"}');

然后,在UPDATE之后,该表包含:
| 产品名称|产品展示_产品展示|服装|颜色|部|
| --|--|--|--|--|
| ABC衬衫DEF| {“color”:“Red”,“gender”:“女”}|衬衫|红色|女性|
fiddle

相关问题