简体   繁体   English

我可以在 Oracle SQL 报告中使用定义吗?

[英]Can I use Define in Oracle SQL reports?

First I want to state that I'm new to Oracle SQL and doesn't have too much experience in coding.首先我想 state 我是 Oracle SQL 的新手,并且没有太多的编码经验。

I'm creating a report for our finance department and I have multiple formulas for counting PO amounts, invoiced amounts, received amounts etc. I would like to define those formulas as variables so I don't have write the formulas every time I use them in code.我正在为我们的财务部门创建一份报告,我有多个公式用于计算采购订单金额、发票金额、收到金额等。我想将这些公式定义为变量,这样我就不必每次使用它们时都编写公式在代码中。 What I need to know is that does defining a variable somehow do changes to original DB table?我需要知道的是,定义一个变量是否会以某种方式改变原始数据库表?

Example case from my code:我的代码中的示例:

SELECT
(t.arrived_qty * t.buy_unit_price)*((100-a.discount)/100)+i.additional_cost

For example I would like to define arrived qty multiplied with buy unit price as Received amount例如,我想将到达数量乘以购买单价定义为收到金额

DEF received_qty = t.arrived_qty * t.buy_unit_price

SELECT &received_qty

Can this sort of logic be used in self service reports or does this modify the original DB table somehow?这种逻辑可以在自助服务报告中使用,还是会以某种方式修改原始数据库表?

Hopefully I was able to explain myself clear enough希望我能够足够清楚地解释自己

Thanks in advance提前致谢

Yes, You can do that and it will not change any DB tables (DDL or DML)是的,您可以这样做,并且不会更改任何数据库表(DDL 或 DML)

See the example of using the expression as a variable:请参阅使用表达式作为变量的示例:

SQL> SELECT * FROM ACCOUNT;

    ACC_NR       SUM_    CUST_ID     SALARY
---------- ---------- ---------- ----------
       500       3400        100
       600       5000        101
       700       5070        102

SQL>
SQL> -- Defining the TOT as CUST_ID + SUM_
SQL>
SQL> DEF TOT = CUST_ID + SUM_;
SQL>
SQL> -- Selecting data using the above formula (variable)
SQL>
SQL> SELECT ACC_NR, &TOT AS TOTAL FROM ACCOUNT;
old   1: SELECT ACC_NR, &TOT AS TOTAL FROM ACCOUNT
new   1: SELECT ACC_NR, CUST_ID AS TOTAL FROM ACCOUNT

    ACC_NR      TOTAL
---------- ----------
       500        100
       600        101
       700        102

SQL>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM