Oracle

checking if table exists function

与世无争的帅哥 提交于 2021-01-29 17:34:02
问题 Can you help me rectify this block of code plz? `CREATE OR REPLACE FUNCTION TABLE_EXISTS(name VARCHAR(50)) RETURNS BOOLEAN AS BEGIN DECLARE counttable INTEGER; SELECT COUNT(1) INTO counttable FROM USER_TABLES WHERE TABLE_NAME=name; if counttable=0 then return false else return true end if; END; / IF (TABLE_EXISTS("LEADS_DELETED")) then DROP TABLE LEADS_DELETED; end if; / CREATE GLOBAL TEMPORARY TABLE LEADS_DELETED ( ID NUMBER(19), PRIMARY KEY (ID) ) ON COMMIT DELETE ROWS` 回答1: You can use a

Trigger selecting child records, multiplying their values and updating parent record

♀尐吖头ヾ 提交于 2021-01-29 17:24:49
问题 I am a PL/SQL newbie and I'm struggling with a trigger. Description: I have three objects - PRODUCT, CONTAINS, ORDER. One product can have many CONTAINS and one ORDER can have many CONTAINS (basically it used to be Many-to-many relationship between PRODUCT and ORDER). Each Product has a column "value", each CONTAINS has a column "amount" and each ORDER has a column "total". When I add a new PRODUCT to ORDER via creating new CONTAINS, I want to recalculate field "total" on ORDER. Example:

Store result of minus query ( list of varchars) in a variable in Oracle PL/SQL

♀尐吖头ヾ 提交于 2021-01-29 15:42:50
问题 I'm using below minus query to get the extra project_ids present in TABLE_ONE compared to TABLE_TWO select project_id from TABLE_ONE minus select project_id from TABLE_TWO; I want to store result of above query which is list of varchars in a variable since i need to perform below 2 steps : If above query returns any project_ids, send an email which contains these project_ids in mail body insert those extra project_ids in TABLE_TWO to make sure all project_ids present in TABLE_ONE are present

sql oracle - remove duplicate value

那年仲夏 提交于 2021-01-29 15:05:50
问题 I have the below query, it returns the column UP that contents duplicated values (for example '111' exists 5 times but not all of them have a value in CODE_DEPT) select UP, CODE_DEPT from ESP_ENSEIGNANT; UP CODE_DEPT 111 f 555 111 222 y 222 111 444 666 222 444 k 111 f 111 666 x so i want to update my query to get a unique UP with CODE_DEPT (if CODE_DEPT is not empty it returns else it returns empty) UP CODE_DEPT 111 f 555 222 y 444 k 666 x 回答1: You can use aggregation: select up, max(code

Dynamic SQL table name as variable

↘锁芯ラ 提交于 2021-01-29 14:35:50
问题 I have this procedure which is working, 2 parameters can be passed when calling procedure and it executes the select query. create or replace procedure dynamic_sql (input1 varchar2, input2 varchar2) as begin execute immediate 'select :variable1, :variable2 from emp' using input1,input2; end; / exec dynamic_sql('ename','job'); In the same way I try to add third variable which will replace the table Emp, but it doesn't work, passed in table name is 100% correct. This is the code that doesn't

How to passing list data variable to store procedure and execute the store procedure?

偶尔善良 提交于 2021-01-29 14:31:58
问题 I have 8 variable list and collect them to variable ls in this below code : Workbook workbook = new Workbook("D:/excel file/Mapping Prod Matriks _Group Sales Commercial.xlsx"); com.aspose.cells.Worksheet worksheet = workbook.getWorksheets().get(0); com.aspose.cells.Cells cells = worksheet.getCells(); Range displayRange = cells.getMaxDisplayRange(); List<String> ParaObjGroup = new ArrayList<String>(); List<String> ParaObjCode = new ArrayList<String>(); List<String> ParaProdMatrixId = new

Oracle Apex 4.2 Dynamic action with custom event “beforeunload” not working

▼魔方 西西 提交于 2021-01-29 14:15:05
问题 So i have created a custom dynamic action that is supposed to run "beforeunload" (in case user closes the tab/browser unexpectedly or navigates away from the page in a manner not intended). This dynamic action runs a simple plsql procedure ( http://prntscr.com/qz0a6c ). A few days ago the Chrome browser updated to version 80 and in this new version "beforeunload" is disallowed and now my dynamic action does not work. Does anyone have an idea on how I could build this functionality differently

ORA-30076: invalid extract field for extract source

空扰寡人 提交于 2021-01-29 14:02:25
问题 I have written a query to extract hours between dates. This will basically retrieve the time entry for the employee. When I am executing the below query, It is working fine but when i add the extract function I am getting an error : ORA-30076: invalid extract field for extract source select emp_id, start_date , stop_date , (ROUND(SUM( (EXTRACT (DAY FROM line_stop_time - line_start_time)*(3600*24)) + (EXTRACT (HOUR FROM line_stop_time - line_start_time)*(3600)) + (EXTRACT (MINUTE FROM line

The NOT IN with NULL values dilemma in ORACLE SQL

前提是你 提交于 2021-01-29 13:23:19
问题 When I used this code WHEN col1 NOT IN (SELECT col2 FROM table_name) THEN 'something' it didn't give the expected results knowing that col2 contains a NULL value, Why did this happened ? Does using IN with NULL values messes with data stored in memory or what? 回答1: This is not an issue with Oracle. This is how SQL is defined. When the subquery returns a NULL value with NOT IN , then no rows match at all. For this reason, I strongly recommend always using NOT EXISTS instead: WHEN NOT EXISTS

Writing a Version Number Function in PL/SQL

十年热恋 提交于 2021-01-29 13:23:06
问题 I want to write a function that will give me the next version number for a table. The table stores the existing version on each record. For example, I have the cat table cats seqid 1 name Mr Smith version number 1.2b.3.4 How can I write a program that will be able to increment these values based on various conditions? This is my first attempt if v_username is not null then v_new_nbr = substr(v_cur_nbr, 1,7)||to_number(substr(v_cur_nbr, 8,1))+1 should be 1.2b.3.5 回答1: substr(v_cur_nbr, 1,7)|