oracle12c

Returning the value of identity column after insertion in Oracle

血红的双手。 提交于 2019-12-18 06:17:12
问题 How do I return the value of an identity column (id) in Oracle 12c after insertion? Seems like most of the approaches out there uses sequence to get back the id of the inserted item. 回答1: Simply use the RETURNING clause. For example - RETURNING identity_id INTO variable_id; Test case - SQL> set serveroutput on SQL> CREATE TABLE t 2 (ID NUMBER GENERATED ALWAYS AS IDENTITY, text VARCHAR2(50) 3 ); Table created. SQL> SQL> DECLARE 2 var_id NUMBER; 3 BEGIN 4 INSERT INTO t 5 (text 6 ) VALUES 7 (

Why EXECUTE IMMEDIATE is needed here?

♀尐吖头ヾ 提交于 2019-12-18 05:10:32
问题 I am a SQL Server user and I have a small project to do using Oracle, so I’m trying to understand some of the particularities of Oracle and I reckon that I need some help to better understand the following situation: I want to test if a temporary table exists before creating it so I had this code here: DECLARE table_count INTEGER; var_sql VARCHAR2(1000) := 'create GLOBAL TEMPORARY table TEST ( hello varchar(1000) NOT NULL)'; BEGIN SELECT COUNT(*) INTO table_count FROM all_tables WHERE table

Query featuring outer joins behaves differently in Oracle 12c

柔情痞子 提交于 2019-12-18 04:38:06
问题 I had a problem come through concerning missing data on Oracle 12c. I took a look at the code and found a query that works on mysql, mssql, oracle 11g, but has different behaviour in oracle 12c. I have generalized the table structure and query somewhat and reproduced the issue. create table thing (thing_id number, display_name varchar2(500)); create table thing_related (related_id number, thing_id number, thing_type varchar2(500)); create table type_a_status (related_id number, status

oracle 12c - select string after last occurrence of a character

前提是你 提交于 2019-12-17 20:07:09
问题 I have below string: ThisSentence.ShouldBe.SplitAfterLastPeriod.Sentence So I want to select Sentence since it is the string after the last period. How can I do this? 回答1: You can probably do this with complicated regular expressions. I like the following method: select substr(str, - instr(reverse(str), '.') + 1) Nothing like testing to see that this doesn't work when the string is at the end. Something about - 0 = 0. Here is an improvement: select (case when str like '%.' then '' else substr

Multiple insert SQL oracle

陌路散爱 提交于 2019-12-17 13:23:58
问题 How do you do multiple insert with SQL in Oracle 12c when you have an identity column? INSERT ALL INTO Table1 (Column2) Values (1) INTO Table1 (Column2) Values (2) SELECT * FROM dual; where Table1 has column1 as an identity, will set the identity column to have the same value which violates the primary key constraint. CREATE TABLE Table1 ( Table1Id NUMBER GENERATED ALWAYS AS IDENTITY, column2 VARCHAR2(255), column3 NUMBER, PRIMARY KEY (Table1Id) ); INSERT ALL INTO Table1 (column2, column3)

error: ORA-65096: invalid common user or role name in oracle

偶尔善良 提交于 2019-12-17 10:10:26
问题 I just installed oracle11g, and it was missing the Scott schema. So i am trying to generate it myself. I got the sql script of "Scott" schema, but when i try to run the query "create user Scott identified by tiger;" it displays the following error: ORA-65096: invalid common user or role name in oracle. Basically it is not allowing me to create a user "Scott". Why is that, and how can I fix my problem? 回答1: Before creating the user run: alter session set "_ORACLE_SCRIPT"=true; I found the

Oracle Joins - Comparison between conventional syntax VS ANSI Syntax

試著忘記壹切 提交于 2019-12-17 04:28:48
问题 Preamble Of late, I see too many geeks commenting on Oracle questions saying that "Do not use (+) operator, rather use JOIN syntax". Question I do see that both work well. But what is the real difference between using them and what makes you feel using them? I would welcome answers, more from experience. 1. Is there anything to do with limitations in application, performance, etc. while using them? 2. What would you suggest for me? I did read something on Oracle documentation but not good

Create Trigger with stored procedures by making dynamic in the trigger column

岁酱吖の 提交于 2019-12-13 20:27:09
问题 Im create new trigger audit using store procedure cause want flexible column in the trigger audit im using Oracle 12 C .. CREATE OR REPLACE PROCEDURE DBADMIN.TEST3 (OUTPUT OUT SYS_REFCURSOR, TABLE_NAME IN VARCHAR2) IS N NUMBER; BEGIN N := 0; EXECUTE IMMEDIATE ' CREATE OR REPLACE TRIGGER DBADMIN.TA_EMPLOYEES3 AFTER INSERT OR DELETE OR UPDATE ON DBADMIN.EMPLOYEES FOR EACH ROW DECLARE SID VARCHAR2 (30); BEGIN SELECT SYS_CONTEXT ('' USERENV '', '' IP_ADDRESS '') INTO IP FROM DUAL; SELECT SEQ#

Oracle DBMS Job not running

爱⌒轻易说出口 提交于 2019-12-13 11:14:59
问题 I defined a job to run from Tuesday to Sundays every 5 min. from 9:00 am to 22:00 pm BEGIN DBMS_SCHEDULER.CREATE_JOB ( job_name => 'GET_INVOICES_JOB', job_type => 'PLSQL_BLOCK', job_action => 'BEGIN LOPES.GET_INVOICES; END;', repeat_interval =>'FREQ=MINUTELY; INTERVAL=5; BYHOUR=9,22; BYDAY=TUE,WED,THU,FRI,SAT,SUN', enabled => TRUE, comments => 'GET_INVOICES'); END; / But the job does not run cheking SELECT * FROM USER_SCHEDULER_JOB_RUN_DETAILS ORDER BY LOG_DATE DESC Checking the Job it seems

Connecting to Oracle database installed on one pc to the java application from another machine

旧街凉风 提交于 2019-12-13 07:46:25
问题 I've installed Oracle 12c (desktop class) on my machine, and I can use it via sql developer on the same machine. Now how can I use the same database from another machine (for java application) in the LAN? I tried using the jdbc thin driver as follows: jdbc:oracle:thin:@10.0.11.69:1521:orcl where 10.0.11.69 is my ip address where Oracle is installed. Do i need to install any server where oracle is installed(10.0.11.69) to connect to my db from another machine? I'm trying this from past 3 days